Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use update() for random part in lmer()?

Tags:

r

lme4

I would like to use the update() function to update the random part of my model, specifically, adding a random effect. Most examples (help("update"), help("update.formula"), lme4:mixed effects modeling with R) focus on the fixed part of the model. How would I go from fm0 to fm1 using update() in the example below?

library(lme4)
(fm0 <- lmer(Reaction ~ Days + (1 | Subject), sleepstudy))
(fm1 <- lmer(Reaction ~ Days + (1 + Days | Subject), sleepstudy))
like image 855
Richard Avatar asked Jul 19 '17 10:07

Richard


People also ask

How do you specify a random slope in LMER?

To accomplish this in LMER just add the variables for which we want to add random slopes to the random part of the input. This means that (1|class) becomes (1+sex+extrav |class) . We can see that all the fixed regression slopes are still significant.

What are random effects in LMER?

The random effects: (1 + Time | Chick) which allows individual chicks to vary randomly in terms of their intercept (starting weight) and their effect of Time (weight change over time, also called a “random slope”, but I think that terminology can get confusing when fitting models with nonlinear predictors).

What is the difference between LMER and Glmer?

The lmer() function is for linear mixed models and the glmer() function is for generalized mixed models.

What is LMER function?

lmer ): formula : a two-sided linear formula describing both the fixed-effects and random-effects part of the model, with the response on the left of the ~ operator and predictors and random effects on the right-hand side of the ~ operator.


1 Answers

I doubt this will be useful in your case, but you have to remove the random effect and then add the desired on back in:

update(fm0, . ~ . -(1|Subject) + (1 + Days | Subject))
like image 152
Remko Duursma Avatar answered Oct 11 '22 11:10

Remko Duursma