tukey_hsd {rstatix} | R Documentation |
Tukey Honest Significant Differences
Description
Provides a pipe-friendly framework to performs Tukey post-hoc
tests. Wrapper around the function TukeyHSD()
. It is
essentially a t-test that corrects for multiple testing.
Can handle different inputs formats: aov, lm, formula.
Usage
tukey_hsd(x, ...)
## Default S3 method:
tukey_hsd(x, ...)
## S3 method for class 'lm'
tukey_hsd(x, ...)
## S3 method for class 'data.frame'
tukey_hsd(x, formula, ...)
Arguments
x |
an object of class |
... |
other arguments passed to the function
|
formula |
a formula of the form |
data |
a data.frame containing the variables in the formula. |
Value
a tibble data frame containing the results of the different comparisons.
Methods (by class)
-
tukey_hsd(default)
: performs tukey post-hoc test fromaov()
results. -
tukey_hsd(lm)
: performs tukey post-hoc test fromlm()
model. -
tukey_hsd(data.frame)
: performs tukey post-hoc tests using data and formula as inputs. ANOVA will be automatically performed using the functionaov()
Examples
# Data preparation
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Tukey HSD from ANOVA results
aov(len ~ dose, data = df) %>% tukey_hsd()
# two-way anova with interaction
aov(len ~ dose*supp, data = df) %>% tukey_hsd()
# Tukey HSD from lm() results
lm(len ~ dose, data = df) %>% tukey_hsd()
# Tukey HSD from data frame and formula
tukey_hsd(df, len ~ dose)
# Tukey HSD using grouped data
df %>%
group_by(supp) %>%
tukey_hsd(len ~ dose)