Given a set of data:> names(data)[1] "city" "house" "visit" "value" I am looking for a way to compute the variance components of the nested model (ie, visit 1 at house 2 at city 3 isn't related to visit 1 and house 2 at city 4), but different houses in the same city may be related, and different visits to the same house are probably related. I want to be able to compute how much of the total variance of "value" is explained by each of these. How can I do that in R? Thanks! -- Russell Senior ``shtal latta wos ba padre u prett tu nashtonfi seniorr at aracnet.com mrlosh'' -- Bashgali Kafir for ``If you have had diarrhoea many days you will surely die.''
On 26 Oct 2003, Russell Senior wrote:> > Given a set of data: > > > names(data) > [1] "city" "house" "visit" "value" > > I am looking for a way to compute the variance components of the > nested model (ie, visit 1 at house 2 at city 3 isn't related to visit > 1 and house 2 at city 4), but different houses in the same city may be > related, and different visits to the same house are probably related. > I want to be able to compute how much of the total variance of "value" > is explained by each of these. How can I do that in R?With lme or (if balanced) aov with an Error term. There are lots of examples about, e.g. in the MASS and nlme scripts from the associated books. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
lme should do the job (r1,r2,r3 are your random factors): library(nlme) y.lme <- lme(y ~ 1,random = ~ 1 | r1/r2/r3) summary(y.lme) This is equivalent to a call to varcomp in S-Plus Pascal -- Dr. Pascal A. Niklaus Institute of Botany University of Basel Sch?nbeinstrasse 6 CH-4056 Basel / Switzerland Russell Senior wrote:>Given a set of data: > > > >>names(data) >> >> >[1] "city" "house" "visit" "value" > >I am looking for a way to compute the variance components of the >nested model (ie, visit 1 at house 2 at city 3 isn't related to visit >1 and house 2 at city 4), but different houses in the same city may be >related, and different visits to the same house are probably related. >I want to be able to compute how much of the total variance of "value" >is explained by each of these. How can I do that in R? > >Thanks! > > > >