[R] GLMM and crossed effects

Andrew Beckerman a.beckerman at sheffield.ac.uk
Thu Jan 6 14:41:23 CET 2005


Hi again.  Perhaps a simple question this time....

I am analysing data with a dependent variable of insect counts, a fixed  
effect of site and two random effects, day, which is the same set of 10  
days for each site, and then transect, which is nested within site (5  
each).

I am trying to fit the cross classified model using GLMM in lme4.  I  
have, for potential use, created a second coding of transect with  
levels 1-5 for site 1 and 6-10 for site2.  Likewise, if a groupedData  
object is necessary, there are als ts1 and ts2 dummy variables, as was  
necessary in the old lme.....

 > str(dat3)
`data.frame':	100 obs. of  7 variables:
  $ site  : Factor w/ 2 levels "Here","There": 1 1 1 1 1 1 1 1 1 1 ...
  $ day   : Factor w/ 10 levels "1","2","3","4",..: 1 1 1 1 1 2 2 2 2 2  
...
  $ trans : Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5  
...
  $ count : int  77 109 81 124 115 84 90 85 130 106 ...
  $ trans2: Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5  
...
  $ ts1   : Factor w/ 10 levels "Here 1","Here 2",..: 1 2 3 4 5 1 2 3 4  
5 ...
  $ ts2   : Factor w/ 10 levels "Here 1","Here 2",..: 1 2 3 4 5 1 2 3 4  
5 ...

Might someone explain to me how I might reflect the fact that transects  
are different between sites, while days are not?

#this does not work, though I thought it might be the best way to  
specify the model.....
 >  
GLMM(count~site,data=dat3,random=list(day=~1,trans=~1|site,family=poisso 
n)
Error in GLMM(count ~ site, data = dat3, random = list(day = ~1, trans  
= ~1 |  :
	subscript out of bounds
In addition: Warning message:
"|" not meaningful for factors in: Ops.factor(1, site)

#This does... but also note the differences in the summary and VarCorr  
variance components...
 >summary(GLMM(count~site,data=dat3,random=list(day=~1,trans2=~1),family= 
poisson))
Generalized Linear Mixed Model

Family: poisson family with log link
Fixed: count ~ site
Data: dat3
       AIC      BIC   logLik
  103.1494 116.1753 -46.5747

Random effects:
  Groups Name        Variance Std.Dev.
  trans2 (Intercept) 0.073011 0.27020
  day    (Intercept) 0.034373 0.18540
# of obs: 100, groups: trans2, 10; day, 10

Estimated scale (compare to 1)  0.6232135

Fixed effects:
             Estimate Std. Error z value Pr(>|z|)
(Intercept)  4.66280    0.13502  34.534   <2e-16 ***
siteThere   -0.25572    0.17216  -1.485   0.1375
---
Signif. codes:  0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Correlation of Fixed Effects:
           (Intr)
siteThere -0.636
 >VarCorr(GLMM(count~site,data=dat3,random=list(day=~1,trans2=~1),family= 
poisson))
  Groups   Name        Variance Std.Dev.
  trans2   (Intercept) 0.028936 0.17010
  day      (Intercept) 0.013623 0.11672
  Residual             0.396322 0.62954


Many thanks
andrew




More information about the R-help mailing list