简体   繁体   English

如何在 R 中重复测量方差分析 model

[英]How to model repeated measures anova in R

I am measuring the photosynthetic capacity (yield) of specific samples over time between 2 species.我正在测量 2 个物种之间特定样品的光合能力(产量)。 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.我认为使用 lme4 的线性混合 model 是通往 go 的方法,但我在这方面还是比较新的。 Below are 3 different models I've run but the results are not consistent.以下是我运行的 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)

In RM2, you have only the interactions.在 RM2 中,您只有交互。

In RM3, you don't specify that the measures are repeated.在 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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