| posthoc_test | R Documentation |
Given a one-way, independent-groups design
(outcome ~ group), check the ANOVA assumptions and run the post-hoc
test they imply, following the standard decision tree:
each group normal and variances equal: Tukey HSD
(tukey_hsd());
each group normal but variances unequal: Games-Howell
(games_howell_test());
at least one group not normal: Dunn's test
(dunn_test()).
Normality is assessed per group with the Shapiro-Wilk test applied
to each group's values, routing on the smallest p-value across groups (a
single non-normal group sends the data to the non-parametric test). This is
deliberately not the pooled model residuals, which unequal variances would
make non-normal and so hide the Games-Howell case. Homogeneity of variance
is assessed with Levene's test (levene_test()). Both are judged
at the significance level. The function returns the chosen test's
usual pairwise result, with the selected method and the assumption verdicts
attached (and shown when the result is printed), so the routing is
transparent rather than hidden.
To check the same assumptions before the omnibus test and read off the
recommended omnibus/post-hoc pair, use check_test_assumptions();
its result can be passed back here through .assumptions so the checks
are not repeated. Choosing a test by first testing its assumptions on the
same data has a known cost — see the note in ?check_test_assumptions.
See the Datanovia tutorial Statistical Tests and Assumptions in R for a worked walkthrough.
posthoc_test(
data,
formula,
significance = 0.05,
...,
.assumptions = NULL,
omnibus = NULL
)
## S3 method for class 'posthoc_test'
print(x, ...)
data |
a data frame containing the variables in the formula. |
formula |
a formula of the form |
significance |
the significance level used to judge the Shapiro-Wilk and Levene assumption tests. Default is 0.05. |
... |
additional arguments forwarded to the selected post-hoc test, but
only those it accepts, so an argument meant for one route does not error on
another. In particular |
.assumptions |
(optional) the tibble returned by
|
omnibus |
(optional) an omnibus test result — from
|
x |
an object of class |
the pairwise comparison table returned by the selected post-hoc test
(a tukey_hsd, games_howell_test or dunn_test object),
additionally classed posthoc_test. The selected method and the
assumption verdicts are stored in the attributes "posthoc.method" and
"assumptions", and printed above the table.
check_test_assumptions(), tukey_hsd(), games_howell_test(),
dunn_test(), levene_test(),
shapiro_test().
The Datanovia tutorial: Statistical Tests and Assumptions in R.
df <- ToothGrowth
df$dose <- as.factor(df$dose)
# Assumptions hold here, so Tukey HSD is chosen
df %>% posthoc_test(len ~ dose)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.