[R-sig-ME] how to extract all information from fitted object in a lme model

Arild Husby arild.husby at ed.ac.uk
Wed Jun 3 16:48:56 CEST 2009


Dear list,

I would like your help on how to extract the fitted values from a lme 
object.

For example, the following code will return the fitted values from a lme 
object in the Orthodont dataset (n=108, one for each age/subject 
combination):

library(nlme)
fm1 <- lme(distance ~ age, data = Orthodont)
fitted(fm1)

However, I do not manage to extract each observations fitted value 
together with its subject id (I can easily extract the values 
themselves, using fittted(fm1)[[1]], but not the subject level 
associated with the values!). Is there some way to get these into, say, 
a dataframe with dimensions 108,2 looking like below:

Subject   fitted_values
M01         24.81...
M01         26.57..
.
.
M02        
etc.

I would like to extract these values and then match them to the subject 
in the dataset using something like:

Orthodont$fitvalues <- match(Orthodont$Subject,matrix$fitted_values)

Probably need to match on both age and Subject code somehow, but age is 
not in the fitted output, but presumably in the right order as in 
dataset so might be possible to do this??

If this is a trivial question, or I have misunderstood some concepts, 
please feel free to point me to relevant literature.

Many thanks for your help,
Arild

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




More information about the R-sig-mixed-models mailing list