[R-sig-ME] factor specific residual variance for random coefficient model with lmer
Thierry Onkelinx
thierry.onkelinx at inbo.be
Thu Jun 11 09:00:57 CEST 2015
You are mixing lme4 and nlme syntax. Varident is a nlme function.
Op 11-jun.-2015 05:23 schreef "li li" <hannah.hlx op gmail.com>:
> Ok. I found from R help page that the weights argument could
> accomplish different residual varainces for different factor levels
> like below.
>
>
> fm2 <- lmer( dv ~ time.num*drug + (0+ drug + time.num | Patient ),
> data=dat.new,
> weights = varIdent(form = ~1 | drug))
> summary(fm2)
>
>
> But the following error term returned.
>
>
> Error in summary(fm2) :
> error in evaluating the argument 'object' in selecting a method for
> function 'summary': Error: object 'fm2' not found
>
> Any advice?
>
> Thanks
> Hanna
>
> 2015-06-10 21:14 GMT-04:00, li li <hannah.hlx op gmail.com>:
> > 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))
> >
>
> _______________________________________________
> R-sig-mixed-models op r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list