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:

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)

Arguments

data

a data frame containing the variables in the formula.

formula

a formula of the form x ~ group where x is a numeric outcome and group is a factor with two or more levels.

significance

the significance level used to judge the Shapiro-Wilk and Levene tests. Default is 0.05.

Value

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.

Examples

df <- ToothGrowth
df$dose <- as.factor(df$dose)
df %>% check_test_assumptions(len ~ dose)
#> # A tibble: 1 × 8
#>   .y.   normality.p homogeneity.p normal equal.variance significance omnibus   
#>   <chr>       <dbl>         <dbl> <lgl>  <lgl>                 <dbl> <chr>     
#> 1 len         0.164         0.528 TRUE   TRUE                   0.05 anova_test
#> # ℹ 1 more variable: posthoc <chr>