我的数据是在时间上重复测量得到的数据,用aov()函数做完重复测量方差分析之后发现不能进行多重比较。
下面的代码给出了一个简单的数据和单因素方差分析/重复测量方差分析的结果。直接做的方差分析是可以进行多重比较的,而重复测量方差分析的结果不论是直接用或是$within都不能进行多重比较。
请问是否有直接用aov()函数的重复测量方差分析的结果做多重比较的方法?或者用其他函数实现重复测量方差分析和多重比较?
df <- data.frame(treat=c('CK','1','2','CK','1','2','CK','1','2','CK','1','2'),
time=c(1,1,1,2,2,2,3,3,3,4,4,4),
y=c(3,2.5,2,2.5,2,1.5,2,1.5,1,2.5,2,1.5))
fit1 <- aov(y~treat, df)
summary(fit1)
#> Df Sum Sq Mean Sq F value Pr(>F)
#> treat 2 2.0 1.0000 6 0.0221 *
#> Residuals 9 1.5 0.1667
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
fit2 <- aov(y~treat+Error(time), df)
summary(fit2)
#>
#> Error: time
#> Df Sum Sq Mean Sq F value Pr(>F)
#> Residuals 1 0.6 0.6
#>
#> Error: Within
#> Df Sum Sq Mean Sq F value Pr(>F)
#> treat 2 2.0 1.0000 8.889 0.00928 **
#> Residuals 8 0.9 0.1125
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit2$Within)
#> Df Sum Sq Mean Sq F value Pr(>F)
#> treat 2 2.0 1.0000 8.889 0.00928 **
#> Residuals 8 0.9 0.1125
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
library(agricolae)
duncan.test(fit1, 'treat')$group
#> y groups
#> CK 2.5 a
#> 1 2.0 ab
#> 2 1.5 b
duncan.test(fit2, 'treat')$group
#> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors): cannot coerce class 'c("aovlist", "listof")' to a data.frame
duncan.test(fit2$Within, 'treat')$group
#> NULL
sessionInfo()
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
#> [2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
#> [3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] agricolae_1.2-8
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_0.12.19 spdep_0.7-9 compiler_3.5.1
#> [4] later_0.7.5 questionr_0.6.3 highr_0.7
#> [7] LearnBayes_2.15.1 tools_3.5.1 boot_1.3-20
#> [10] digest_0.6.18 evaluate_0.12 nlme_3.1-137
#> [13] lattice_0.20-35 Matrix_1.2-14 shiny_1.1.0
#> [16] rstudioapi_0.8 yaml_2.2.0 expm_0.999-3
#> [19] spData_0.2.9.4 coda_0.19-2 stringr_1.3.1
#> [22] knitr_1.20 cluster_2.0.7-1 gtools_3.8.1
#> [25] combinat_0.0-8 rprojroot_1.3-2 grid_3.5.1
#> [28] R6_2.3.0 rmarkdown_1.10 sp_1.3-1
#> [31] gdata_2.18.0 klaR_0.6-14 deldir_0.1-15
#> [34] magrittr_1.5 gmodels_2.18.1 backports_1.1.2
#> [37] promises_1.0.1 htmltools_0.3.6 MASS_7.3-51
#> [40] splines_3.5.1 mime_0.6 xtable_1.8-3
#> [43] httpuv_1.4.5 stringi_1.2.4 miniUI_0.1.1.1
#> [46] AlgDesign_1.1-7.3
<sup>Created on 2019-03-23 by the reprex package (v0.2.1)</sup>