[R-sig-ME] Behavior of coef() for lmer() model w/ level-2 variance stratified

David Afshartous dafshartous at med.miami.edu
Wed Feb 6 23:09:31 CET 2008



Prof Bates:

FYI, coef() does not seem to work for models fit w/ lmer() where the level-2
variance is stratified, e.g., depends on treatment group.  Is there a quick
fix, or should I simply calculate the desired coefficients manually?
Example code below.

Thanks,
David


J = 10; K = 4
set.seed(500)
fake = Strat.mean.var.simple (J,K)
lme.no.strat = lmer (y ~  treatment.ind + (1 | person1) , data = fake)
lme.strat = lmer (y ~  treatment.ind + ( 0 + placebo.ind | person1) + (0 +
treatment.ind | person1), data = fake)
coef(lme.strat)
Error in coef(lme.strat) : unable to align random and fixed effects

coef(lme.no.strat)

An object of class ³coef.lmer²
[[1]]
   (Intercept) treatment.ind
1          6.0           2.9
2          7.9           2.9
3          7.4           2.9
4          5.1           2.9
5          6.7           2.9
6          4.0           2.9
7          8.1           2.9
8          8.2           2.9
9          6.4           2.9
10         6.4           2.9

#####################################################
J = 10
K = 4
Strat.mean.var.simple <- function (J, K){
    time <- rep(seq(0,1, ,length=K), J) # K measurements
    person <- rep(1:(J/2), each = K)
    treatment <- rep(0:1, each = J/2)
    treatment.ind <- rep(0:1, each = (J/2)*K)
    person1 <- rep(1:J, ,each = K)
    placebo.ind.1 <- treatment.ind < 1
    placebo.ind = ifelse( placebo.ind.1, 1, 0)
#
    mu.a.true.P = 4.8
    mu.a.true.T = 8.8
    sigma.a.true.P = 2.2
    sigma.a.true.T = 4.2
    sigma.y.true = 1.2
#
    a.true.P = rnorm (J/2, mu.a.true.P, sigma.a.true.P)
    a.true.T = rnorm (J/2, mu.a.true.T, sigma.a.true.T)
#
    y.P <- rnorm( (J/2)*K, a.true.P[person], sigma.y.true)
    y.T <- rnorm( (J/2)*K, a.true.T[person], sigma.y.true)
    y <- c(y.P, y.T)
    return ( data.frame (y, time, person1, treatment.ind, placebo.ind))
}




More information about the R-sig-mixed-models mailing list