0

I fitted a linear mixed model using lme function of nlme package. 'Summary' command shows the coefficients, their standard errors and correlation matrix of the coefficients. How can I get this correlation matrix (covariance matrix is also fine) in a R data set form?

lm command (for linear model) do provide a covariance matrix in the object 'summary(lm5)$cov.unscaled'. I want to find a counterpart of this in lme function.

user67275
  • 1
  • 9
  • 38
  • 64
  • Read the package documentation. There are are full set of extractor functions. – IRTFM Jun 29 '14 at 16:31
  • Specifically you can use `help(package="nlme")` to see all the functions in a package. Or you can use `methods(class="lme")` to see all the functions that have a method for the "lme" class. – MrFlick Jun 29 '14 at 16:39

1 Answers1

4

If you want the variance-covariance matrix of the fixed effects, use

vcov(fitted.model)

If you want the correlation matrix, use

cov2cor(vcov(fitted.model))

You can also use

summary(fitted.model)$corFixed

(use str(summary(fitted.model)) to find the bits you need), but the accessors above are better because they don't make use of the (not necessarily stable) internal structure of the results.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453