Jacob Wegelin
2004-Aug-03 23:15 UTC
[R] lme fitted correlation of random effects: where is it?
The print method for lme *prints out* the fitted correlation matrix for the random effects. Is there any way to get these values as an object in R? I have examined the components of the lme object (called "junk" in the example below) and the components of summary(junk) without finding these numbers. (How I did this: I dumped the entire lme object to a text file and then used egrep to search the text file for one of the long strings of digits that are in the printout. The string was not in the file. It appears that the print method computes the fitted correlation matrix on the fly?? Or where does it get it?) Below is the printout of the correlation matrix. One could print it to a file and then use perl to get the numbers back, but that seems a bit circuitous. What am I overlooking? Of course, this correlation matrix is not the sample correlation matrix of the random effects, as is confirmed below. Thanks for any ideas. Jake Wegelin> junkLinear mixed-effects model fit by REML Data: blockmat Log-restricted-likelihood: -426.3231 Fixed: RESP ~ -1 + intS + tS + intC + tC + intA + tA intS tS intC tC intA tA -0.049391372 0.034116310 -0.003453588 0.200868693 0.019390920 -0.233687228 Random effects: Formula: ~(-1 + intS + tS) + (-1 + intC + tC) + (-1 + intA + tA) | ID Structure: General positive-definite, Log-Cholesky parametrization StdDev Corr intS 0.2891005 intS tS intC tC intA tS 0.5652176 0.026 intC 0.3550297 0.661 0.144 tC 0.5335840 -0.078 0.563 -0.008 intA 0.4261338 -0.560 0.109 0.034 0.189 tA 0.6932241 -0.092 0.423 0.058 0.096 -0.141 Residual 0.5847087 Number of Observations: 360 Number of Groups: 40> cor(junk$coefficients$random$ID)intS tS intC tC intA tA intS 1.00000000 0.00969535 0.726342257 -0.113025813 -0.63004526 -0.08474931 tS 0.00969535 1.00000000 0.189830146 0.697937620 0.13437668 0.51908803 intC 0.72634226 0.18983015 1.000000000 0.005010784 -0.01763164 0.07153269 tC -0.11302581 0.69793762 0.005010784 1.000000000 0.25276614 0.14386815 intA -0.63004526 0.13437668 -0.017631636 0.252766142 1.00000000 -0.16658238 tA -0.08474931 0.51908803 0.071532693 0.143868146 -0.16658238 1.00000000> version_ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 9.1 year 2004 month 06 day 21 language R
Thomas Lumley
2004-Aug-04 00:36 UTC
[R] lme fitted correlation of random effects: where is it?
On Tue, 3 Aug 2004, Jacob Wegelin wrote:> > The print method for lme *prints out* the fitted correlation matrix for > the random effects. Is there any way to get these values as an object in > R? I have examined the components of the lme object (called "junk" in the > example below) and the components of summary(junk) without finding these > numbers. > > (How I did this: I dumped the entire lme object to a text file and then > used egrep to search the text file for one of the long strings of digits > that are in the printout. The string was not in the file. It appears that > the print method computes the fitted correlation matrix on the fly?? > Or where does it get it?) >It's remarkably complicated. If you look at getS3method("print","lme") you see that it comes from print(summary(x$modelStruct), sigma=x$sigma) You then look at what the class of x$modelstruct is > class(fm1$modelStruct) [1] "lmeStructInt" "lmeStruct" "modelStruct" and look at getS3method("print","lmeStructInt"), which doesn't exist. You then try lmeStruct, with no luck, and then getS3method("print","modelStruct") After a lot more chasing through methods you find that the correlation matrix is computed by the generic function pdMatrix. You probably want to look at getS3method("pdMatrix","pdSymm") and getS3method("pdMatrix","pdMat") And all this may well change when Doug finishes lme4. -thomas
Doran, Harold
2004-Aug-04 00:55 UTC
[R] lme fitted correlation of random effects: where is it?
I believe getVarCov() will give you what you need. Harold -----Original Message----- From: r-help-bounces@stat.math.ethz.ch on behalf of Thomas Lumley Sent: Tue 8/3/2004 8:36 PM To: Jacob Wegelin Cc: r-help@stat.math.ethz.ch Subject: Re: [R] lme fitted correlation of random effects: where is it? On Tue, 3 Aug 2004, Jacob Wegelin wrote: > > The print method for lme *prints out* the fitted correlation matrix for > the random effects. Is there any way to get these values as an object in > R? I have examined the components of the lme object (called "junk" in the > example below) and the components of summary(junk) without finding these > numbers. > > (How I did this: I dumped the entire lme object to a text file and then > used egrep to search the text file for one of the long strings of digits > that are in the printout. The string was not in the file. It appears that > the print method computes the fitted correlation matrix on the fly?? > Or where does it get it?) > It's remarkably complicated. If you look at getS3method("print","lme") you see that it comes from print(summary(x$modelStruct), sigma=x$sigma) You then look at what the class of x$modelstruct is > class(fm1$modelStruct) [1] "lmeStructInt" "lmeStruct" "modelStruct" and look at getS3method("print","lmeStructInt"), which doesn't exist. You then try lmeStruct, with no luck, and then getS3method("print","modelStruct") After a lot more chasing through methods you find that the correlation matrix is computed by the generic function pdMatrix. You probably want to look at getS3method("pdMatrix","pdSymm") and getS3method("pdMatrix","pdMat") And all this may well change when Doug finishes lme4. -thomas ______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html [[alternative HTML version deleted]]