# Nested/SplitModel - RepeatedMeasures/MixedModel ANOVA: levels of nesting & scripting in R

My data set has the following variables:

• Treatment (4 types- fixed)
• Location (8 locations- fixed)
• Position in Location (3 positions per location- fixed)
• Samples are taken in each position (3 samples per position-random)
• Time (two sampling times - fixed)
• Mineralisation rate (as result of analysis of samples taken)

Two locations are used to test each treatment (ie 4 treatments, 2 locations per treatment, 8 locations total).

I want to do a split-plot (/nested?) repeated measures (/mixed model?) ANOVA in R using the above variables.

Q.1. Does this sound suitable?

My goal is to see if there is an affect of 1) position, 2) treatment, 3) time and 4) interaction of all (ie pos*treat*, pos*time, treat*time, pos*treat*time) on mineralization rates.

Q 2. Is location nested in treatment? Is sample nested in position?

Q 3. What are the between- and within- factors?

Q 4. What is the subject/plot? - Is it the location or position or sample or rate?

Q 5. How can I put time as repeated measures in my R formula?

Q 6. Would you use aov, lme, or ezANOVA?

Q 7. How do I code the seperate independent variables, and their interactions into a proper R formula?

I have literally been trying to figure this out for days and I cannot seem to find an answer that makes sense...

-
You mention two sampling times as repeated measures, but your description of the variables does not seem to include it. – mnel Dec 20 '12 at 1:24
thanks for the comment, I have edited it. hope it is clearer! – Lorain Dec 20 '12 at 13:53

Tricky problem! Is location fixed or random? Is position fixed or random? I assume that sample is random.

• Since treatment is assigned to location, location is the sampling unit. Basically, the comparison between treatments is done at that level. $n=8$.
• The measurement unit is the observation you take on your "samples" at a given time.
• Location is not nested in treatment. The treatment is applied to the location.
• Position is nested inside location.
• Sample is nested inside position.
• Time is nested inside Sample.
• Time is crossed with treatment.

You have 3 levels of nesting (time within sample, sample within position, position within location).

If location, position and sample are random, I think the R formula will look like this:

Y ~ Treatment * Time +(1|location|position|sample)

You have 1 row in your data frame for each sample observation at each time - with appropriate codings for all of your design characteristics.

Would it work to combine the repeated measures into a score such as their average or their difference? That could make the model easier to interpret.

-
+1, this is a really nice answer! One thing I wonder about: you state that there are "3 levels of nesting (location, position, sample)" & also that "Time is nested inside Sample". There is a little tension b/t these statements. Is there a way to make this clearer for me? – gung Dec 20 '12 at 4:06
Thanks for the commendation. Time is the last level of the model, so you have time < sample < position < location. But I have noticed that the "end of the line" in a random effects model is not usually referred to as a "level". In a simple means model $X=\mu + \epsilon$, the error term is a random effect, but we don't speak of such a model as having one level of nesting. It's just semantics at this point. I have changed the wording to make it more clear. – Placidia Dec 20 '12 at 4:12
Thanks, that is clearer. – gung Dec 20 '12 at 4:20
With R, I would use lmer from the lme4 package. lme (from nlme) is an earlier version of that package. Formulae are defined in slightly different ways. treatment*time includes the fixed effects for treatment and time along with their interaction. – Placidia Dec 20 '12 at 20:37
If location and position are random, you can still test for their effect with lmer and the formula I gave. In that case, you are testing whether the variance of those components is > 0. If location and position are fixed, a different formula is needed. You might want to read an introduction to mixed models before going any further, since they can be tricky. – Placidia Dec 20 '12 at 20:43