(所以该method
项目是在别处定义的,并不像我假设的那样是参数的名称。)在 uwlax.edu 网站上链接的代码中有三个多重比较示例。第二个给出了你想要的,即一组全对比较。它不是“Dunnett's C”,但我的经验是,R 的作者通常会提供最强大的测试,并且使用过时的测试不太方便。Dunnett 的 C 代码在 SPSS 网站上的引用已有 40 年历史。和 TukeyHSD 函数的引用要ghlt
更新得多,并且作者受到高度尊重。我认为没有令人信服的理由使用 Dunnett 的 C,而是使用实现目标的 TukeyHSD 选项:
method1=c(96,79,91,85,83,91,82,87)
method2=c(77,76,74,73,78,71,80)
method3=c(66,73,69,66,77,73,71,70,74)
score=c(method1,method2,method3)
method=c(rep(1,length(method1)),
rep(2,length(method2)),
rep(3,length(method3)))
method=factor(method)
anova_results=aov(score~method)
anova_results
#------------
Call:
aov(formula = score ~ method)
Terms:
method Residuals
Sum of Squares 1090.6190 387.2143
Deg. of Freedom 2 21
Residual standard error: 4.29404
Estimated effects may be unbalanced
#----------
summary(anova_results)
#------------------
Df Sum Sq Mean Sq F value Pr(>F)
method 2 1090.6 545.3 29.57 7.81e-07 ***
Residuals 21 387.2 18.4
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
TukeyHSD(anova_results)
#--------------
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = score ~ method)
$method
diff lwr upr p adj
2-1 -11.178571 -16.78023 -5.5769151 0.0001590
3-1 -15.750000 -21.00924 -10.4907592 0.0000006
3-2 -4.571429 -10.02592 0.8830666 0.1113951
TukeyHSD(anova_results, ordered=T)
#---------------
Tukey multiple comparisons of means
95% family-wise confidence level
factor levels have been ordered
Fit: aov(formula = score ~ method)
$method
diff lwr upr p adj
2-3 4.571429 -0.8830666 10.02592 0.1113951
1-3 15.750000 10.4907592 21.00924 0.0000006
1-2 11.178571 5.5769151 16.78023 0.0001590