Performs Dunnett's test for comparing each of several treatment
groups against a single control (reference) group. Unlike all-pairwise
post-hoc tests, Dunnett's procedure controls the family-wise error rate over
only the k - 1 treatment-vs-control comparisons, using the exact
multivariate-t distribution (which accounts for the correlation between the
comparisons that share the control group).
This is a pipe-friendly wrapper around emmeans::emmeans() +
emmeans::contrast() (with adjust = "mvt"), so the
emmeans package must be installed. The results match
DescTools::DunnettTest() and multcomp::glht(..., mcp(... =
"Dunnett")).
See the Datanovia tutorial One-Way ANOVA in R for a worked walkthrough.
Arguments
- data
a data.frame containing the variables in the formula.
- formula
a formula of the form
x ~ groupwherexis a numeric variable giving the data values andgroupis a factor with one or multiple levels giving the corresponding groups. For example,formula = TP53 ~ cancer_group.- ref.group
a character string specifying the reference (control) group. Each remaining group level is compared against this group. If
NULL(default), the first level of the grouping variable is used as the control.- conf.level
confidence level of the (simultaneous) confidence intervals.
- detailed
logical value. Default is FALSE. If TRUE, a detailed result is shown.
Value
a data frame with some of the following columns:
.y.: the outcome variable used in the test.group1,group2: the compared groups;group1is the control (reference) andgroup2is the treatment, consistent with theref.groupconvention oft_test()/wilcox_test()/dunn_test()/emmeans_test().n1,n2: sample sizes of the control and treatment groups.estimate: the estimated mean differencegroup1 - group2(control minus treatment).conf.low,conf.high: simultaneous confidence interval for the difference.statistic: the t-statistic.df: degrees of freedom.p.adj: the Dunnett-adjusted p-value.method: the statistical test used.p.adj.signif: the significance level of the adjusted p-value.
The estimate, confidence
interval, se and method columns are returned only when detailed =
TRUE.
The returned object has an attribute called args, which is a list holding the test arguments.
References
Dunnett, C. W. (1955) A multiple comparison procedure for comparing several treatments with a control. Journal of the American Statistical Association, 50, 1096-1121.
See also
tukey_hsd(), games_howell_test(),
emmeans_test()
The Datanovia tutorial: One-Way ANOVA in R.
Examples
if (requireNamespace("emmeans", quietly = TRUE)) {
# Compare each dose to the control dose ("0.5")
ToothGrowth %>% dunnett_test(len ~ dose)
# Detailed output (estimate + simultaneous confidence interval)
ToothGrowth %>% dunnett_test(len ~ dose, detailed = TRUE)
# Grouped data
ToothGrowth %>%
group_by(supp) %>%
dunnett_test(len ~ dose)
}
#> # A tibble: 4 × 10
#> supp .y. group1 group2 n1 n2 statistic df p.adj p.adj.signif
#> * <fct> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
#> 1 OJ len 0.5 1 10 10 -5.64 27 1.07e- 5 ****
#> 2 OJ len 0.5 2 10 10 -7.65 27 6.31e- 8 ****
#> 3 VC len 0.5 1 10 10 -5.61 27 1.19e- 5 ****
#> 4 VC len 0.5 2 10 10 -11.6 27 1.11e-11 ****
