为什么线性混合模型在SAS和nlme中工作,而不是lme4?

时间:2016-06-30 02:26:09

标签: r sas lme4 nlme

我的数据包括对照组的20名受试者和实验组的20名受试者。感兴趣的DV是在每个参与者上测量的峰值功率的变化分数。还有一个虚拟变量xVarExp,其仅包括实验组中的受试者1。我对个人反应很感兴趣,这些数字的差异是对此进行总结的统计数据。我也对每个小组的手段感兴趣; Exptal和Control。

我的数据结构如下:

structure(list(Subject = structure(1:40, .Label = c("Alex", "Ariel", 
"Ashley", "Bernie", "Casey", "Chris", "Corey", "Courtney", "Devon", 
"Drew", "Dylan", "Frances", "Gene", "Jaimie", "Jean", "Jesse", 
"Jo", "Jody ", "Jordan", "Kelly", "Kerry", "Kim", "Kylie", "Lauren", 
"Lee", "Leslie", "Lindsay", "Morgan", "Pat", "Reilly", "Robin", 
"Sage", "Sam", "Sidney", "Terry", "Tristan", "Vic", "Wil", "Wynn", 
"Zane"), class = "factor"), Group = structure(c(1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L), .Label = c("Control", "Exptal"), class = "factor"), 
    xVarExp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1), DV = c(3.3, -0.8, 2.7, 2.8, 0.6, 5.2, 
    1, 3.4, 1.3, -2.4, 8.5, 3.5, -1.9, 4.3, 1.2, -1.9, -0.6, 
    1.3, -2.6, -1, -3.7, 1.9, 4.6, 2.9, 7.2, -1.7, 4.2, 3.9, 
    -3.2, 9.9, 2.7, -1.7, 7.9, 8.1, 3.8, 2.8, 4.6, 0.8, 2.5, 
    4.1)), .Names = c("Subject", "Group", "xVarExp", "DV"), row.names = c(NA, 
-40L), class = "data.frame")

统计员是SAS用户,并使用下面的代码获得合理的答案:

title "Analyzing change scores";
proc mixed data=import plots(only)=StudentPanel(conditional) alpha=0.1 nobound;
class Subject Group;
model DV=Group/residual outp=pred ;
random xVarExp/subject=Subject;
lsmeans Group/diff=control("Control") cl alpha=0.1;
run;

我开始使用R和lme4,我相信代码是:

Model1 <- lmer(DV ~ Group + (1|Subject/xVarExp), 
             data = RawData)

但是,我收到以下内容:Error: number of levels of each grouping factor must be < number of observations

我设法使用以下语法在nlme中使用与SAS输出匹配的建模工作:

Model2 <- lme(DV ~ Group, 
            random = ~ 1|xVarExp/Subject, data = RawData)

我的问题是:1)为什么模型适用于nlme而不是lme4? 2)如何匹配SAS语法以使模型进入lme4?

谢谢!

1 个答案:

答案 0 :(得分:4)

lme4 包中有一些导致错误的内置模型检查。如果需要使用lmer拟合不寻常的线性混合模型,则可以更改忽略模型默认情况下通过lmerControl中的参数检查该错误。

要允许具有与您所适合的模型中的剩余误差项相同数量的级别的随机效果,您需要将check.nobs.vs.nlevcheck.nobs.vs.nRE更改为{{1}来自默认"ignore"。因此,您希望每个组具有不同残差方差的模型可能看起来像

"stop"

但是,如果您想要的模型允许每个组有不同的残差差异,那么您可以考虑使用 nlme 中的Model1 <- lmer(DV ~ Group + (xVarExp-1|Subject), data = RawData, control = lmerControl(check.nobs.vs.nlev = "ignore", check.nobs.vs.nRE="ignore")) 。在gls中,您可以轻松扩展线性模型以允许非常数方差。该模型看起来像

gls

这两个模型给出了固定效应的相同估计值和标准误差:

Model2 <- gls(DV ~ Group, data = RawData, weights = varIdent(form = ~1|Group))