0

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

semchena31
  • 51
  • 1
  • 7
  • when I ran it, it told me "Power for model comparison, (95% confidence interval): 0.00% ( 0.00, 3.62)". You have to write some more code that will simulate experimental data sets for differing total numbers of observations (you'll have to decide whether growing the data set means e.g. increasing the number of participants, or increasing the number of observations per participant ...) – Ben Bolker Jun 01 '21 at 02:38
  • I only want to increase the number of participants. I do not know how to do that but I will search, thank you. – semchena31 Jun 03 '21 at 09:45

0 Answers0