重复测量方差分析,具有随机效应并进行球度测试和校正

时间:2019-07-19 20:35:07

标签: r statistics regression anova nlme

我正在分析一个数据集,其中随时间测量了来自不同治疗方法的重复种群。我想用人口随机效应进行重复测量anova,并用Mauchly球形度检验和p值惩罚(当违反球形度时需要)。

我正在尝试使用Anova软件包中的car命令,但是我很难添加随机效果。我可以使用car软件包对球性和G-G校正进行Mauchly检验,并进行重复测量ANOVA。

以下是使用sleepstudy数据集的示例代码

#change to wide format
sleepwide<-dcast(sleepstudy, Subject ~Days, mean, value.var="Reaction")

#rename columns
names(sleepwide) = c("Subject","x0", "x1", "x2", "x3", "x4", "x5",
                     "x6", "x7", "x8", "x9")

#create treatment column to used as fixed effect
sleepwide$treatment<-c('a','b','a','b','a','b','a','b','a','b','a','b',
                       'a','b','a','b','a','b')

#run a linear model for all time points with treatment as a fixed effect
z1<-lm(cbind(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) ~ treatment, data=sleepwide)

#dictate the sample design 
sample<-with(sleepwide, ordered(c("x0", "x1", "x2", "x3", "x4", "x5", "x6",
             "x7", "x8", "x9")), levels=c("x0", "x1", "x2", "x3", "x4", "x5", 
             "x6", "x7", "x8", "x9"))

idata=data.frame(sample)

#run Anova in car package 
ranova<-Anova(z1, idata=idata, idesign=~sample, type="III")

当我尝试以随机效果运行主题时,运行与上面相同的代码(例如,z2代替上面的z1),它将运行测试。

    z2<-lme(cbind(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) ~ treatment, 
            random=(~1|Subject), data=sleepwide)

有人能用随机效应进行莫希利检验+校正来进行重复测量方差分析的方法吗?

0 个答案:

没有答案