2
$\begingroup$

I would like to explain a variable a with a variable b and I know the relation between a and b is linear and depends on a variable c. This is why I am using a linear mixed-effect model.

But I am still not sure of the following models I need to use (and why they are different at all): a~b+(1+b|c) and a~(1+b|c)

library(lme4)
set.seed(1)
b=runif(100);c=sample(3,100,replace=T)
a=jitter(ifelse(c==1,2*b+1,ifelse(c==2,3*b+2,4*b+3)),amount=0.1)

coef(lmer(a~b+(1+b|c)))

$c
  (Intercept)        b
1    0.935440 2.086795
2    1.971616 3.039178
3    2.996026 3.980746


coef(lmer(a~(1+b|c)))
$c
         b (Intercept)
1 2.084875   0.9365474
2 3.038673   1.9718491
3 3.981722   2.9954843

Both models seem to give the same (good) result.

$\endgroup$
2
  • $\begingroup$ Do you have repeated measures? $\endgroup$
    – Bruna w
    Commented Nov 27, 2017 at 11:57
  • $\begingroup$ @Brunaw Yes: I added an example of the type of data I use $\endgroup$ Commented Nov 27, 2017 at 12:01

2 Answers 2

2
$\begingroup$

The second model does not fit your data.

Both models assume that there is a linear dependence between the response and the variable $b$ for each level of the variable $c$. The slopes are randomly distributed around a fixed slope. The difference between the two models is that the second one assumes that this fixed slope is zero. Take a look at the random effects for $b$ (differences between the estimated random slope and the true slope):

> ranef(lmer(a~b+(1+b|c)))
$c
   (Intercept)            b
1 -1.032253982 -0.948777953
2  0.003921909  0.003604753
3  1.028332073  0.945173200
> ranef(lmer(a~(1+b|c)))
$c
  (Intercept)        b
1    2.263031 2.084875
2    3.298333 3.038673
3    4.321968 3.981722

Clearly, the random effects in the second model do not look centered around zero, however this is an assumption of the model.

By the way the second model is the same as the first model constrained to have a zero fixed slope, and then you can compare the two models with a likelihood ratio test:

> fit1 <- lmer(a~b+(1+b|c))
> fit2 <- lmer(a~(1+b|c))
> anova(fit2, fit1)
refitting model(s) with ML (instead of REML)
Data: NULL
Models:
fit2: a ~ (1 + b | c)
fit1: a ~ b + (1 + b | c)
     Df     AIC     BIC logLik deviance Chisq Chi Df Pr(>Chisq)   
fit2  5 -250.29 -237.26 130.14  -260.29                           
fit1  6 -256.67 -241.04 134.34  -268.67 8.387      1   0.003779 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The likelihood ratio test rather rejects the constrained model.

For your true data, you should choose the second model if you have any reason to believe that the overall slope is $0$.

$\endgroup$
4
  • $\begingroup$ Thanks, if I understand well this means that whether the overall intercept is not 0, I need to build a model such as a~1+b + (1+b|c) ? $\endgroup$ Commented Nov 28, 2017 at 10:05
  • $\begingroup$ @user3507085 The intercept (the 1 term) is automatically included. $\endgroup$ Commented Nov 28, 2017 at 10:06
  • $\begingroup$ Thus if the overall intercept is 0 the model is a ~ 0 + b + (1+b|c) ?! :) $\endgroup$ Commented Nov 28, 2017 at 10:07
  • $\begingroup$ @user3507085 Yes. Or, equivalently, -1 + b + (1+b | c). $\endgroup$ Commented Nov 28, 2017 at 10:29
0
$\begingroup$

One first comment is that in order to make your code fully reproducible you should set a seed for the variables (set.seed() in R) and tell us that you're using the lme4 package.

On your fisrt model you're using the variable b, which means you're going to estimate a coefficient for it. In the second model you're not doing that: this is the main difference between your models.

The syntax (1+b|c) does not include b in the model, it is used to tell R that your random effects are constant in b. I don't really know if this makes sense, because b is the only variable in your model.

$\endgroup$
1
  • 1
    $\begingroup$ I thought (1+b|c) means a random intercept and random slope are being fit, with levels defined by c. So the model looks like $y_{ik}=\beta_0+u_{0k} +b_{ik}u_{bk} + e_{ik}$ where you have $u_{0k} iid\sim N (0,\sigma_{u0}^2) $ and $u_{bk} iid\sim N (0,\sigma_{ub}^2) $ and $e_{ik} iid\sim N (0,\sigma_{e}^2)$. The index $i $ is for the unit, and the index $k $ is for the values of "c" ($k=1,2,3$ in the example) $\endgroup$ Commented Nov 27, 2017 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.