Companion to Chapters 10–11 (Normality: Concepts and
Normality in Practice). A reference guide to visual and
statistical checks for normality, in base R plus the e1071
package. Other assumptions (equal variance, independence) are covered
separately.
You may use AI assistants (ChatGPT, Claude, etc.) to help debug your R code — that’s a realistic professional skill. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of an assignment based on this guide, note where at the end.
Tip: in the examples below, replace d with your
dataset and y with your numeric variable.
d <- your_dataframe # e.g., d <- read.csv("file.csv")
y <- d$your_variable # numeric variable to testHistogram
hist(y, main = "Histogram of y", xlab = "y")A roughly bell-shaped curve indicates approximate normality.
Boxplot
boxplot(y, horizontal = TRUE, main = "Boxplot of y", xlab = "y")Symmetric box and whiskers → roughly normal. Long tails or outliers → possible skew.
Q–Q Plot
qqnorm(y)
qqline(y)If points fall along the line, the data are approximately normal. An S-shape signals a kurtosis problem (heavier or lighter tails); a curve signals skew (@sec-normality-practice has annotated examples).
By group (optional)
par(mfrow = c(1,2))
for (g in levels(d$group)) {
qqnorm(y[d$group==g], main = paste("QQ:", g))
qqline(y[d$group==g])
}
par(mfrow = c(1,1))Use when comparing multiple groups before running a t-test or ANOVA.
summary(y) # min, quartiles, median, mean, max
mean(y)
sd(y)Skewness and kurtosis — use the e1071
package, which is what the rest of this course uses:
library(e1071)
skewness(y)
kurtosis(y)Interpretation (rough rules of thumb):
e1071::kurtosis() reports excess
kurtosis — a normal distribution gives ≈ 0, and the acceptable range is
roughly −1 to +1.If you ever see raw kurtosis instead (computed by hand, or from a different package), a normal distribution gives ≈ 3, and the equivalent acceptable range is roughly 2 to 4. Don’t mix the two thresholds — always check which convention a given number uses before judging it.
shapiro.test(y)H₀: the data are normal.
Caveat: with large samples (n > 50 or so), Shapiro–Wilk becomes oversensitive and will flag trivial departures. At large n, lean on the histogram and Q–Q plot rather than the test alone.
For group-wise testing:
by(y, d$group, shapiro.test)For paired designs: check the differences (post − pre), not each column separately — the two columns can each be skewed while the differences are normal, or vice versa.
diffs <- d$post - d$pre
shapiro.test(diffs)For regression: check the residuals, not the raw outcome variable.
shapiro.test(residuals(model))Always check both: plots show the practical shape of the data; the Shapiro test shows statistical evidence for deviation.
(Illustrative — from a simulated example, not independently re-verified with a live R session for this migration.)
Shapiro-Wilk normality test
W = 0.973, p = 0.412
Report as: “The distribution of scores did not deviate significantly from normality, W = 0.97, p = .41 (n = 40).”
set.seed(1)
y <- rnorm(30, mean = 100, sd = 15)
hist(y)
qqnorm(y); qqline(y)
shapiro.test(y)Then try skewed data:
y2 <- rexp(30, rate = 1/100)
hist(y2)
qqnorm(y2); qqline(y2)
shapiro.test(y2)Compare what the histogram, Q–Q plot, and Shapiro test each show for the normal vs. the skewed sample.
| Step | Purpose | Command |
|---|---|---|
| 1 | Visual overview | hist(), boxplot() |
| 2 | Linearity in Q–Q | qqnorm(), qqline() |
| 3 | Summary stats | summary(), mean(), sd(),
library(e1071); skewness(); kurtosis() |
| 4 | Normality test | shapiro.test() |
This guide limits scope to normality checks. Homogeneity of variance, linearity, and independence are addressed elsewhere in the course.