Skip to content

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.

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.

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)

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.5097
expression B: W = 0.9780, p = 0.7689
intensity A: W = 0.8953, p = 0.006458
intensity B: W = 0.7747, p = 2.343e-05

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)
}

Normal Q-Q plot of expression residuals after subtraction of the group means.Normal Q-Q plot of intensity residuals after subtraction of the group means.

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.568
intensity: Levene F = 0.0414, p = 0.8394

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.

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.

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.

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.