-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path07-s01-lab07e.Rmd
More file actions
147 lines (109 loc) · 5.03 KB
/
07-s01-lab07e.Rmd
File metadata and controls
147 lines (109 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
## Solutions to Questions
```{r lab7-solutions-setup, echo = FALSE, message=FALSE, warning=FALSE}
library(broom)
ratings <- read_csv("data/07-s01/inclass/GuiltJudgements.csv")
```
Below you will find the solutions to the questions for the Activities for this chapter. Only look at them after giving the questions a good try and speaking to the tutor about any issues.
### InClass Activities
#### InClass Task 1
```{r ch7-task1, eval = FALSE}
library(broom)
library(tidyverse)
ratings <- read_csv("GuiltJudgements.csv")
```
[Return to Task](#Ch7InClassQueT1)
#### InClass Task 2
```{r ch7-task2, results='asis'}
lates <- ratings %>%
filter(Evidence == "Late") %>%
select(Participant, Evidence, `12`, `13`) %>%
rename(Twelve = `12`, Thirteen = `13`) %>%
mutate(diff = Twelve - Thirteen)
```
[Return to Task](#Ch7InClassQueT2)
#### InClass Task 3
```{r ch7-task3, results='asis', fig.cap = "Potential Solution to Task 3"}
lates %>%
ggplot(aes(diff)) +
geom_histogram(binwidth = 1) +
labs(x = "Difference in GuiltRating", y = NULL) +
theme_bw()
```
[Return to Task](#Ch7InClassQueT3)
#### InClass Task 4
The Task only asks for the boxplot. We have added some additional functions to tidy up the figure a bit that you might want to play with.
```{r ch7-task4, results='asis', fig.cap = "Potential Solution to Task 4"}
lates %>%
ggplot(aes(y = diff)) +
geom_boxplot() +
theme_bw()
```
[Return to Task](#Ch7InClassQueT4)
#### InClass Task 5
```{r ch7-task5, results='asis'}
descriptives <- lates %>%
select(-diff) %>%
gather(Timepoint, GuiltRating, Twelve, Thirteen) %>%
group_by(Timepoint) %>%
summarise(n = n(),
mean = mean(GuiltRating),
sd = sd(GuiltRating),
se = sd/sqrt(n),
LowerCI = mean - 1.96*se,
UpperCI = mean + 1.96*se)
```
```{r hidden-1, include = FALSE}
desc2 <- descriptives %>%
mutate_at(vars(mean, sd, se, LowerCI, UpperCI),
webex::round2, digits = 2)
.d12 <- desc2 %>% filter(Timepoint == "Twelve")
.d13 <- desc2 %>% filter(Timepoint == "Thirteen")
```
[Return to Task](#Ch7InClassQueT5)
#### InClass Task 6
* A basic barplot with 95% Confidence Intervals.
* We have embellished the figure a little but you can mess around with the code to see what each bit does.
```{r ch7-task6-1, results='asis', fig.cap = "Possible Solution to Task 7"}
ggplot(descriptives, aes(x = Timepoint, y = mean, fill = Timepoint)) +
geom_col(colour = "black") +
scale_fill_manual(values=c("#E2A458", "#61589C")) +
scale_x_discrete(limits = c("Twelve","Thirteen")) +
labs(x = "Timepoint of Evidence", y = "GuiltRating") +
guides(fill="none") +
geom_errorbar(aes(ymin = LowerCI, ymax = UpperCI),
position = "dodge", width = .15) +
scale_y_continuous(breaks = c(1:9), limits = c(0,9)) +
coord_cartesian(ylim = c(1,9), xlim = c(0.5,2.5), expand = FALSE) +
theme_classic()
```
* An alternative way to display just the means and errorbars would be to use the pointrange approach. This image shows again the 95% CI
```{r ch7-task6-2, results='asis', fig.cap = "Alternative Solution to Task 7"}
ggplot(descriptives, aes(x = Timepoint, y = mean, fill = Timepoint)) +
geom_pointrange(aes(ymin = LowerCI, ymax = UpperCI))+
scale_x_discrete(limits = c("Twelve","Thirteen")) +
labs(x = "Timepoint of Evidence", y = "GuiltRating") +
guides(fill="none")+
scale_y_continuous(breaks = c(1:9), limits = c(0,9)) +
coord_cartesian(ylim = c(1,9), xlim = c(0.5,2.5), expand = FALSE) +
theme_bw()
```
[Return to Task](#Ch7InClassQueT6)
#### InClass Task 7
* Remember to set `paired = TRUE` to run the within-subjects t-test
```{r ch7-task7, results='asis'}
results <- t.test(lates %>% pull(Twelve),
lates %>% pull(Thirteen), paired = TRUE) %>%
tidy()
```
[Return to Task](#Ch7InClassQueT7)
#### InClass Task 8
A potential write-up for this study would be as follows:
**A paired-samples t-test was run to compare the change in guilt ratings before (M = `r .d12$mean`, SD = `r .d12$sd`) and after (M = `r .d13$mean`, SD = `r .d13$sd`) the crucial evidence was heard. A significant difference was found (t(`r webex::round2(results$parameter,2)`) = `r webex::round2(results$statistic, 2)`, p `r if_else(webex::round2(results$p.value, 3) < .001, "< .001", paste0("= ", webex::round2(results$p.value, 3)))`) with Timepoint 13 having an average rating `r webex::round2(results$estimate, 2) %>% abs()` units lower than Timepoint 12. This tells us that the critical evidence did have an influence on the rating of guilt by jury members.**
When rounding off p-values that are less than .001, rounding will give you a value of 0 which is a bit silly. Values less than .001 would normally be written as p < .001. To create a reader-friendly p-value, then you could try something like the following in your code:
```{r example-1, eval=FALSE}
ifelse(results$p.value < .001,
"p < .001",
paste0("p = ", round(results$p.value,3)))
```
[Return to Task](#Ch7InClassQueT8)
<span style="font-size: 22px; font-weight: bold; color: var(--purple);">Chapter Complete!</span>