[R] dfs in lme

Lorenz.Gygax@fat.admin.ch Lorenz.Gygax at fat.admin.ch
Mon Jun 7 09:36:51 CEST 2004


Dear R-mixed-effects-modelers,

I could not answer this questions with the book by Pinheiro & Bates and did
not find anything appropriate in the archives, either ...

We are preparing a short lecture on degrees of freedom and would like to
show lme's as an example as we often need to work with these. I have a
problem in understanding how many dfs are needed if random terms are used
for explanatory variables in addition to the intercept (if I have understood
correctly that ist the same as saying that interactions between random and
fixed effects are considered). I tried the following code:

library ('nlme')
options (contrasts= c ('contr.treatment', 'contr.poly'))

# create fake data
data.df <- data.frame (gruppe= rep (1:4, rep (20, 4)))

# create response variable
data.df$zv <- rnorm (80, 2)

# create potential explanatory variables
data.df$explan <- rnorm (80, 2)
data.df$treat <-  as.factor (sample (1:3, 80, T))
data.df$treat1 <- as.factor (sample (1:4, 80, T))
data.df$treat2 <- as.factor (sample (1:5, 80, T))
data.df$treat3 <- as.factor (sample (1:6, 80, T))

# with each of the explanatory variables
withoutInt <- lme (zv ~ explan, data= data.df, random= ~1 | gruppe)
withInt <- lme (zv ~ explan, data= data.df, random= ~ explan | gruppe)
anova (withoutInt)
anova (withInt)
anova (withoutInt, withInt)


There are two main things that I wonder about:

(1) the two anova() commands on the single models have the same residual
degrees of freedom even though the model withInt has an additional
explanatory variable. Why are the residual dfs not reduced?

(2) In the model comparison, it becomes visible that the model with 'explan'
in the random effect does indeed use more dfs. But I cannot figure out where
that number of dfs comes from. I thought that basically for each of the
levels in the grouping variable additional parameters are estimated? Thus, I
would expect somethind like df(interaction)= df(explanatory
variable)*df(random effect), but what I find is:

explanatory variable	delta-dfs of the model comparison
                        (= dfs of the interaction of the explanatory
                           variable with the random effect 'gruppe',
                           which has 4 levels, 3 dfs)
continuous (1 df)		 2
3 levels (2 dfs)		 5
4 levels (3 dfs)		 9
5 levels (4 dfs)		14
6 levels (5 dfs)		20

Can anyone point me in the right direction on where and how to answer these
questions?

Many thanks and regards, Lorenz
- 
Lorenz Gygax
Tel: +41 (0)52 368 33 84 / lorenz.gygax at fat.admin.ch      

Center for proper housing of ruminants and pigs
Swiss Veterinary Office
agroscope FAT Tänikon, CH-8356 Ettenhausen / Switzerland
Fax : +41 (0)52 365 11 90 / Tel: +41 (0)52 368 31 31




More information about the R-help mailing list