对象在lme4中不工作的时间的随机斜率 [英] Random slope for time in subject not working in lme4

查看:44
本文介绍了对象在lme4中不工作的时间的随机斜率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在带有lme4(1.1-7)的模型中插入随机斜率:

I can not insert a random slope in this model with lme4(1.1-7):

> difJS<-lmer(JS~Tempo+(Tempo|id),dat,na.action=na.omit)
Error: number of observations (=274) <= number of random effects (=278) for term 
(Tempo | id); the random-effects parameters and the residual variance (or scale
parameter) are probably unidentifiable

使用nlme可以正常工作:

With nlme it is working:

    > JSprova<-lme(JS~Tempo,random=~1+Tempo|id,data=dat,na.action=na.omit)
    > summary(JSprova)
Linear mixed-effects model fit by REML Data: dat
AIC      BIC    logLik
769.6847 791.3196 -378.8424

Random effects:
Formula: ~1 + Tempo | id
Structure: General positive-definite, Log-Cholesky parametrization
            StdDev    Corr
(Intercept) 1.1981593 (Intr)
Tempo       0.5409468 -0.692
Residual    0.5597984       

Fixed effects: JS ~ Tempo 
                Value  Std.Error  DF   t-value p-value
(Intercept)  4.116867 0.14789184 138 27.837013  0.0000
Tempo       -0.207240 0.08227474 134 -2.518874  0.0129
Correlation: 
      (Intr)
Tempo -0.837

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-2.79269550 -0.39879115  0.09688881  0.41525770  2.32111142

Number of Observations: 274
Number of Groups: 139

我认为这是缺少数据的问题,因为在极少数情况下,DV的时间2缺少数据,但使用 na.action = na.omit 不应将两者打包表现得一样吗?

I think it is a problem of missing data as I have few cases where there is a missing data in time two of the DV but with na.action=na.omit should not the two package behave in the same way?

推荐答案

它与 lme 是兼容的",但我有99%的把握确保您的随机斜率确实与残差变化混淆.问题在于,每个受试者只有两个测量值(或者在4种情况下每个受试者只有一个测量值-但这在这里并不重要),因此每个人的随机斜率加上随机截距会为每个观察结果带来随机效果.

It is "working" with lme, but I'm 99% sure that your random slopes are indeed confounded with the residual variation. The problem is that you only have two measurements per subject (or only one measurement per subject in 4 cases -- but that's not important here), so that a random slope plus a random intercept for every individual gives one random effect for every observation.

如果您尝试在 lme 拟合上尝试 intervals(),则会出现一个错误,指出方差-协方差矩阵无法识别.

If you try intervals() on your lme fit, it will give you an error saying that the variance-covariance matrix is unidentifiable.

您可以通过禁用某些可识别性检查来强制 lmer 执行此操作(请参见下文).

You can force lmer to do it by disabling some of the identifiability checks (see below).

library("lme4")
library("nlme")
library("plyr")

将数据限制为每个人只有两点:

Restrict the data to only two points per individual:

sleepstudy0 <- ddply(sleepstudy,"Subject",
      function(x) x[1:2,])
m1 <- lme(Reaction~Days,random=~Days|Subject,data=sleepstudy0)
intervals(m1)
## Error ... cannot get confidence intervals on var-cov components

lmer(Reaction~Days+(Days|Subject),data=sleepstudy0)
## error

如果需要,可以强制 lmer 使其适合该模型:

If you want you can force lmer to fit this model:

m2B <- lmer(Reaction~Days+(Days|Subject),data=sleepstudy0,
        control=lmerControl(check.nobs.vs.nRE="ignore"))
## warning messages

估计方差与 lme 估计的方差不同,但这并不奇怪,因为某些参数是共同无法识别的.

The estimated variances are different from those estimated by lme, but that's not surprising since some of the parameters are jointly unidentifiable.

如果您仅对推断固定效果感兴趣,可以 忽略这些问题,但我不建议这样做.

If you're only interested in inference on the fixed effects, it might be OK to ignore these problems, but I wouldn't recommend it.

明智的做法是认识到坡度之间的变化是无法识别的.在坡度之间可能存在个体差异,但是您无法使用此模型进行估算.不要尝试拟合随机截距模型,并让隐式/默认随机误差项处理斜率之间的变化.

The sensible thing to do is to recognize that the variation among slopes is unidentifiable; there may be among-individual variation among slopes, but you just can't estimate it with this model. Don't try; fit a random-intercept model and let the implicit/default random error term take care of the variation among slopes.

关于CrossValidated,有一个最近的相关问题;在那里,我还引用了另一个示例.

There's a recent related question on CrossValidated; there I also refer to another example.

这篇关于对象在lme4中不工作的时间的随机斜率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆