How to Run the Shapiro-Wilk Test in R (With Real Examples and APA Reporting)
A step-by-step guide to shapiro.test() — interpreting output, fixing non-normal data, and writing it up for your thesis
How to Run the Shapiro-Wilk Test in R (With Real Examples and APA Reporting)
A step-by-step guide to shapiro.test() — interpreting output, fixing non-normal data, and writing it up for your thesis
If you’re about to run ANOVA, a t-test, or linear regression, the Shapiro-Wilk test is the fastest way to check whether your data is normal enough to trust the result. Here’s exactly how to run it in R, read the output, fix it when it fails, and write it up properly.

Quick answer: Run
shapiro.test(your_variable). If the p-value is greater than .05, your data doesn't significantly deviate from normal — proceed with parametric tests. If p ≤ .05, transform the data or switch to a non-parametric test. The function works for sample sizes between 3 and 5,000.
What the Shapiro-Wilk Test Actually Checks
The Shapiro-Wilk test, developed by Samuel Shapiro and Martin Wilk in 1965, tests the null hypothesis that your sample was drawn from a normally distributed population. It’s the standard first check before ANOVA, t-tests, and regression, because all three assume normally distributed data (or residuals).
It returns two numbers:
- W — a value between 0 and 1. Closer to 1 means your data’s shape correlates more closely with a normal curve.
- p-value — your decision rule. p > .05 means you fail to reject the null (data looks normal). p ≤ .05 means you reject it (data is not normal).
It’s specifically the strongest choice for small-to-medium samples — exactly the range most thesis and dissertation datasets fall into. (For larger samples, the Kolmogorov-Smirnov test becomes more appropriate — more on that below.)
[embed]
Running shapiro.test() in R, Step by Step
Step 1: Load the package
shapiro.test() lives in R's built-in stats package — nothing to install.
library(stats)
Step 2: Prepare your data
It needs to be a numeric vector. We’ll use the built-in mtcars dataset and the mpg column.
mtcars_data <- mtcars
mpg_data <- mtcars_data$mpg
Step 3: Run the test
shapiro_test_result <- shapiro.test(mpg_data)
print(shapiro_test_result)
Output:
Shapiro-Wilk normality test
data: mpg_data
W = 0.94756, p-value = 0.1229
Reading the Output
W = 0.948 is close to 1. p = 0.123 is above .05, so you fail to reject the null hypothesis — mpg does not significantly deviate from normal, and you're clear to run a parametric test on it.
That’s it. That’s the whole decision rule. Everything past this point is what to do when the answer isn’t this clean.
When Your Data Fails the Test
Failing is common, especially with skewed data — costs, counts, reaction times, horsepower. Here’s a real example using the hp column from mtcars, which is right-skewed:
shapiro.test(mtcars$hp)
Shapiro-Wilk normality test
data: mtcars$hp
W = 0.93342, p-value = 0.04881
p = .049 — just under .05. This data significantly deviates from normal. Two ways forward:
Option 1 — Transform it. A log transform is the standard first attempt for right-skewed data:
log_hp <- log(mtcars$hp)
shapiro.test(log_hp)
Shapiro-Wilk normality test
data: log_hp
W = 0.97026, p-value = 0.5065
p jumps to .507 — the transformed variable is now consistent with normality. If log doesn’t fully fix it, try a square-root transform (sqrt(x)) for moderate skew, or a cube-root transform (x^(1/3)) if your data includes zero or negative values, where log isn't defined.
Option 2 — Go non-parametric. If no transformation works, drop the normality assumption: use Mann-Whitney U instead of an independent t-test, Wilcoxon signed-rank instead of a paired t-test, or Kruskal-Wallis instead of one-way ANOVA. Often the faster, more defensible call on a deadline.
Reporting It in APA Format
APA italicizes both W and p, drops the leading zero on both (neither can exceed 1), and rounds to two decimals.
Template: “A Shapiro-Wilk test indicated that [variable] [was/was not] significantly different from a normal distribution, W = .XX, p = .XX.”
Passing example (mpg): “A Shapiro-Wilk test indicated that mpg scores were not significantly different from a normal distribution, W = .95, p = .12, suggesting the assumption of normality was satisfied.”
Failing example (hp): “A Shapiro-Wilk test indicated that horsepower scores were significantly different from a normal distribution, W = .93, p = .049, violating the assumption of normality. A log transformation was therefore applied prior to further analysis.”
Drop either sentence straight into your Results section.
Shapiro-Wilk vs. Kolmogorov-Smirnov
AspectShapiro-WilkKolmogorov-SmirnovR functionshapiro.test()ks.test()Best sample size3–5,000Works at any size; better for large nPower at small nHighLowerParameters neededNone — estimated from dataMust specify, or results are biasedTypical useDefault check before ANOVA/t-test/regressionComparing two samples, or vs. a fully specified distribution
For a typical thesis dataset, Shapiro-Wilk is the stronger default — and what most committees expect cited.
Common Mistakes
- Testing the raw outcome instead of model residuals. For ANOVA and regression, normality applies to the residuals. Fit the model first:
shapiro.test(resid(your_model)). - Testing pooled data instead of splitting by group. If comparing groups, normality is assumed within each group — subset before testing.
- Trusting the p-value alone past n ≈ 300–500. At large samples the test flags trivial deviations as significant. Pair it with a histogram or Q-Q plot.
- Transforming indefinitely without a stopping rule. Decide in advance: log, then square-root, then non-parametric — don’t keep trying variants until one happens to clear p = .05.
A Few Quick Answers
What sample size does this need? Between 3 and 5,000. Below 3 it can’t compute. Above 5,000 it gets overly sensitive — consider Kolmogorov-Smirnov or Anderson-Darling instead.
My data failed — is my analysis dead? No. Transform it (log/sqrt/cube-root) and retest, or switch to the non-parametric equivalent of whatever test you planned.
Is there a calculator instead of R? A few exist for tiny datasets, but R is free, scales to any real dataset size, and produces output your committee will recognize.
If you’re stuck on a normality check, an assumption violation, or anything further down your pipeline, I help thesis and dissertation researchers with exactly this kind of analysis in R, SPSS, Minitab, and Excel — reach out at **contact@rstudiodatalab.com* or message me directly on WhatsApp Originally published at rstudiodatalab.com.*
메타데이터
- post_id
- 73404a6bc609
- slug
- how-to-run-the-shapiro-wilk-test-in-r-with-real-examples-and-apa-reporting-73404a6bc609
- url
- https://medium.com/operations-research-bit/how-to-run-the-shapiro-wilk-test-in-r-with-real-examples-and-apa-reporting-73404a6bc609
- canonical_url
- https://medium.com/operations-research-bit/how-to-run-the-shapiro-wilk-test-in-r-with-real-examples-and-apa-reporting-73404a6bc609
- author_url
- https://medium.com/@rstudiodatalab
- status
- ok
- fetched_at
- 2026-06-24 13:29:15