[R] Extracting level-1 variance from lmer()

From: David Afshartous <dafshartous_at_med.miami.edu>
Date: Tue, 05 Feb 2008 14:37:05 -0500

All,

How does one extract the level-1 variance from a model fit via lmer()?

In the code below the level-2 variance component may be obtained via subscripting, but what about the level-1 variance, viz., the 3.215072 term? (actually this term squared) Didn't see anything in the archives on this.

Cheers,
David

> fm <- lmer( dv ~ time.num*drug + (1 | Patient.new), data=dat.new )

> VarCorr(fm)

$Patient.new
1 x 1 Matrix of class "dpoMatrix"

            (Intercept)
(Intercept) 8.519916

attr(,"sc")

   scale
3.215072

> VarCorr(fm)[[1]][1]

[1] 8.519916
> VarCorr(fm)[[2]][1]

Error in VarCorr(fm)[[2]] : subscript out of bounds

##########################################################
set.seed(500)
n.timepoints <- 4
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.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(drug, dv)
dat.new$Dind <- as.numeric(dat.new$drug == "D")
dat.new$Pind <- as.numeric(dat.new$drug == "P")
dat.new$time.num = rep(1:n.timepoints, n.subj.per.tx*2)
dat.new$Patient.new = rep(1:20, each=8)

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 05 Feb 2008 - 19:34:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 20:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive