[R] Multilevel analysis with package lme

Douglas Bates bates at stat.wisc.edu
Sun Mar 21 17:14:53 CET 2004


Atropin75 at t-online.de (Felix Eschenburg) writes:

> Dear list,
> i am a student of psychology and have to do a multilevelanalysis on some data. 
> 
> About that i have one general and one specific question.
> 
> This is what i have copied from the help-file on lme:
>   data(bdf)
>      fm <- lme(langPOST ~ IQ.ver.cen + avg.IQ.ver.cen, data = bdf,
>                random = ~ IQ.ver.cen | schoolNR)
>      summary(fm)
> 
> after summary(fm) i get the following error:
> Error in verbose || attr(x, "verbose") : invalid `y' type in `x || y'

Using
Package: nlme
Version: 3.1-48
Date: 2004/01/14
Priority: recommended
Title: Linear and nonlinear mixed effects models
Author: Jose Pinheiro <Jose.Pinheiro at pharma.novartis.com>, Douglas
        Bates <bates at stat.wisc.edu>, Saikat DebRoy
        <saikat at stat.wisc.edu>, and Deepayan Sarkar
        <deepayan at stat.wisc.edu>
Maintainer: Douglas Bates <bates at stat.wisc.edu>

I get

> library(nlme)
> data(bdf)
>   fm <- lme(langPOST ~ IQ.ver.cen + avg.IQ.ver.cen, data = bdf,
               random = ~ IQ.ver.cen | schoolNR)
> summary(fm)
Linear mixed-effects model fit by REML
 Data: bdf 
       AIC      BIC    logLik
  15231.88 15272.01 -7608.938

Random effects:
 Formula: ~IQ.ver.cen | schoolNR
 Structure: General positive-definite, Log-Cholesky parametrization
            StdDev    Corr  
(Intercept) 2.8400175 (Intr)
IQ.ver.cen  0.4604824 -0.635
Residual    6.4295396       

Fixed effects: langPOST ~ IQ.ver.cen + avg.IQ.ver.cen 
                  Value Std.Error   DF   t-value p-value
(Intercept)    40.75032 0.2879720 2155 141.50793       0
IQ.ver.cen      2.46037 0.0838685 2155  29.33607       0
avg.IQ.ver.cen  1.41174 0.3238119  129   4.35976       0
 Correlation: 
               (Intr) IQ.vr.
IQ.ver.cen     -0.273       
avg.IQ.ver.cen  0.029 -0.212

Standardized Within-Group Residuals:
        Min          Q1         Med          Q3         Max 
-4.17445076 -0.63852405  0.06580449  0.70386427  2.71187810 

Number of Observations: 2287
Number of Groups: 131 

> I assume that i have not installed the package nlme correcty, but
> reinstalling did not fix that error. So, what can i do about that ?

The nlme package is a required package and should be installed with
any binary version of R.  You should not need to install that package
separately.

> Then i have another question about my data.
> I have one response variable and about 20 explanatory variables. These 
> variables are nested in a grouping variable of about 100 groups, which is 
> nested in another grouping variable of 2 groups .
> I have tried this 
> lme.model <- lme(respVar~expVar1, data=myData, random = respVar1+...
> +respVar20| groupingVariable_level2,na.action=na.omit)

I don't think you could have used that syntax.  You would have needed
something like

 random = ~ respVar1+...+respVar20| groupingVariable_level2

and that is almost certainly not what you want to try to fit.  (BTW, I
think you have written respVar where you meant expVar.)  That model
has at least 20*(20+1)/2 = 210 variances and covariances to estimate.
It is unlikely that you could do that or that you would want that.

> As i understood Snijders and Bosker, with that i have a fixed effect of 
> expVar1 on respVar and a random effect of all the others explanatory 
> variables. They are also nested in grouping Variable level 2.
> Now my question is, if this is the correct term and how do i include the 
> groupingVariable 3 into my model ?

I would start with simpler models and take a lot at a lot of
diagnostic plots along the way.

> As you can see, i just begun to learn about multilevelanalysis, so
> if you have a link, where it is explained, how to do that with R, I
> would be very thankful.

Well there is a book by Pinheiro and Bates (Springer, 2000) called
"Mixed-effects models in S and S-PLUS" that you may want to look at.




More information about the R-help mailing list