[R] nested hierarchical design

lorenz.gygax at art.admin.ch lorenz.gygax at art.admin.ch
Wed Jan 17 10:41:20 CET 2007

> 1. The first I used to do in SPSS and I would like to be able 
> to do it in R as well.
> This is the hierarchical model I would like to use: a continuous 
> variable explained by factor A(fixed) + factor B(random) 
> nested in A + factor C (random) nested in factor B (which is nested
> in A).

You would need the following, I guess:

lme (var ~ A, data= NameOfDataFrame, random= ~ 1 | B/C)

This means that C is nested in B. If all C within B have the same levels of A, the model automatically treats B as nested in A(but you can check that based on the degrees of freedom in the output).

> 2. the same model but than for count data (like 15 out of 30, 
> 23 out of 60) instead of the continous variable(I know the basics
> of glm in R)

I guess, this can be viewed as a data set with binary outcomes and thus modeled by a generalised mixed-effects model with a binomial distribution using glmmPQL (in library MASS) or lmer (in library lme4). Please refer to:

  author = {Pinheiro, Jose C and Bates, Douglas M},
  title = {Mixed-Effects Models in {S} and {S}-{P}{L}{U}{S}},
  publisher = {Springer},
  year = {2000},
  address = {New York}

@BOOK {Ven:02,
  AUTHOR = {Venables, W N and Ripley, B D},
  TITLE = {Modern Applied Statistics with {S}},
  PUBLISHER = {Springer},
  YEAR = {2002},
  ADDRESS = {New York},
  EDITION = {fourth}

  author       = {Douglas Bates},
  title	       = {Fitting Linear Mixed Models in {R}},
  journal      = {R News},
  year	       = 2005,
  volume       = 5,
  number       = 1,
  pages	       = {27--30},
  month	       = {May},
  url	       = {http://CRAN.R-project.org/doc/Rnews/},

and: http://wiki.r-project.org/rwiki/doku.php?id=guides:lmer-tests

Do not be surprised if the results are not identical to those in SPSS ...

Regards, Lorenz Gygax
Swiss Federal Veterinary Office
Centre for proper housing of ruminants and pigs
Agroscope Reckenholz-Tänikon Research Station ART

More information about the R-help mailing list