0

From the post below,

Replace lm coefficients in [r]

I am also interested in changing the coefficients of a mixed model fitted with lmer. For e.g. in a a model of the form below:

mod <- lmer(y ~ x1 + x2 + x3 + (1|class/subjects), data=data)

How can I change the coefficients of x1 and x2 to another number (0 or 0.1 or 1 etc).

89_Simple
  • 3,393
  • 3
  • 39
  • 94

1 Answers1

2

I don't see a valid reason to do this and you might encounter some mighty dragons, but it is easy to do.

library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
summary(fm1)$coef
#             Estimate Std. Error   t value
#(Intercept) 251.40510   6.823773 36.842535
#Days         10.46729   1.545958  6.770744

fm1@beta[names(fixef(fm1)) == "Days"] <- 0
summary(fm1)$coef
#            Estimate Std. Error  t value
#(Intercept) 251.4051   6.823773 36.84253
#Days          0.0000   1.545958  0.00000
Roland
  • 127,288
  • 10
  • 191
  • 288