-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA2_P3_LanguageASD_power_instructions.Rmd
199 lines (162 loc) · 8.32 KB
/
A2_P3_LanguageASD_power_instructions.Rmd
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
---
title: "Assignment 1 - Language Development in ASD - Power and simulations"
author: "[YOUR NAME]"
date: "[DATE]"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Welcome to the third exciting part of the Language Development in ASD exercise
In this part of the assignment, we try to figure out how a new study should be planned (i.e. how many participants?) in order to have enough power to replicate the findings (ensuring our sample size is adequate, our alpha at 0.05 and our beta at 0.8):
1- if we trust the estimates of the current study. Report the power analysis and comment on what you can (or cannot) use its estimates for.
2- if we are skeptical of the current study. Report the power analysis and comment on what you can (or cannot) use its estimates for.
3- if we only have access to 30 participants. Identify the power for each relevant effect and discuss whether it's worth to run the study and why
The list above is also what you should discuss in your code-less report.
## Learning objectives
- Learn how to calculate statistical power
- Critically appraise how to apply frequentist statistical power
### Exercise 1
How much power does your study have (if your model estimates are quite right)?
- Load your dataset (both training and testing), fit your favorite model, assess power for your effects of interest (probably your interactions).
- Report the power analysis and comment on what you can (or cannot) use its estimates for.
- Test how many participants you would have to have to replicate the findings (assuming the findings are correct)
N.B. Remember that main effects are tricky once you have interactions in the model (same for 2-way interactions w 3-way interactions in the model). If you want to test the power of main effects, run a model excluding the interactions.
N.B. Check this paper: https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.12504
You will be using:
- powerSim() to calculate power
- powerCurve() to estimate the needed number of participants
- extend() to simulate more participants
```{r}
##Loading data
library(pacman)
p_load(tidyverse, lmerTest, simr)
df_train <- read_csv("train.csv")
df_test <- read_csv("test.csv")
df_test$Child.ID <- 66+df_test$Child.ID
df <- merge(df_train, df_test, all = T)
df <- df[-which(is.na(df$CHI_MLU)),]
##Modelling
model1 <- lmer(CHI_MLU ~ Visit + Diagnosis + verbalIQ1 + (1 + Visit | Child.ID),
df,
REML = F,
control = lmerControl(optimizer = "nloptwrap",
calc.derivs = F))
model2 <- lmer(CHI_MLU ~ Visit * Diagnosis * verbalIQ1 + (1 + Visit | Child.ID),
df,
REML = F,
control = lmerControl(optimizer = "nloptwrap",
calc.derivs = F))
summary(model1)
summary(model2)
#Checking for effect estimates
fixef(model1)["Visit"] #0.23
fixef(model1)["DiagnosisTD"] #-0.26
fixef(model1)["verbalIQ1"] #0.08
fixef(model2)["Visit:DiagnosisTD:verbalIQ1"] #0.02
#Doing the power analysis; The probability of showing an effect when the effect is there.
set.seed(123)
powerSim(model1,
test = fixed("Visit"),
nsim = 100) #100%
powerSim(model1,
test = fixed("Diagnosis"),
nsim = 100) #89.00%
powerSim(model1,
test = fixed("verbalIQ1"),
nsim = 100) #100.0%
powerSim(model2,
test = fixed("Visit:Diagnosis:verbalIQ1"),
nsim = 100) #97%
#There seems to be enough power for both the main effects and the interaction effect.
pc_inter <- powerCurve(model2,
test = fixed("Visit:Diagnosis:verbalIQ1"),
along = "Child.ID",
nsim = 100)
print(pc_inter) #around 35 is the required sample size to have a power estimate of above 80%, if you want to replicate the finding of a three way interaction effect.
plot(pc_inter)
pc_Visit <- powerCurve(model1,
test = fixed("Visit"),
along = "Child.ID",
nsim = 100)
print(pc_Visit) #around 7 is the required sample size to have a power estimate of above 80%, if you want to replicate the finding of a three way interaction effect.
plot(pc_Visit)
pc_Diagnosis <- powerCurve(model1,
test = fixed("Diagnosis"),
along = "Child.ID",
nsim = 100)
print(pc_Diagnosis) #around 53 is the required sample size to have a power estimate of above 80%, if you want to replicate the finding of a three way interaction effect.
plot(pc_Diagnosis)
pc_verbalIQ1 <- powerCurve(model1,
test = fixed("verbalIQ1"),
along = "Child.ID",
nsim = 100)
print(pc_verbalIQ1) #Apparently only around 3 are the required sample size to have a power estimate of above 80%, if you want to replicate the finding of a three way interaction effect.
plot(pc_verbalIQ1)
```
### Exercise 2
How would you perform a more conservative power analysis?
- Identify and justify a minimum effect size for each of your relevant effects
- take the model from exercise 1 and replace the effects with the minimum effect size that you'd accept.
- assess the power curve by Child.ID, identifying an ideal number of participants to estimate each effect
- if your power estimates do not reach an acceptable threshold simulate additional participants and repeat the previous analysis
- Report the power analysis and comment on what you can (or cannot) use its estimates for.
```{r}
###How would you perform a more conservative power analysis?
##Identify and justify a minimum effect size for each of your relevant effects
#Specifying the minimum effect size
fixef(model1)["Visit"] #0.23
summary(model1)
plot(df$CHI_MLU, df$Visit)
ggplot(df, aes(Visit, CHI_MLU, colour = Diagnosis))+
geom_point()+
geom_smooth(method="lm")
#take the model from exercise 1 and replace the effects with the minimum effect size that you'd accept.
h0 <- lmer(CHI_MLU ~ Visit + Diagnosis + (1+Visit|Child.ID),
df,
REML = F,
control = lmerControl(optimizer = "nloptwrap",
calc.derivs = F))
summary(h0)
fixef(h0)["Visit"] #0.23
fixef(h0)["DiagnosisTD"] #0.23
#Defining the model from exercise 1
h1 <- lmer(CHI_MLU ~ Visit * Diagnosis + (1+Visit|Child.ID),
df,
REML = F,
control = lmerControl(optimizer = "nloptwrap",
calc.derivs = F))
#Power simulation for Visit
summary(h1)
fixef(h1)["Visit"] #0.10
fixef(h1)["Visit"] <- 0.23 #Choosing 0.23 because the simpler model where there is no interaction says that there is a mean increase of 0.23 MLU per visit.
pc_Visit2 <- powerCurve(h1,
test = fixed("Visit"),
along = "Child.ID",
nsim = 100)
print(pc_Visit2) #There is no threshhold where we have a sufficient amount of power. An extension of our data is needed.
plot(pc_Visit2)
#Power simulation for diagnosis
fixef(h1)["DiagnosisTD"] #-0.23
fixef(h1)["DiagnosisTD"] <- 0.23 #Choosing 0.23 because the simpler model where there is no interaction says that there is a mean increase of 0.23 from being an ASD kid than being a TD kid. IS THIS RIGHT!=?!?!?!?!?!?
pc_Diagnosis2 <- powerCurve(h1,
test = fixed("Diagnosis"),
along = "Child.ID",
nsim = 100)
print(pc_Diagnosis2) #There is no threshhold where we have a sufficient amount of power. An extension of our data is needed.
plot(pc_Diagnosis2)
#Power simulation for interaction
fixef(h1)["Visit:DiagnosisTD"]
fixef(h1)["Visit:DiagnosisTD"] <- 0.1 #Just choosing an abritrary number
#assess the power curve by Child.ID, identifying an ideal number of participants to estimate each effect
pc_inter2 <- powerCurve(h1,
test = fixed("Visit:Diagnosis"),
along = "Child.ID",
nsim = 100)
print(pc_inter2)#around 65 is the required sample size to have a power estimate of above 80%, given that the effect size is changed to 0.1.
plot(pc_inter2)
```
### Exercise 3
Assume you have only the resources to collect 30 kids (15 with ASD and 15 TDs). Identify the power for each relevant effect and discuss whether it's worth to run the study and why
```{r}
```