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")).
dunnett_test(
data,
formula,
ref.group = NULL,
conf.level = 0.95,
detailed = FALSE
)a data.frame containing the variables in the formula.
a formula of the form x ~ group where x is a
numeric variable giving the data values and group is a factor with
one or multiple levels giving the corresponding groups. For example,
formula = TP53 ~ cancer_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.
confidence level of the (simultaneous) confidence intervals.
logical value. Default is FALSE. If TRUE, a detailed result is shown.
a data frame with some of the following columns:
.y.: the outcome variable used in the test.
group1,group2: the compared groups; group1 is the control
(reference) and group2 is the treatment, consistent with the
ref.group convention of t_test()/wilcox_test()/
dunn_test()/emmeans_test().
n1,n2: sample sizes of
the control and treatment groups.
estimate: the estimated mean
difference group1 - 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.
Dunnett, C. W. (1955) A multiple comparison procedure for comparing several treatments with a control. Journal of the American Statistical Association, 50, 1096-1121.
# Compare each dose to the control dose ("0.5")
ToothGrowth %>% dunnett_test(len ~ dose)
#> # A tibble: 2 × 9
#> .y. group1 group2 n1 n2 statistic df p.adj p.adj.signif
#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
#> 1 len 0.5 1 20 20 -6.81 57 1.34e- 8 ****
#> 2 len 0.5 2 20 20 -11.6 57 3.33e-16 ****
# Detailed output (estimate + simultaneous confidence interval)
ToothGrowth %>% dunnett_test(len ~ dose, detailed = TRUE)
#> # A tibble: 2 × 14
#> .y. group1 group2 n1 n2 estimate conf.low conf.high se statistic
#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 len 0.5 1 20 20 -9.13 -12.2 -6.09 1.34 -6.81
#> 2 len 0.5 2 20 20 -15.5 -18.5 -12.5 1.34 -11.6
#> # ℹ 4 more variables: df <dbl>, p.adj <dbl>, p.adj.signif <chr>, method <chr>
# 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 ****