及时重复测量方差分析

时间:2019-03-08 22:26:55

标签: r anova

我有一个简单的数据集,其中包含两次治疗(trt),3次重复以及在不同日期重复进行的测量。响应变量是yield。我们正在寻找治疗上的差异。 我知道我的重复测量嵌套在rep中,像aov(yield〜trt)这样的简单方差分析不合适,因为它将每个重复测量视为独立的rep。 我认为我必须指定一个错误字词,并将日期嵌套在rep中,但是我对语法感到困惑。

这是我的代码

summary(aov(data=yi,yield~trt + Error(rep/date)))  #this means date nested in rep

谢谢您的帮助!

这是我的数据集

structure(list(date = structure(c(17676, 17680, 17683, 17687, 
17690, 17695, 17698, 17702, 17705, 17709, 17712, 17716, 17719, 
17723, 17726, 17730, 17733, 17737, 17740, 17744, 17747, 17751, 
17754, 17759, 17761, 17765, 17768, 17772, 17775, 17779, 17782, 
17676, 17680, 17683, 17687, 17690, 17695, 17698, 17702, 17705, 
17709, 17712, 17716, 17719, 17723, 17726, 17730, 17733, 17737, 
17740, 17744, 17747, 17751, 17754, 17759, 17761, 17765, 17768, 
17772, 17775, 17779, 17782, 17676, 17680, 17683, 17687, 17690, 
17695, 17698, 17702, 17705, 17709, 17712, 17716, 17719, 17723, 
17726, 17730, 17733, 17737, 17740, 17744, 17747, 17751, 17754, 
17759, 17761, 17765, 17768, 17772, 17775, 17779, 17782, 17676, 
17680, 17683, 17687, 17690, 17695, 17698, 17702, 17705, 17709, 
17712, 17716, 17719, 17723, 17726, 17730, 17733, 17737, 17740, 
17744, 17747, 17751, 17754, 17759, 17761, 17765, 17768, 17772, 
17775, 17779, 17782, 17676, 17680, 17683, 17687, 17690, 17695, 
17698, 17702, 17705, 17709, 17712, 17716, 17719, 17723, 17726, 
17730, 17733, 17737, 17740, 17744, 17747, 17751, 17754, 17759, 
17761, 17765, 17768, 17772, 17775, 17779, 17782, 17676, 17680, 
17683, 17687, 17690, 17695, 17698, 17702, 17705, 17709, 17712, 
17716, 17719, 17723, 17726, 17730, 17733, 17737, 17740, 17744, 
17747, 17751, 17754, 17759, 17761, 17765, 17768, 17772, 17775, 
17779, 17782), class = "Date"), yield = c(990, 1560, 1520, 1845, 
1820, 2260, 1175, 1630, 1305, 2065, 1060, 2060, 1565, 1755, 1380, 
1875, 1590, 1640, 1185, 1585, 830, 2055, 1285, 2555, 1230, 2095, 
1565, 1935, 1235, 1510, 1570, 660, 1010, 720, 1370, 1305, 1670, 
1120, 1780, 1210, 1675, 1600, 1490, 1010, 1060, 985, 1075, 915, 
1640, 895, 1535, 1330, 1990, 980, 2270, 1135, 1525, 1180, 1020, 
1010, 1050, 710, 975, 1290, 1115, 785, 1625, 1705, 1235, 1700, 
1430, 1175, 1115, 1275, 1035, 1085, 1185, 1475, 870, 1580, 845, 
1560, 635, 2315, 800, 2365, 945, 1515, 1435, 1855, 1355, 1585, 
1315, 745, 1125, 655, 1085, 1430, 1980, 985, 1675, 1090, 1510, 
1085, 1730, 1065, 1460, 795, 1345, 1165, 1145, 655, 1310, 645, 
1780, 945, 2375, 950, 1805, 1760, 1510, 1590, 1515, 1030, 645, 
1681, 750, 985, 1065, 1350, 875, 1520, 1045, 1800, 1165, 2070, 
1410, 1435, 1490, 1705, 1230, 1865, 1015, 1740, 745, 1275, 1180, 
2030, 755, 1540, 1410, 1340, 1155, 1495, 1160, 1335, 1030, 690, 
1330, 1005, 1240, 1190, 1625, 965, 1565, 1195, 1305, 1180, 1255, 
1090, 1675, 1250, 1615, 595, 1395, 695, 1600, 1165, 2215, 675, 
1300, 1190, 1035, 985, 985, 935), trt = c("117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"117 lb/ac Preplant", "117 lb/ac Preplant", "117 lb/ac Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant", "No Preplant", "No Preplant", "No Preplant", "No Preplant", 
"No Preplant"), rep = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
3, 3, 3, 3, 3)), row.names = c(NA, -186L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,则您对yield ~ trt感兴趣,但是数据不是独立的,因为每个rep都有多个测量值。

据检查数据可知,唯一发生的嵌套是trtrep的嵌套。如果您按照以下方式建模,则会自动考虑:

require(lme4)
LMM <- lmer(yield ~ trt + (1 | rep), data = yi)
summary(LMM)

# or:
LMM <- aov(data = yi, yield ~ trt + Error(rep))
summary(LMM)

如果您担心收益取决于日期,则可以将其建模为固定效应,因为(1 | rep)已经考虑了重复措施。此外,考虑一下date产生随机影响的含义:如果您要重复此实验,是否会随机选择新日期?这些日期是否来自某个较大的日期分布,从而导致收益率呈正态分布偏移? date *似乎有季节性的影响,您可以将其建模为例如像this

*尝试:plot(yield ~ date, yi, pch = paste(rep), col = factor(trt))