Power simulation in R for a linear mixed model

92 views Asked by At

I need to do a linear mixed model simulation to get power for varying sample sizes.

My model is:

Ratings = y

Fixed effect, x = Ring

Random effect = participants

The code I tried is below. It only returns 'Based on 100 simulations, (0 warnings, 100 errors) alpha = 0.05, nrow = 2000' ....

Thank you!!

#create a dataframe
library(lmerTest)
library(simr)
library(tidyverse)
Ring = c('Ring', 'NoRing')
#from 1 to 10 (11 is not included).
Ring = rep(Ring, times = 1000)
attractiveness = floor(runif(10, min=1, max=11)) #this creates random numbers
#from 1 to 10 (11 is not included).

participants<-rep(factor(1:100),each=20)
targetID = rep(c(1,2,3,4,5,6,7,8,9,10), each= 2)
targetImage= rep(targetID, times= 100)
Ratings = rep(attractiveness, times = 200)
data<-data.frame(participants, Ring, targetImage, Ratings)
#parameters for the model:

## Intercept and slopes for ring
fixed <- c(3, 0.5)

## Random intercepts for participants 
rand <- 0.5

## residual variance
res <- 2
model <- makeLmer(Ratings ~ Ring + (1|participants), fixef=fixed, 
                  VarCorr=rand, sigma=res, data=data)
sim_treat <- powerSim(model, nsim=100, test = fcompare(Ratings~Ring))
sim_treat

0

There are 0 answers