Random slope for time in subject not working in lme4

Andrea Gragnano

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

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

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?

Ben Bolker

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.

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

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

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

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.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

lme4 fails to calculate random intercepts with no warnings

From Dev

How to compare a model with no random effects to a model with a random effect using lme4?

From Dev

lme4: how to specify 2 correlations with random intercept, without adding correlations between random slopes

From Dev

Extract raw model matrix of random effects from lmer objects (lme4, R)

From Dev

How to specify different random effects in nlme vs. lme4?

From Dev

Design matrix for MLM from library(lme4) with fixed and random effects

From Dev

Extract raw model matrix of random effects from lmer objects (lme4, R)

From Dev

Incorporating time series into a mixed effects model in R (using lme4)

From Dev

drawing a slope in random circles python

From Dev

random not working + counting time in C++

From Dev

Mailto with subject not working

From Dev

Logitech wireless keyboard stops working after random intervals of time

From Dev

Angular 6 Subject Subscribe is not working

From Dev

Outlook : Prepend time to appointment subject

From Dev

How to efficiently generate a straight line with random slope and intercept in Python?

From Dev

How to modify slots lme4 >1.0

From Dev

Convergence error for development version of lme4

From Dev

Setting rhoend parameter with lme4

From Dev

Prediction with lme4 on new levels

From Dev

R stargazer, lme4 and lmerTest incompatibility

From Dev

bootstrapping with lme4 model and missing values

From Dev

lme4 calculate confidence intervals of covariances

From Dev

Setting rhoend parameter with lme4

From Dev

Interpreting glmer confidence interval in lme4

From Dev

Using car:::linearHypothesis() with lme4 models

From Dev

Hide warning message in lme4

From Dev

Email subject in Laravel 4

From Dev

foundation tooltip is not working. Any idea on this subject?

From Dev

foundation tooltip is not working. Any idea on this subject?

Related Related

  1. 1

    lme4 fails to calculate random intercepts with no warnings

  2. 2

    How to compare a model with no random effects to a model with a random effect using lme4?

  3. 3

    lme4: how to specify 2 correlations with random intercept, without adding correlations between random slopes

  4. 4

    Extract raw model matrix of random effects from lmer objects (lme4, R)

  5. 5

    How to specify different random effects in nlme vs. lme4?

  6. 6

    Design matrix for MLM from library(lme4) with fixed and random effects

  7. 7

    Extract raw model matrix of random effects from lmer objects (lme4, R)

  8. 8

    Incorporating time series into a mixed effects model in R (using lme4)

  9. 9

    drawing a slope in random circles python

  10. 10

    random not working + counting time in C++

  11. 11

    Mailto with subject not working

  12. 12

    Logitech wireless keyboard stops working after random intervals of time

  13. 13

    Angular 6 Subject Subscribe is not working

  14. 14

    Outlook : Prepend time to appointment subject

  15. 15

    How to efficiently generate a straight line with random slope and intercept in Python?

  16. 16

    How to modify slots lme4 >1.0

  17. 17

    Convergence error for development version of lme4

  18. 18

    Setting rhoend parameter with lme4

  19. 19

    Prediction with lme4 on new levels

  20. 20

    R stargazer, lme4 and lmerTest incompatibility

  21. 21

    bootstrapping with lme4 model and missing values

  22. 22

    lme4 calculate confidence intervals of covariances

  23. 23

    Setting rhoend parameter with lme4

  24. 24

    Interpreting glmer confidence interval in lme4

  25. 25

    Using car:::linearHypothesis() with lme4 models

  26. 26

    Hide warning message in lme4

  27. 27

    Email subject in Laravel 4

  28. 28

    foundation tooltip is not working. Any idea on this subject?

  29. 29

    foundation tooltip is not working. Any idea on this subject?

HotTag

Archive