-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPower.Rmd
118 lines (79 loc) · 3.54 KB
/
Power.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
---
title: "Power simulations"
author: "Helio"
date: '2022-12-03'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
summary(pupil_arousal_findings$pupil_from_arousal)
install.packages("simr")
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
library(simr)
library(lmerTest)
# Power for predictor 'x', (95% confidence interval):
power_models<- list()
table(is.na(db_full4new_stim_screen_pupil_nopract$arousal_c))
table(is.na(db_full4new_stim_screen_pupil_nopract$pup_basCor))
power_models$pupil <- lmer(pup_basCor ~ arousal_c +(1 | ssid), REML = FALSE,
data = subset(db_full4new_stim_screen_pupil_nopract,
# pupil_outlier == FALSE &
Group == "NT" & !is.na(pup_basCor) &
!is.na(arousal_c)
# arousal_outler == FALSE
))
db_full4new_stim_screen_pupil_nopract
power_models$pupil1<- power_models$pupil
fixef(power_models$pupil1)["arousal_c"]<- .4
sim_.4 <- powerSim(power_models$pupil1, nsim = 100)
sim_.4
# Power for predictor 'arousal_c', (95% confidence interval):
# 100.0% (96.38, 100.0)
?powerCurve
curve<- powerCurve(power_models$pupil1, nsim = 100)
plot(curve)
model3 <- extend(power_models$pupil1, along="ssid", n=1)
pc3 <- powerCurve(power_models$pupil1, along="ssid", nsim = 10)
plot(pc3)
extendeddata_along_ssid<- extend(power_models$pupil1, along="ssid", n=100)
pc_extended100 <- powerCurve(extendeddata_along_ssid, along="ssid", nsim = 100)
pc_extended100
plot(pc_extended100)
```
SCR
```{r}
power_models$BIO_CDA.PhasicMax <- lmer(BIO_CDA.PhasicMax ~ valence_c + (1|ssid) + (1|stimIAPS),
REML = FALSE,
data = subset(db_full4new_stim_screen_pupil_nopract_nt_304,
!is.na(arousal_c)&
!is.na(BIO_CDA.PhasicMax)))
table(is.na(db_full4new_stim_screen_pupil_nopract_nt_304$arousal_c))
table(is.na(db_full4new_stim_screen_pupil_nopract_nt_304$BIO_CDA.PhasicMax))
summary(power_models$BIO_CDA.PhasicMax)
power_models$BIO_CDA.PhasicMax1<- power_models$BIO_CDA.PhasicMax
# 0.01571715
fixef(power_models$BIO_CDA.PhasicMax)["valence_c"]
# reverse log to get proper unites wot meaninful effect size
0.01571715
ex
fixef(power_models$BIO_CDA.PhasicMax1)["valence_c"] <- -.1
summary(power_models$BIO_CDA.PhasicMax)
summary(power_models$BIO_CDA.PhasicMax1)
sim_SCR <- powerSim(power_models$BIO_CDA.PhasicMax1,
nsim = 100)
# extendedscr100<- extend(power_models$BIO_CDA.PhasicMax1, along="ssid", n=100)
# extendedscr100_int<- extend(power_models$BIO_CDA.PhasicMax1, along="ssid", n=100)
# pc_scr100<- powerCurve(extendedscr100, along="ssid", nsim = 100)
# plot(pc_scr100)
extendedscr1002<- extend(power_models$BIO_CDA.PhasicMax1, along="ssid", n=100)
# pc_scr100_2<- powerCurve(extendedscr1002, along="ssid", nsim = 100)
# extendedscr100_int@call
pc_scr100_int<- powerCurve(extendedscr1002,
test = fixed("valence_c", "z"),
along="ssid", nsim = 50)
plot(pc_scr100_int)
```