Checking Assumptions
A diagnostic cannot certify that a statistical test is valid. Start with the experimental unit and the comparison you want to estimate, then inspect whether the model describes the measurements. A large diagnostic p-value does not establish normality, equal variance, or independence.
Start with the study design
Section titled “Start with the study design”For the example below, each row represents a different independent sample. A mean difference between two independent groups is the target. Welch’s t-test allows the groups to have different variances, so a preliminary variance test does not select between Student’s and Welch’s tests.
| Study structure | Analysis decision |
|---|---|
| Different samples in two groups | Estimate the group mean difference with an appropriate interval. Welch’s test does not require equal variances. |
| The same samples before and after treatment | Analyze the within-sample differences with a paired analysis. |
| Repeated measurements or several cells from each donor | Model the dependence or summarize at the experimental unit. See mixed models. |
| Count outcomes with unequal exposure | Use a count model and an exposure offset where appropriate. See count regression. |
Normality assumptions belong to the within-group errors of an ANOVA or linear model. Pooling raw measurements from groups with different means can create a non-normal mixture even when each group’s errors are normal. Independence comes from the study design; a Shapiro-Wilk test cannot check it.
Get the data
Section titled “Get the data”Download assumptions_data.csv into your working directory. The invented dataset contains 60 samples, a group label, an expression measurement, and an intensity measurement. Run the blocks for your chosen language in order.
The examples use R with ggplot2 and car, or Python with pandas, SciPy, and Matplotlib.
library(ggplot2)library(car)
data <- read.csv("assumptions_data.csv")data$group <- factor(data$group)dir.create("outputs", showWarnings = FALSE)from pathlib import Path
import matplotlib.pyplot as pltimport pandas as pdfrom scipy import stats
data = pd.read_csv("assumptions_data.csv")output = Path("outputs")output.mkdir(exist_ok=True)Inspect distributions within groups
Section titled “Inspect distributions within groups”The following table reports Shapiro-Wilk statistics separately for each group. A small p-value is evidence against that normal model. A large p-value means that this test did not detect a departure; a small sample can hide substantial departures.
These results describe the example. They do not trigger an automatic switch to another test. A rank test answers a different question from a comparison of means, and unequal distribution shapes complicate a location interpretation.
for (variable in c("expression", "intensity")) { for (group_name in levels(data$group)) { values <- data[data$group == group_name, variable] diagnostic <- shapiro.test(values) cat(sprintf("%s %s: W = %.4f, p = %.4g\n", variable, group_name, diagnostic$statistic, diagnostic$p.value)) }}expression A: W = 0.9689, p = 0.5097expression B: W = 0.9780, p = 0.7689intensity A: W = 0.8953, p = 0.006458intensity B: W = 0.7747, p = 2.343e-05for variable in ("expression", "intensity"): for group_name in sorted(data["group"].unique()): values = data.loc[data["group"] == group_name, variable] diagnostic = stats.shapiro(values) print(f"{variable} {group_name}: W = {diagnostic.statistic:.4f}, " f"p = {diagnostic.pvalue:.4g}")expression A: W = 0.9689, p = 0.5097expression B: W = 0.9780, p = 0.7689intensity A: W = 0.8953, p = 0.006458intensity B: W = 0.7747, p = 2.343e-05Inspect the model residuals
Section titled “Inspect the model residuals”Subtracting each group’s fitted mean produces residuals for the model with one mean per group. The Q-Q plots compare those residuals with normal quantiles. Examine the tails and isolated points, then consider the sample size and the sensitivity of the intended estimate. A plot near the reference line is compatible with the model, not proof of it.
for (variable in c("expression", "intensity")) { model_formula <- reformulate("group", response = variable) fitted_model <- lm(model_formula, data = data) residual_data <- data.frame(residual = residuals(fitted_model)) qq_plot <- ggplot(residual_data, aes(sample = residual)) + stat_qq(color = "#3B6DB3") + stat_qq_line() + labs(title = paste("Group-centered residuals:", variable), x = "Theoretical normal quantiles", y = "Residual quantiles") + theme_minimal(base_size = 12) ggsave(paste0("outputs/qq-", variable, "-r.png"), qq_plot, width = 5, height = 4, dpi = 150)}

for variable in ("expression", "intensity"): group_mean = data.groupby("group")[variable].transform("mean") residuals = data[variable] - group_mean figure, axis = plt.subplots(figsize=(5, 4)) stats.probplot(residuals, dist="norm", plot=axis) axis.set(title=f"Group-centered residuals: {variable}", xlabel="Theoretical normal quantiles", ylabel="Residual quantiles") figure.tight_layout() figure.savefig(output / f"qq-{variable}-python.png", dpi=150) plt.close(figure)

Describe variance without a selection rule
Section titled “Describe variance without a selection rule”Levene’s test compares dispersion between groups. Both implementations below use deviations from group medians. Its p-value measures evidence against equal population variances under the test assumptions. A large value does not establish that the variances are equal, and it does not make an analysis safe.
for (variable in c("expression", "intensity")) { diagnostic <- leveneTest(reformulate("group", response = variable), data = data, center = median) cat(sprintf("%s: Levene F = %.4f, p = %.4g\n", variable, diagnostic[["F value"]][1], diagnostic[["Pr(>F)"]][1]))}expression: Levene F = 0.3297, p = 0.568intensity: Levene F = 0.0414, p = 0.8394for variable in ("expression", "intensity"): group_a = data.loc[data["group"] == "A", variable] group_b = data.loc[data["group"] == "B", variable] diagnostic = stats.levene(group_a, group_b, center="median") print(f"{variable}: Levene F = {diagnostic.statistic:.4f}, " f"p = {diagnostic.pvalue:.4g}")expression: Levene F = 0.3297, p = 0.568intensity: Levene F = 0.0414, p = 0.8394Respond to a model problem
Section titled “Respond to a model problem”Check unusual records against the source data before excluding them. For a positive measurement with a multiplicative interpretation, a log-scale analysis changes the target from an arithmetic mean difference to a comparison on the log scale. State that target before interpreting the result.
For independent group means, Welch’s method handles unequal variances. Strong skew, small samples, and influential observations still require judgment. A count model addresses counts directly; a paired or mixed model addresses dependence. A rank test does not repair dependence or automatically estimate a difference in medians.
Check your understanding
Section titled “Check your understanding”Two normal populations have different means. Their combined measurements produce a curved Q-Q plot. Does that alone invalidate a comparison of group means?
It does not. The combined distribution mixes the two means. Inspect each group’s distribution and the fitted residuals, and check independence from the design.
Scientific references
Section titled “Scientific references”The NIST residual guidance describes graphical checks for model errors. Rochon, Gondan, and Kieser, 2012 distinguish conditional test errors from the error rate of the complete selection procedure. Their simulated procedures retain acceptable overall error rates in the settings they examine. Their results do not make a nonsignificant normality test proof of normality.
Fox and Weisberg, 2019, describe the car functions in An R Companion to Applied Regression.
Further reading
Section titled “Further reading”The NIST residual guidance explains graphical checks for model errors. The R Shapiro-Wilk reference states the normality hypothesis and sample size limits of the diagnostic used here.
Rochon, Gondan, and Kieser examine the consequences of choosing a test after a normality pretest. Their comparison helps distinguish conditional error rates from the error rate of the complete procedure.
Continue with two-group estimates and figures, or use Sample Size and Power to plan a study.