基歪伯克 - Dunnett Test
type: channel
link: https://52.gay/tag/Dunnett-Test/
items: R实现Tukey HSD Test和Dunnett Test

R实现Tukey HSD Test和Dunnett Test
type: item
date: 2021-09-01T04:13:28+00:00
description: Tukey HSD Test和Dunnett是常用的多组数据间的差异显著性检验方法。[scode type="blue"]Tukey's HSD（忠实显著性差异），也称作 Tukey HSD、WSD 或 Tukey(a) 检验，控制假阳性率判断族。这意味着，如果在 0.05 级别上执行检验，那么在执行所有成对比较时，获得一个或多个假阳性的几率是 0.05。It reduces Type I error at the expense of Power. It is appropriate to use this test when one desires all the possible comparisons between a large set of means (6 or more means).Post Hoc tests that assume equal variance.[/scode][scode type="blue"]将一组处理与单个控制平均值进行比较的成对多重比较 T 检验。您可以选择第一个类别或最后一个类别作为默认控制类别。双向检验任何级别（除控制类别之外）的因素平均值是否不等于控制类别的因素平均值。控制检验任何级别的因素平均值是否小于控制类别的因素平均值。控制检验任何级别的因素平均值是否大于控制类别的因素平均值。Post Hoc tests that do not assume equal variances[/scode]0. 做几组数据数据set.seed(1080) data <- data.frame(group = rep(c("P1", "P2", "P3"), each = 40), values = c(rnorm(40, 0, 3),rnorm (40, 0, 6),rnorm (40, 1, 5))) data$group<-as.factor(data$group) head(data) 1. 先做ANOVAmodel <- aov(values~group, data=data) summary(model) 输出： Df Sum Sq Mean Sq F value Pr(>F) group 2 161.2 80.60 3.588 0.0307 * Residuals 117 2628.5 22.47 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 2-1. Tukey HSD TestTukeyHSD(model, conf.level=.95) 输出 Tukey multiple comparisons of means 95% family-wise confidence level Fit: aov(formula = values ~ group, data = data) $group diff lwr upr p adj P2-P1 1.066363 -1.4496236 3.582350 0.5744712 P3-P1 2.811853 0.2958665 5.327840 0.0244720 P3-P2 1.745490 -0.7704965 4.261477 0.2302467 2-2. Tukey投图plot(TukeyHSD(model, conf.level=.95), las = 2)3-1. Dunnett Testinstall.packages("DescTools") library(DescTools) DunnettTest(x=data$values, g=data$group, control ="P2") 输出： Dunnett's test for comparing several treatments with a control : 95% family-wise confidence level $P2 diff lwr.ci upr.ci pval P1-P2 -1.066363 -3.4395508 1.306825 0.5001 P3-P2 1.745490 -0.6276977 4.118678 0.1788 Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 参考文章：https://www.r-bloggers.com/2021/08/how-to-perform-dunnetts-test-in-r/https://www.r-bloggers.com/2021/08/how-to-perform-tukey-hsd-test-in-r/