Re: [R] nested hierarchical design

From: <>
Date: Wed 17 Jan 2007 - 09:41:20 GMT

> 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	       = {},


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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Jan 17 20:46:37 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 17 Jan 2007 - 10:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.