Checking fit with Q–Q plots
Line your data up against a distribution and read the pattern. See why a plot often beats a normality test.
What runs in CodeSplash
- STAT104Shapiro–Wilk test Runs in CodeSplash
- STAT118Anderson–Darling general goodness of fit test Runs in CodeSplash
- Normality test (one test) Verified in Python and R
- Normality tests (battery) Verified in Python and R
- Fit a distribution (goodness of fit) Verified in Python and R
- Power transformation (Box–Cox / Yeo–Johnson) Verified in Python and R
You will be able to
- Read skew and heavy tails from a Q–Q plot
- Say why a normality test can mislead at both small and large n
- Compare candidate distributions with AIC and goodness of fit
Read first
Two lists, side by side
ReadA Q–Q plotQ–Q plotPlots your data's quantiles against a reference distribution's; points on the line mean the shapes match. sorts your data and plots each value against the matching quantile of a reference distribution. If the data come from that distribution, the points fall along a straight line.
You don't need to judge a shape by eye. You judge whether a line is straight, which people do very well.
View data
| residual |
|---|
| 12.030 |
| 12.730 |
| 12.050 |
| 11.050 |
| 14.390 |
| 8.810 |
| 8.720 |
| 10.120 |
| −12.530 |
| 7.840 |
| 12.620 |
| 9.670 |
| 9.460 |
| 4.730 |
| 9.430 |
| 10.990 |
| 10.770 |
| 5.770 |
| 7.130 |
| 11.320 |
| 8.440 |
| 11.200 |
| 13.010 |
| 7.980 |
| 12.130 |
| 11.090 |
| 11.050 |
| 12.950 |
| 8.590 |
| 13.150 |
| 10.540 |
| 2.260 |
| 6.510 |
| 7.720 |
| 7 |
| 12.790 |
| 8.330 |
| 13.230 |
| 10.180 |
| 11.580 |
| 9.800 |
| 5.410 |
| 9.680 |
| 14.120 |
| 7.420 |
| 1.440 |
| 16.020 |
| 15.470 |
| 8.660 |
| 13.800 |
| 5.300 |
| 6.890 |
| 7.410 |
| 4.260 |
| 3.360 |
| 11.810 |
| 9.150 |
| 10.380 |
| 10.830 |
| 13.260 |
First 60 of 200 rows.
This example uses the built-in data in Charts. The button opens the recipe, where you can read its guide and change its controls.
Build one
ExplorePredict the pattern first. Then change Skewness ε and Tail weight δ, and connect each shape with its pattern. Lower Sample size n and see how much a small sample wanders, even with no real departure.
AExplorable · Build a Q–Q plot
How do skewness and heavy tails show up in a normal Q–Q plot?
Before plotting: what pattern will the points make?
Below 1: heavier tails.
Commit your prediction above to see the result
Make your prediction to see the result.
Name the pattern
Read| What you see | What it means |
|---|---|
| Points on the line | Compatible with the reference |
| Curve bending up at both ends | Right skew |
| Curve bending down at both ends | Left skew |
| S shape, steep at the ends | Heavy tails |
| S shape, flat at the ends | Light tails |
A plot or a test?
PredictPredict first
Your data have a mild skew that barely affects a t test. With , how often does a Shapiro–Wilk test reject normality?
Reveal
Almost every time, at a large enough . With a sample that large it detects departures too small to matter, while at small it can miss large ones. The test answers "is this exactly normal?", and that isn't your question.
See the paradox
ExploreCompare the rejection rates at small and large with the t test's Type I error. Find a departure where Shapiro–Wilk nearly always rejects at , while the t test stays close to its promised rate.
AExplorable · The normality-test paradox
Why is a normality test least helpful exactly when you might rely on it?
How often does Shapiro–Wilk reject this skew at n = 1,000?
Commit your prediction above to see the result
Make your prediction to see the result.
Fix it, or fit another family
ReadOzone's skewness is 1.24. A Box–Cox transformation with λ = 0.20 brings it to −0.02, and the Shapiro–Wilk p moves from p < .001 to p = .340.
Or fit another family. For a set of lifetimes, AIC prefers the gamma distribution, and its goodness-of-fit test gives p = .410: compatible with that fit.
Check your reading
CheckpointCheck yourself
On a normal Q–Q plot the points lie close to the line in the middle, and bend sharply upward at the right end only. What does that suggest?
Show the answer
Answer: a
Points above the line at the right end mean the largest values exceed what the reference predicts. Small wiggles at the ends are normal, so judge them against the band.
Check yourself
With 8 data points, a Shapiro–Wilk test gives p = 0.60. What can you conclude?
Show the answer
Answer: b
A large p at small is no evidence of normality. Use a Q–Q plot and what you know about the process that produced the data.
Check yourself
For fuel economy (mpg) in the mtcars data, what is the Shapiro–Wilk W? Give two decimals.
Show the answer
Answer: 0.947564726479274
It's close to 1, with . W measures how straight the Q–Q plot is.
Check a column in the app
In the appOn a numeric column's page in Insights, Which distribution is this? compares the candidates for you, with Q–Q plots. In Analyze, run a normality test or a battery, and fit families directly.
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
ozone = pd.read_csv("airquality.csv")["Ozone"].dropna()
stats.probplot(ozone, dist="norm", plot=plt)
plt.savefig("ozone-qq.png")
print(stats.shapiro(ozone))ozone <- na.omit(read.csv("airquality.csv")$Ozone)
png("ozone-qq.png")
qqnorm(ozone)
qqline(ozone)
dev.off()
shapiro.test(ozone)Recap
Recap- A Q–Q plot compares your data with a reference. A straight line means compatible.
- Bends show skew, and S shapes show tails.
- Normality tests over-react at large and under-react at small . Ask whether a departure matters for your method.
Concepts in this lesson