简体   繁体   English

为什么线性混合模型在SAS和nlme中有效但在lme4中无效?

[英]Why does a linear mixed model work in SAS and nlme but not lme4?

My data consists of 20 subjects in a control group and 20 in an experimental group. 我的数据由对照组中的20名受试者和实验组中的20名受试者组成。 The DV of interest is a change score of peak power measured on each participant. 感兴趣的DV是在每个参与者上测得的峰值功率变化分数。 There is also a dummy variable xVarExp that includes a 1 for subjects in the experimental group only. 还有一个虚拟变量xVarExp ,其中仅针对实验组中的对象包含1。 I am interested in individual responses and the variance of these numbers is the statistic summarising this. 我对个人回答感兴趣,这些数字的差异就是对此的统计总结。 I am also interested in the means of each group; 我也对每个小组的手段感兴趣; Exptal and Control. 控制和控制。

My data is structured as follows: 我的数据结构如下:

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")

The statistician is a SAS user and has used the code below to obtain sensible answers: 该统计员是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;

I am beginning to use R and lme4, whereby I believe the code is: 我开始使用R和lme4,我相信代码是:

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

However, I receive the following: Error: number of levels of each grouping factor must be < number of observations 但是,我收到以下信息: Error: number of levels of each grouping factor must be < number of observations

I managed to get the modelling working, using the syntax below, in nlme which matches the output of SAS: 我使用与SAS输出匹配的nlme,使用下面的语法设法使建模工作:

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

My questions are: 1) Why does the model work in nlme but not lme4? 我的问题是:1)为什么该模型在nlme中有效,但在lme4中无效? and 2) How can I match the SAS syntax to get the model going in lme4? 和2)如何匹配SAS语法以使模型在lme4中运行?

Thank you! 谢谢!

The lme4 package has some built-in model checks that are leading to errors. lme4软件包具有一些内置的模型检查,这些检查会导致错误。 If you need to fit an unusual linear mixed model with lmer , you can change ignore the model checks that error by default via arguments in lmerControl . 如果您需要使用lmer拟合异常线性混合模型, lmer可以更改默认值,忽略模型会通过lmerControl参数检查该错误。

To allow for a random effect that has the same number of levels as the residual error term like in the model you are fitting, you would need to change check.nobs.vs.nlev and check.nobs.vs.nRE to "ignore" from the default "stop" . 为了允许具有与残留误差项相同级别的数量的随机效应(如您要拟合的模型),您需要将check.nobs.vs.nlevcheck.nobs.vs.nRE更改为"ignore"从默认的"stop" So a model where you want a different residual variance per group might look something like 因此,您希望每个组具有不同残差的模型可能看起来像

Model1 <- lmer(DV ~ Group + (xVarExp-1|Subject), 
            data = RawData, control = lmerControl(check.nobs.vs.nlev = "ignore",
                                        check.nobs.vs.nRE="ignore"))

However, if the model you want is one that allows for a different residual variance per group then you might consider using gls from nlme . 但是,如果您想要的模型允许每个组具有不同的残差,那么您可以考虑使用nlme的 gls In gls you can easily extend the linear model to allow for nonconstant variance. gls您可以轻松扩展线性模型以允许非恒定方差。 That model would look like 该模型看起来像

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

These two models give the same estimates and standard errors for the fixed effects: 这两个模型对固定效果给出了相同的估计值和标准误差:

summary(Model1)$coefficients
            Estimate Std. Error  t value
(Intercept)    1.395  0.6419737 2.172986
GroupExptal    1.685  1.0449396 1.612533

summary(Model2)$tTable
            Value Std.Error  t-value    p-value
(Intercept) 1.395 0.6419737 2.172986 0.03608378
GroupExptal 1.685 1.0449396 1.612533 0.11512145

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM