[R-sig-ME] factor specific residual variance for random coefficient model with lmer

li li hannah.hlx at gmail.com
Thu Jun 11 03:14:11 CEST 2015


Hi all,
  I am wondering how to specify the model fm1 below so that the two
groups (treatment and control) specified by the column drug in the
data matrix have different residual variances. Any suggestion?
  Please see the codes below.
  Thanks very much!
    Hanna




set.seed(500)
n.timepoints <- 8
n.subj.per.tx <- 20
sd.d <- 5;
sd.p <- 2;
sd.res <- 1.3
drug <- factor(rep(c("D", "P"), each = n.timepoints, times =
n.subj.per.tx))
drug.baseline <- rep( c(0,5), each=n.timepoints, times=n.subj.per.tx )
Patient <- rep(1:(n.subj.per.tx*2), each = n.timepoints)
Patient.baseline <- rep( rnorm( n.subj.per.tx*2, sd=c(sd.d, sd.p) ),
each=n.timepoints )
time <- factor(paste("Time-", rep(1:n.timepoints, n.subj.per.tx*2),
sep=""))
time.baseline <-
rep(1:n.timepoints,n.subj.per.tx*2)*as.numeric(drug=="D")
dv <- rnorm( n.subj.per.tx*n.timepoints*2,
mean=time.baseline+Patient.baseline+drug.baseline, sd=sd.res )
dat.new <- data.frame(time, drug, dv, Patient)
dat.new$time.num = rep(1:n.timepoints, n.subj.per.tx*2)

library(lme4)
fm1 <- lmer( dv ~ time.num*drug + (0+ drug + time.num | Patient ),
data=dat.new )
summary(fm1)
resid(fm1)
plot(resid(fm1))



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