线性混合模型的R功率模拟

线性混合模型的R功率模拟,r,simulation,lme4,lmertest,R,Simulation,Lme4,Lmertest,我需要做一个线性混合模型模拟,以获得不同样本大小的功率 我的模型是: 评级=y 固定效应,x=环 随机效应=参与者 我试过的代码如下。它仅返回“基于100个模拟”(0个警告,100个错误) α=0.05,nrow=2000’ 谢谢 #create a dataframe library(lmerTest) library(simr) library(tidyverse) Ring = c('Ring', 'NoRing') #from 1 to 10 (11 is not included).

我需要做一个线性混合模型模拟,以获得不同样本大小的功率

我的模型是:

评级=y

固定效应,x=环

随机效应=参与者

我试过的代码如下。它仅返回“基于100个模拟”(0个警告,100个错误) α=0.05,nrow=2000’

谢谢

#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

#创建数据帧
图书馆(lmerTest)
图书馆(simr)
图书馆(tidyverse)
环=c('Ring','NoRing')
#从1到10(不包括11)。
响铃=重复(响铃,次数=1000)
吸引力=楼层(runif(10,min=1,max=11))#这会产生随机数
#从1到10(不包括11)。

参与者在我运行它时,它告诉我“模型比较的能力(95%置信区间):0.00%(0.00,3.62)”。您必须编写更多的代码来模拟不同观察总数的实验数据集(您必须确定增加数据集是否意味着增加参与者数量,或增加每个参与者的观察数量……),我只想增加参与者数量。我不知道怎么做,但我会搜索,谢谢。