Extracting variance components from lmer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting variance components from lmer

Rick DeShon
Hi All.

I need a bit of help extracting the residual error variance from the VarCorr
structure from lmer.

#Here's a 2-way random effects model
lmer.1    <- lmer(rating ~ (1|person)+(1|rater), data = dat)

#Get the structure
vc.fit <- VarCorr(lmer.1)

#results in.....
$person
1 x 1 Matrix of class "dpoMatrix"
            (Intercept)
(Intercept)   0.7755392

$rater
1 x 1 Matrix of class "dpoMatrix"
            (Intercept)
(Intercept)   0.2054469

attr(,"sc")
[1] 0.5051518

#I can pull out the person and rater variance components easy enough. For
example...
vc.person <- vc.fit$person@x

I'm sure it's simple but I have not been able to grab the residual variance
in the last matrix.  I simply wish to asign the residual to a scalar
variable.  Any suggestions would be appreciated!

Thanks!

Rick DeShon


--
Rick DeShon
306 Psychology Building
Department of Psychology
Michigan State University
East Lansing, MI 48824-1116

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Extracting variance components from lmer

Christoph Buser
Hi Rick

There may be a better way, but the following should work:
 
attributes(vc.fit)$sc

Regards,

Christoph Buser

--------------------------------------------------------------
Christoph Buser <[hidden email]>
Seminar fuer Statistik, LEO C13
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-44-632-4673 fax: 632-1228
http://stat.ethz.ch/~buser/
--------------------------------------------------------------


Rick DeShon writes:
 > Hi All.
 >
 > I need a bit of help extracting the residual error variance from the VarCorr
 > structure from lmer.
 >
 > #Here's a 2-way random effects model
 > lmer.1    <- lmer(rating ~ (1|person)+(1|rater), data = dat)
 >
 > #Get the structure
 > vc.fit <- VarCorr(lmer.1)
 >
 > #results in.....
 > $person
 > 1 x 1 Matrix of class "dpoMatrix"
 >             (Intercept)
 > (Intercept)   0.7755392
 >
 > $rater
 > 1 x 1 Matrix of class "dpoMatrix"
 >             (Intercept)
 > (Intercept)   0.2054469
 >
 > attr(,"sc")
 > [1] 0.5051518
 >
 > #I can pull out the person and rater variance components easy enough. For
 > example...
 > vc.person <- vc.fit$person@x
 >
 > I'm sure it's simple but I have not been able to grab the residual variance
 > in the last matrix.  I simply wish to asign the residual to a scalar
 > variable.  Any suggestions would be appreciated!
 >
 > Thanks!
 >
 > Rick DeShon
 >
 >
 > --
 > Rick DeShon
 > 306 Psychology Building
 > Department of Psychology
 > Michigan State University
 > East Lansing, MI 48824-1116
 >
 > [[alternative HTML version deleted]]
 >
 > ______________________________________________
 > [hidden email] mailing list
 > https://stat.ethz.ch/mailman/listinfo/r-help
 > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Extracting variance components from lmer

Douglas Bates-2
On 2/21/06, Christoph Buser <[hidden email]> wrote:
> Hi Rick
>
> There may be a better way, but the following should work:
>
> attributes(vc.fit)$sc

That works but a more direct way would be

attr(vc.fit, "sc")

By the way,  that value is the estimated standard deviation not the
estimated variance.

>
> Regards,
>
> Christoph Buser
>
> --------------------------------------------------------------
> Christoph Buser <[hidden email]>
> Seminar fuer Statistik, LEO C13
> ETH (Federal Inst. Technology)  8092 Zurich      SWITZERLAND
> phone: x-41-44-632-4673         fax: 632-1228
> http://stat.ethz.ch/~buser/
> --------------------------------------------------------------
>
>
> Rick DeShon writes:
>  > Hi All.
>  >
>  > I need a bit of help extracting the residual error variance from the VarCorr
>  > structure from lmer.
>  >
>  > #Here's a 2-way random effects model
>  > lmer.1    <- lmer(rating ~ (1|person)+(1|rater), data = dat)
>  >
>  > #Get the structure
>  > vc.fit <- VarCorr(lmer.1)
>  >
>  > #results in.....
>  > $person
>  > 1 x 1 Matrix of class "dpoMatrix"
>  >             (Intercept)
>  > (Intercept)   0.7755392
>  >
>  > $rater
>  > 1 x 1 Matrix of class "dpoMatrix"
>  >             (Intercept)
>  > (Intercept)   0.2054469
>  >
>  > attr(,"sc")
>  > [1] 0.5051518
>  >
>  > #I can pull out the person and rater variance components easy enough. For
>  > example...
>  > vc.person <- vc.fit$person@x
>  >
>  > I'm sure it's simple but I have not been able to grab the residual variance
>  > in the last matrix.  I simply wish to asign the residual to a scalar
>  > variable.  Any suggestions would be appreciated!
>  >
>  > Thanks!
>  >
>  > Rick DeShon
>  >
>  >
>  > --
>  > Rick DeShon
>  > 306 Psychology Building
>  > Department of Psychology
>  > Michigan State University
>  > East Lansing, MI 48824-1116
>  >
>  >      [[alternative HTML version deleted]]
>  >
>  > ______________________________________________
>  > [hidden email] mailing list
>  > https://stat.ethz.ch/mailman/listinfo/r-help
>  > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html