如何为R中的重复测量方差分析建模

时间:2019-10-11 05:46:22

标签: r lme4 anova

我正在测量2种物种之间随时间变化的特定样品的光合能力(产量)。在每个物种中,样品被分类为“漂白的”或“未漂白的”。我想对方差进行重复测量分析,以确定产量是否因物种,漂白状态和时间点的相互作用而有所不同。我认为使用lme4的线性混合模型是可行的方法,但是我在这方面还相对较新。以下是我运行的3种不同模型,但结果不一致。

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)

1 个答案:

答案 0 :(得分:0)

在RM2中,只有交互。

在RM3中,您没有指定重复测量。

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)