hello R help I am trying to analyze a data set that has been collected from a hierarchical sampling design. The model should be a mixed model nested ANOVA. The purpose of my study is to analyze the variability at each spatial scale in my design (random factors, variance components), and say something about the variability between regions (fixed factor, contrast of means). The data is as follows; region (fixed) Location (random) Site(random) site nested in location nested in region. I would like to run this as an ANOVA and then compute variance components. My question is when i use the aov command; mod1 <- aov(density ~ region/location/site) is there any way to tell R which factor is random and fixed. I know i can specify fixed and random factors using lme or lmer but these methods do not allow me to extract an anova table (or do they?) I know that the data can be analyzed using a nested ANOVA because i have based my design on several papers in the marine biological literature (MEPS). Thank-you for any advice in advance. Stephen Cole [[alternative HTML version deleted]]
Hi Stephen, Hopefully you will get an answer from one of the experts on mixed models who subscribe to this list. However, you should know that both lme() and lmer() currently have anova() methods. The first will give you p-values (but no SS), and the second will give you SS (but no p-values). You can, however, get the latter using functions in the languageR package. This also has an aovlmer.fnc() that uses MCMC to get p-values.>From what you have said about your data, and about what you want from them,you clearly should be using either lme() or lmer(). Further, objects from both functions work with glht() from the multcomp package, so you also have access to a full range of post-hoc tests. HTH, Mark. Stephen Cole-2 wrote:> > hello R help > > I am trying to analyze a data set that has been collected from a > hierarchical sampling design. The model should be a mixed model nested > ANOVA. The purpose of my study is to analyze the variability at each > spatial scale in my design (random factors, variance components), and say > something about the variability between regions (fixed factor, contrast of > means). The data is as follows; > > region (fixed) > Location (random) > Site(random) > > site nested in location nested in region. > > I would like to run this as an ANOVA and then compute variance components. > > My question is when i use the aov command; mod1 <- aov(density ~ > region/location/site) > is there any way to tell R which factor is random and fixed. > > I know i can specify fixed and random factors using lme or lmer but these > methods do not allow me to extract an anova table (or do they?) > I know that the data can be analyzed using a nested ANOVA because i have > based my design on several papers in the marine biological literature > (MEPS). Thank-you for any advice in advance. > > Stephen Cole > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- View this message in context: http://www.nabble.com/Mixed-model-Nested-ANOVA-tp15639930p15641867.html Sent from the R help mailing list archive at Nabble.com.
So, Site is nested in location. Location is nested in Region. And you are looking at how density varies. Let's think about this from the point of view of a model with varying intercepts. You have some mean density in your study. That mean will deviate by site, location, and region. Each of which is nested in the other. So. density ~ N(site mean, within site sd) site mean ~ N(location mean, between site SD) location mean ~ N(region mean, between location SD) region mean ~ N(0, between region SD) This last one may seem odd, but you can see it if you think about, say, location mean = region mean + N(0, between location SD), or, similarly, density = site mean + N(0, within site sd) This can be fit in lmer with the following (I believe) mod1<-lmer(density ~ 1 + (1|site) + (1|location) + (1|region)) You can then use other methods described previously in the thread for post-hoc analysis. You can also use the arm library and look at ranef(mod1) and se.ranef(mod1) to look at the coefficient estimates and error for each level. I often find it helpful to look at an estimate +/- 2SE. The nesting of location within region, site within location, etc, should take care of itself. See R news 2005 issue 1 page 29 http://www.r-project.org/doc/Rnews/Rnews_2005-1.pdf -Jarrett Stephen Cole-2 wrote:> > hello R help > > I am trying to analyze a data set that has been collected from a > hierarchical sampling design. The model should be a mixed model nested > ANOVA. The purpose of my study is to analyze the variability at each > spatial scale in my design (random factors, variance components), and say > something about the variability between regions (fixed factor, contrast of > means). The data is as follows; > > region (fixed) > Location (random) > Site(random) > > site nested in location nested in region. > > I would like to run this as an ANOVA and then compute variance components. > > My question is when i use the aov command; mod1 <- aov(density ~ > region/location/site) > is there any way to tell R which factor is random and fixed. > > I know i can specify fixed and random factors using lme or lmer but these > methods do not allow me to extract an anova table (or do they?) > I know that the data can be analyzed using a nested ANOVA because i have > based my design on several papers in the marine biological literature > (MEPS). Thank-you for any advice in advance. > > Stephen Cole > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- View this message in context: http://www.nabble.com/Mixed-model-Nested-ANOVA-tp15639930p15642007.html Sent from the R help mailing list archive at Nabble.com.
Hi Stephen On 22/02/2008, Stephen Cole <swbcole at gmail.com> wrote:> hello R help > > I am trying to analyze a data set that has been collected from a > hierarchical sampling design. The model should be a mixed model nested > ANOVA. The purpose of my study is to analyze the variability at each > spatial scale in my design (random factors, variance components), and say > something about the variability between regions (fixed factor, contrast of > means). The data is as follows; > > region (fixed) > Location (random) > Site(random) > > site nested in location nested in region. > > I would like to run this as an ANOVA and then compute variance components. > > My question is when i use the aov command; mod1 <- aov(density ~ > region/location/site) > is there any way to tell R which factor is random and fixed.This depends on whether your design is balanced or not. If, your data are balanced, you may use Error() in aov() to specify error-strata, but then you may as well work out the variance parameters from the sums of squares manually. A more general procedure would be to use either lme or lmer, from which you can get anova tables of fixed effects with anova().> > I know i can specify fixed and random factors using lme or lmer but these > methods do not allow me to extract an anova table (or do they?) > I know that the data can be analyzed using a nested ANOVA because i have > based my design on several papers in the marine biological literature > (MEPS). Thank-you for any advice in advance.If you data are nested lme usually works rather smooth. Here you might want use something like anova(mymodel) to get anova for the fixed effects. The variance components are provided with summary(mymodel) Best Rune> > Stephen Cole > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Reasonably Related Threads
- mixed model nested ANOVA (part two)
- nested anova and multiple comparisons
- Help please! How to code a mixed-model with 2 within-subject factors using lme or lmer?
- Some questions on repeated measures (M)ANOVA & mixed models with lme4
- moving from aov() to lmer()