Checking for Normality in R

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.

A Note on AI Tools

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.

1. Set Up Your Variable

d <- your_dataframe          # e.g., d <- read.csv("file.csv")
y <- d$your_variable         # numeric variable to test

2. Visual Checks for Normality

Histogram

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.

3. Descriptive Statistics

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

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.

4. Shapiro–Wilk Test

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

5. Combining Plots and Tests

Always check both: plots show the practical shape of the data; the Shapiro test shows statistical evidence for deviation.

6. When Normality Matters

7. Minimal Reporting Example

(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).”

8. Try It Yourself

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.

Quick Reference

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.