-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerCalc.R.rtf
More file actions
81 lines (79 loc) · 4.21 KB
/
powerCalc.R.rtf
File metadata and controls
81 lines (79 loc) · 4.21 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
{\rtf1\ansi\ansicpg1252\cocoartf2822
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;\red63\green108\blue175;\red0\green0\blue0;}
{\*\expandedcolortbl;;\cssrgb\c30980\c50588\c74118;\cssrgb\c0\c0\c0;}
\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
\deftab720
\pard\pardeftab720\sl398\partightenfactor0
\f0\fs34\fsmilli17333 \cf2 \expnd0\expndtw0\kerning0
# R-code for computing statistical power\
\pard\pardeftab720\partightenfactor0
\f1\fs29\fsmilli14667 \cf3 # Load necessary libraries\
library(simr)\
library(lme4)\
library(lmerTest)\
\'a0\
# Create mock data for 30 participants, each assigned to a condition (Control or Manipulation)\
set.seed(123)\
id <- rep(1:30, each=2)\'a0 # Each participant measured in one of two conditions\
group <- rep(c("Control", "Manipulation"), times=15)\'a0 # 15 per group\
simdf <- data.frame(id, group)\
\'a0\
# Set parameters for fixed effects\
fixed <- c(0, 0.8)\'a0 # Hypothetical large effect size for group\
\'a0\
# Set random effect variance for individual differences\
rand <- 0.6\'a0 # Variance attributable to participants\
\'a0\
# Set residual variance (error)\
res <- 1\
\'a0\
# Construct the mock model. `simr` will simulate a dependent variable "y" based on these parameters.\
modelsim <- makeLmer(y ~ group + (1|id), data=simdf, fixef=fixed, VarCorr=rand, sigma=res)\
summary(modelsim)\
\'a0\
# Power calculation: Test if there is any difference between "Control" and "Manipulation" groups\
set.seed(123)\
powerSim(modelsim, nsim=100, test=fcompare(y ~ 1))\
\'a0\
########Results############\
\'a0\
Linear mixed model fit by REML ['lmerMod']\
Formula: y ~ group + (1 | id)\
Data: simdf\
\'a0\
REML criterion at convergence: 185.9\
\'a0\
Scaled residuals: \
\'a0 Min\'a0\'a0\'a0\'a0\'a0\'a0 1Q\'a0\'a0 Median\'a0\'a0\'a0\'a0\'a0\'a0 3Q\'a0\'a0\'a0\'a0\'a0 Max \
-2.02467 -0.43228 -0.01981\'a0 0.50131\'a0 1.98160 \
\'a0\
Random effects:\
\'a0 Groups\'a0\'a0 Name\'a0\'a0\'a0\'a0\'a0\'a0\'a0 Variance Std.Dev.\
id\'a0\'a0\'a0\'a0\'a0\'a0 (Intercept) 0.6\'a0\'a0\'a0\'a0\'a0 0.7746\'a0 \
Residual\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 1.0\'a0\'a0\'a0\'a0\'a0 1.0000\'a0 \
Number of obs: 60, groups:\'a0 id, 30\
\'a0\
Fixed effects:\
\'a0 Estimate Std. Error t value\
(Intercept)\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 0.0000\'a0\'a0\'a0\'a0 0.2309\'a0\'a0 0.000\
groupManipulation\'a0\'a0 0.8000\'a0\'a0\'a0\'a0 0.2582\'a0\'a0 3.098\
\'a0\
Correlation of Fixed Effects:\
\'a0 (Intr)\
groupMnpltn -0.559\
#########\
> # Power calculation: Test if there is any difference between "Control" and "Manipulation" groups\
\'a0 > set.seed(123)\
> powerSim(modelsim, nsim=100, test=fcompare(y ~ 1))\
Simulating: |=\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 Simulating: |===\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 Simulating: |===========\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 Simulating: |==========================\'a0\'a0\'a0\'a0\'a0\'a0\'a0\'a0 Simulating: |==============================\'a0\'a0\'a0\'a0 Simulating: |================================== Simulating: |===================================Simulating: |===================================Simulating: |===================================Simulating: |===================================Power for model comparison, (95% confidence interval):======================================================================================|\
\'a0 87.00% (78.80, 92.89) ########## NICE!!##############\
\'a0\
Test: Likelihood ratio\
Comparison to y ~ 1 + [re]\
\'a0\
Based on 100 simulations, (0 warnings, 0 errors)\
alpha = 0.05, nrow = 60\
\'a0\
Time elapsed: 0 h 0 m 2 s\
}