ANOVA error: why is each row of output *not* identified by a unique combination of keys?

ANOVA error: why is each row of output *not* identified by a unique combination of keys?

我有一个双向方差分析测试(w/repeated 测量),我正在使用四个几乎相同的数据集:

> res.aov <- anova_test(
+   data = LST_Weather_dataset_N, dv = LST, wid = Month,
+   within = c(Buffer, TimePeriod),
+   effect.size = "ges",
+   detailed = TRUE,
+ )

其中:

对于一个数据集,我得到错误:

Error: Each row of output must be identified by a unique combination of keys.
Keys are shared for 38 rows:
* 10, 11
* 217, 218
* 240, 241
* 263, 264
* 286, 287
* 309, 310
* 332, 333
...

据我所知,我有独特的组合。

dplyr::count(LST_Weather_dataset_N, LST, Month, Buffer, TimePeriod, sort = TRUE) 

returns

             LST Month Buffer TimePeriod n
1   -6.309045316    12    100          2 1
2   -5.655279925     9   1000          2 1
3   -5.224196295    12    200          2 1
4   -5.194473224     9   1100          2 1
5   -5.025429891    12    400          2 1
6   -4.987575966     9    700          2 1
7   -4.979453868    12    600          2 1
8   -4.825298768    12    300          2 1
9   -4.668994574    12    500          2 1
10  -4.652282192    12    700          2 1
...

'n' 始终为 1。

我不明白为什么会这样。

以下数据框的摘录:

> dput(LST_Weather_dataset_N[sample(1:nrow(LST_Weather_dataset_N), 50),])
structure(list(Buffer = c(1400L, 700L, 300L, 1400L, 100L, 200L, 
1700L, 100L, 800L, 1900L, 1100L, 100L, 700L, 800L, 1400L, 400L, 
1300L, 200L, 1200L, 500L, 1200L, 1300L, 400L, 1000L, 1300L, 1100L, 
100L, 300L, 300L, 600L, 1100L, 1400L, 1500L, 1600L, 1700L, 1800L, 
1700L, 1300L, 1200L, 300L, 1100L, 1900L, 1700L, 700L, 1400L, 
1200L, 1600L, 1700L, 1900L, 1300L), Date = c("02/05/2014", "18/01/2017", 
"19/06/2014", "25/12/2013", "15/09/2017", "08/04/2017", "22/08/2014", 
"21/07/2014", "13/07/2017", "25/12/2013", "22/10/2013", "02/05/2014", 
"07/03/2017", "15/03/2014", "13/07/2017", "19/06/2014", "25/12/2013", 
"17/10/2017", "16/04/2014", "06/10/2013", "15/09/2017", "18/01/2017", 
"10/01/2014", "17/12/2016", "13/07/2017", "19/06/2014", "07/03/2017", 
"15/03/2014", "11/02/2014", "22/10/2013", "06/10/2013", "15/09/2017", 
"16/04/2014", "18/01/2017", "15/03/2014", "21/07/2014", "17/10/2017", 
"15/09/2017", "10/01/2014", "23/09/2014", "16/04/2014", "22/10/2013", 
"11/06/2017", "26/05/2017", "19/06/2014", "14/08/2017", "11/02/2014", 
"26/02/2017", "26/02/2017", "11/02/2014"), LST = c(1.255502397, 
4.33385966, 3.327025603, -0.388631166, -0.865430798, 4.386292648, 
-0.243018665, 3.276865987, 0.957036835, -0.065821795, 0.69731779, 
4.846851651, -1.437700684, 1.003808572, 0.572460421, 2.995902374, 
-0.334633662, -1.231447567, 0.644520741, 0.808262029, -3.392959991, 
2.324569449, 2.346707612, -3.124354627, 0.58719862, 1.904859254, 
1.701580958, 2.792443253, 1.638270039, 1.460743317, 0.699767335, 
-3.015643366, 0.930527864, 1.309519336, 0.477789664, 0.147584938, 
-0.498188865, -3.506795723, -1.007487965, 1.149604087, 1.192366386, 
0.197471474, 0.999391224, -0.190613618, 1.27324015, 2.686622796, 
0.573109026, 0.97847983, 0.395005095, -0.40855426), Month = c(5L, 
1L, 6L, 12L, 9L, 4L, 8L, 7L, 7L, 12L, 10L, 5L, 3L, 3L, 7L, 6L, 
12L, 10L, 4L, 10L, 9L, 1L, 1L, 12L, 7L, 6L, 3L, 3L, 2L, 10L, 
10L, 9L, 4L, 1L, 3L, 7L, 10L, 9L, 1L, 9L, 4L, 10L, 6L, 5L, 6L, 
8L, 2L, 2L, 2L, 2L), Year = c(2014L, 2017L, 2014L, 2013L, 2017L, 
2017L, 2014L, 2014L, 2017L, 2013L, 2013L, 2014L, 2017L, 2014L, 
2017L, 2014L, 2013L, 2017L, 2014L, 2013L, 2017L, 2017L, 2014L, 
2016L, 2017L, 2014L, 2017L, 2014L, 2014L, 2013L, 2013L, 2017L, 
2014L, 2017L, 2014L, 2014L, 2017L, 2017L, 2014L, 2014L, 2014L, 
2013L, 2017L, 2017L, 2014L, 2017L, 2014L, 2017L, 2017L, 2014L
), JulianDay = c(122L, 18L, 170L, 359L, 258L, 98L, 234L, 202L, 
194L, 359L, 295L, 122L, 66L, 74L, 194L, 170L, 359L, 290L, 106L, 
279L, 258L, 18L, 10L, 352L, 194L, 170L, 66L, 74L, 42L, 295L, 
279L, 258L, 106L, 18L, 74L, 202L, 290L, 258L, 10L, 266L, 106L, 
295L, 162L, 146L, 170L, 226L, 42L, 57L, 57L, 42L), TimePeriod = c(1L, 
2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 
2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 
2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 
1L), Temperature = c(28L, 9L, 31L, 12L, 27L, 21L, 29L, 36L, 38L, 
12L, 23L, 28L, 12L, 21L, 38L, 31L, 12L, 23L, 25L, 22L, 27L, 9L, 
11L, 7L, 38L, 31L, 12L, 21L, 14L, 23L, 22L, 27L, 25L, 9L, 21L, 
36L, 23L, 27L, 11L, 31L, 25L, 23L, 29L, 27L, 31L, 34L, 14L, 16L, 
16L, 14L), Humidity = c(6L, 34L, 7L, 31L, 29L, 22L, 34L, 15L, 
19L, 31L, 16L, 6L, 14L, 14L, 19L, 7L, 31L, 12L, 9L, 12L, 29L, 
34L, 33L, 18L, 19L, 7L, 14L, 14L, 31L, 16L, 12L, 29L, 9L, 34L, 
14L, 15L, 12L, 29L, 33L, 18L, 9L, 16L, 8L, 13L, 7L, 13L, 31L, 
31L, 31L, 31L), Wind_speed = c(6L, 0L, 6L, 7L, 13L, 33L, 6L, 
20L, 9L, 7L, 0L, 6L, 0L, 6L, 9L, 6L, 7L, 6L, 0L, 7L, 13L, 0L, 
0L, 35L, 9L, 6L, 0L, 6L, 6L, 0L, 7L, 13L, 0L, 0L, 6L, 20L, 6L, 
13L, 0L, 0L, 0L, 0L, 24L, 11L, 6L, 24L, 6L, 26L, 26L, 6L), Wind_gust = c(0L, 
0L, 0L, 0L, 0L, 54L, 0L, 46L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 48L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 46L, 0L, 0L, 0L, 0L, 0L, 0L, 48L, 0L, 0L, 39L, 
0L, 41L, 41L, 0L), Wind_trend = c(1L, 0L, 1L, 1L, 2L, 2L, 0L, 
1L, 2L, 1L, 0L, 1L, 0L, 1L, 2L, 1L, 1L, 0L, 0L, 2L, 2L, 0L, 1L, 
1L, 2L, 1L, 0L, 1L, 1L, 0L, 2L, 2L, 0L, 0L, 1L, 1L, 0L, 2L, 1L, 
1L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Wind_direction = c(0, 
0, 0, 337.5, 360, 22.5, 0, 22.5, 0, 337.5, 0, 0, 0, 0, 0, 0, 
337.5, 180, 0, 247.5, 360, 0, 0, 180, 0, 0, 0, 0, 337.5, 0, 247.5, 
360, 0, 0, 0, 22.5, 180, 360, 0, 0, 0, 0, 360, 22.5, 0, 360, 
337.5, 360, 360, 337.5), Pressure = c(940.2, 943.64, 937.69, 
951.37, 932.69, 933.94, 937.07, 938.01, 937.69, 951.37, 939.72, 
940.2, 948.33, 947.71, 937.69, 937.69, 951.37, 943.32, 932.69, 
944.71, 932.69, 943.64, 942.31, 943.01, 937.69, 937.69, 948.33, 
947.71, 941.94, 939.72, 944.71, 932.69, 932.69, 943.64, 947.71, 
938.01, 943.32, 932.69, 942.31, 938.94, 932.69, 939.72, 928.31, 
931.12, 937.69, 932.37, 941.94, 936.13, 936.13, 941.94), Pressure_trend = c(1L, 
2L, 0L, 2L, 0L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 0L, 2L, 
1L, 2L, 1L, 0L, 2L, 2L, 2L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 2L, 
2L, 1L, 1L, 1L, 0L, 2L, 1L, 2L, 1L, 0L, 0L, 0L, 1L, 1L, 2L, 2L, 
1L)), row.names = c(179L, 14L, 195L, 426L, 306L, 118L, 299L, 
229L, 244L, 436L, 374L, 153L, 90L, 91L, 256L, 197L, 424L, 348L, 
137L, 355L, 328L, 26L, 7L, 419L, 254L, 211L, 78L, 81L, 43L, 359L, 
373L, 332L, 143L, 32L, 109L, 263L, 393L, 330L, 23L, 309L, 135L, 
398L, 224L, 166L, 217L, 290L, 69L, 72L, 76L, 63L), class = "data.frame")

嗯,这有点尴尬。

错误出现是因为实际上没有成对的月份数据。由于确定月份值时出错,一个月有 57 个数据 (19x3),而不是每个月有 38 个数据 (19x2)。更正此问题,并检查每个月是否具有相同数量的方差分析配对数据,使测试 运行 成功。

> res.aov <- anova_test(
+   data = LST_Weather_dataset_N, dv = LST, wid = Month,
+   within = c(Buffer, TimePeriod),
+   effect.size = "ges",
+   detailed = TRUE,
+ )
> get_anova_table(res.aov, correction = "auto")
ANOVA Table (type III tests)

             Effect DFn DFd     SSn     SSd      F        p p<.05   ges
1       (Intercept)   1  11 600.135 974.584  6.774 2.50e-02     * 0.189
2            Buffer  18 198 332.217 331.750 11.015 2.05e-21     * 0.115
3        TimePeriod   1  11  29.561 977.945  0.333 5.76e-01       0.011
4 Buffer:TimePeriod  18 198  13.055 283.797  0.506 9.53e-01       0.005

不过,我仍然不明白错误消息是如何告诉我这一点的。