View source: R/check_test_assumptions.R
| check_test_assumptions | R Documentation |
For a one-way, independent-groups design
(outcome ~ group), check the two assumptions that decide which family
of tests is appropriate — normality (Shapiro-Wilk, per group) and
homogeneity of variance (Levene) — and return the verdicts together with
the recommended omnibus and post-hoc test:
each group normal and equal variances: anova_test() +
tukey_hsd();
each group normal but unequal variances: welch_anova_test()
+ games_howell_test();
at least one group not normal: kruskal_test() + dunn_test().
The result is a tidy one-row tibble, so the same single assumption check can
drive both the omnibus and the post-hoc coherently — run the recommended
omnibus, then pass the result to posthoc_test() via its
.assumptions argument to avoid re-checking.
A note on choosing a test from the data. Selecting the test by first testing its assumptions on the same data is convenient but has a known cost: the assumption gate is least reliable exactly when it matters (Shapiro-Wilk has little power at small n and rejects trivial departures at large n), and conditioning the choice on it makes the p-value of the test finally run no longer the exact nominal quantity. A common alternative is to skip the gate and use a robust method unconditionally — Welch ANOVA with Games-Howell (which reduce to the classic result when variances are equal) or a rank-based test. Treat this recommendation as guidance, not a substitute for judgement.
See the Datanovia tutorial Statistical Tests and Assumptions in R for a worked walkthrough.
check_test_assumptions(data, formula, significance = 0.05)
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 tests. Default is 0.05. |
a one-row tibble with the columns .y. (the outcome),
normality.p (the smallest Shapiro-Wilk p across groups),
homogeneity.p (Levene's p), the logical verdicts normal and
equal.variance, the significance used, and the recommended
omnibus and posthoc test names.
posthoc_test(), shapiro_test(),
levene_test().
The Datanovia tutorial: Statistical Tests and Assumptions in R.
df <- ToothGrowth
df$dose <- as.factor(df$dose)
df %>% check_test_assumptions(len ~ dose)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.