简体   繁体   中英

How to model repeated measures anova in R

I am measuring the photosynthetic capacity (yield) of specific samples over time between 2 species. Within each species the samples are categorized as "bleached" or "non-bleached". I want to run a repeated measures analysis of variance to determine if yield differs based on the interactive effect of species, bleaching status and timepoint. I think a linear mixed model using lme4 is the way to go but I'm still relatively new at this. Below are 3 different models I've run but the results are not consistent.

Master <- structure(list(ColonyID = c("221", "222", "217", "218", "219", 
"220", "211", "212", "11", "12", "209", "210", "203", "204", 
"201", "202", "19", "20", "3", "4", "43", "44", "45", "46", "243", 
"244", "247", "248", "239", "240", "26", "27", "41", "42", "237", 
"238", "229", "230", "35", "36", "221", "222", "217", "218", 
"219", "220", "211", "212", "11", "12", "209", "210", "203", 
"204", "201", "202", "19", "20", "3", "4", "43", "44", "45", 
"46", "243", "244", "247", "248", "239", "240", "26", "27", "41", 
"42", "237", "238", "229", "230", "35", "36"), Species = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Montipora capitata", 
"Porites compressa"), class = "factor"), Bleach = structure(c(1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Bleach", 
"Non-bleach"), class = "factor"), Yield = c(0.653, 0.654, 0.652, 
0.659, 0.586, 0.653, 0.524, 0.649, 0.556, 0.634, 0.579, 0.675, 
0.607, 0.63, 0.616, 0.622, 0.625, 0.582, 0.674, 0.62, 0.575, 
0.502, 0.57, 0.545, 0.552, 0.547, 0.544, 0.609, 0.518, 0.597, 
0.557, 0.488, 0.589, 0.525, 0.55, 0.608, 0.563, 0.484, 0.583, 
0.538, 0.563, 0.54, 0.584, 0.576, 0.557, 0.59, 0.506, 0.53, 0.663, 
0.645, 0.55, 0.634, 0.483, 0.585, 0.522, 0.584, 0.573, 0.504, 
0.515, 0.632, 0.532, 0.497, 0.534, 0.46, 0.482, 0.493, 0.501, 
0.494, 0.583, 0.401, 0.457, 0.441, 0.4, 0.419, 0.475, 0.49, 0.597, 
0.337, 0.468, 0.449), Timepoint = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)), class = "data.frame", row.names = c(NA, 
-80L))

RM1 <- lmer(Yield ~ Bleach * Species * Timepoint + (1|ColonyID), data = Master)
anova(RM1)

RM2 <- aov(Yield ~ Bleach * Species * Timepoint + Error(ColonyID/(Bleach * Species)), data = Master)
summary(RM2)

RM3 <- aov(Yield ~ Bleach * Species * Timepoint, data = Master)
summary(RM3)

In RM2, you have only the interactions.

In RM3, you don't specify that the measures are repeated.

library(nlme)
library(lme4)

str(Master)
RM1a <- lmer(Yield ~ Bleach * Species * Timepoint + (1|ColonyID), data = Master)
summary((RM1a))


RM1 = lme(Yield ~ Bleach * Species * Timepoint,
              random = ~1|ColonyID,
              data=Master)

summary(RM1)


RM2 <- aov(Yield ~ Bleach * Species * Timepoint + Error(ColonyID/(Bleach * Species)), data = Master)
summary(RM2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM