Shapiro-Wilk Test in R: Step-by-Step Guide (shapiro.test)

Run the Shapiro-Wilk test in R with shapiro.test(). Step-by-step code, output interpretation, APA reporting, and fixes for non-normal data
Author photo
Written by Dr. Zubair, PhD Statistics
Reviewed by Dr Ali

Dr. Zuabir holds a PhD in Statistics and has helped 200+ PhD and Master's students complete their dissertation statistical analysis using R, SPSS, and Minitab.

If you're about to run ANOVA, a t-test, or linear regression for your thesis, the Shapiro-Wilk test in R is the fastest way to check whether your data is close enough to normal to trust those results. This guide shows you exactly how to run shapiro.test(), read the W statistic and p-value, fix non-normal data, and write the result up in APA format for your methodology chapter.

Quick Answer
Run shapiro.test(your_variable) in R. If the p-value is greater than .05, your data does not significantly deviate from normal — you're clear to use parametric tests like ANOVA or a t-test. If the p-value is .05 or below, treat your data as non-normal and either transform it or switch to a non-parametric test. The function works for sample sizes between 3 and 5,000.
Shapiro-Wilk Normality Test | shapiro.test in R

The Shapiro-Wilk test was developed by Samuel Shapiro and Martin Wilk in 1965 and remains the most widely recommended normality test for small-to-medium sample sizes — exactly the range most thesis and dissertation datasets fall into. It tests the null hypothesis that your sample was drawn from a normally distributed population, which matters because parametric tests like ANOVA, t-tests, and linear regression all assume that condition.

Table of Contents

What Is the Shapiro-Wilk Test in R?

The Shapiro-Wilk normality test evaluates whether a numeric sample plausibly came from a normal distribution. It returns two numbers: a W statistic between 0 and 1, and a p-value. The closer W is to 1, the more closely your data's shape matches a normal curve.

Null hypothesis! The data is normally distributed — it has no significant difference from a normal curve.


Alternate Hypothesis! The data is not normally distributed.

You decide which hypothesis to accept using the p-value. If the p-value is less than 0.05, you reject the null hypothesis — the data is not normal. If the p-value is greater than 0.05, you fail to reject the null hypothesis — the data appears normal enough to proceed.

the Shapiro-Wilk test is frequently applied to assess the normality of data distributions

Why You Need This Before ANOVA, T-Tests, and Regression

Researchers routinely confirm normality with the Shapiro-Wilk test before running a chi-square or ANOVA on their primary outcomes — it's a standard preliminary check, not an optional one, before trusting parametric output [1]. The same logic applies across fields: water-quality researchers verify normality and homogeneity of variance before applying further statistical methods [2], and the test's small-sample strength is precisely why Baharum recommends it for samples under 50 [3]. Multiple studies confirm it detects deviations from normality more reliably than alternatives at small n [4, 5].

The Shapiro-Wilk test is a statistical test used to determine if a sample of data comes from a normal distribution.

Samuel Shapiro and Martin Wilk

The test isn't limited to univariate data either — it has been extended to multivariate normality checks, which matters if your thesis involves MANOVA or factor analysis. In veterinary research, for instance, it's the default first step before any further model-fitting [7]. In a direct comparison of normality tests, it showed superior power for detecting non-normality versus the Kolmogorov-Smirnov test specifically [8].

Normality Test Parametric/Non-parametric Best for Sample Size Sensitivity Strengths Weaknesses
Shapiro-Wilk TestParametric< 5000HighMost accurate for small datasetsOverly sensitive past n = 5000
Kolmogorov-Smirnov TestNon-parametricLargeMediumWorks against any distributionLess powerful for small datasets
Anderson-Darling TestNon-parametricSmall to MediumHighMore weight in the tailsMore complex calculation
Lilliefors TestNon-parametricMediumMediumExtension of K-S testAssumes mean/variance unknown
Jarque-Bera TestParametricLargeLowEasy to computeUnreliable for small datasets
D'Agostino's K-squared TestParametricMedium to LargeMediumTests skewness and kurtosisNeeds a larger sample

Step-by-Step: How to Perform the Shapiro-Wilk Test in R

Step 1: Load the stats package

shapiro.test() lives in R's built-in stats package, so there's nothing to install.

# Load the stats package
library(stats)

Step 2: Prepare your data

Your data needs to be a numeric vector. We'll use R's built-in mtcars dataset and the miles-per-gallon (mpg) column.
# Load the mtcars dataset
mtcars_data <- mtcars
# Select the mpg variable
mpg_data <- mtcars_data$mpg
Prepare Your Data for the Test using shapiro.test in R

Step 3: Run shapiro.test()

Call the function directly on your numeric vector.
# Perform the Shapiro-Wilk test
shapiro_test_result <- shapiro.test(mpg_data)
# Display the results
print(shapiro_test_result)
Apply the Shapiro-Wilk Test using R

How to Interpret Shapiro-Wilk Test Output in R

Running the code above on mpg_data returns:

	Shapiro-Wilk normality test

data:  mpg_data
W = 0.94756, p-value = 0.1229

Here's the read: W = 0.948 is close to 1, telling you the data's shape correlates well with a normal distribution. p = 0.123 is above 0.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.

Test Statistic (W) and P-Value using shapiro.test in R

What to Do When Your Data Fails the Shapiro-Wilk Test

A failed test is common, especially with the skewed distributions typical of survey, cost, and reaction-time data. Here's a real failing example using the hp (horsepower) 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 = 0.049 is just under 0.05 — this data significantly deviates from normal. You have two paths forward.

Option 1: Transform the data. A log transformation is the most common first attempt for right-skewed data like cost, count, or horsepower variables:

log_hp <- log(mtcars$hp)
shapiro.test(log_hp)

	Shapiro-Wilk normality test

data:  log_hp
W = 0.97026, p-value = 0.5065

After a log transform, p jumps to 0.507 — the transformed variable is now consistent with a normal distribution and is ready for parametric testing. If a log transform doesn't fully resolve it, try a square-root transform (sqrt(x)) for moderate skew or a cube-root transform (x^(1/3)) for data containing zero or negative values, where log isn't defined.

Option 2: Switch to a non-parametric test. If no transformation normalizes the data, drop the normality assumption entirely and use the non-parametric equivalent: 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. This is often the faster, more defensible route for a thesis on a tight deadline.

Send me your p-value and variable type and I'll tell you the fastest defensible fix for your specific dataset.

How to Report the Shapiro-Wilk Test in APA Format (For Your Thesis)

APA style italicizes both the W statistic and the p-value, and drops the leading zero on both since neither can exceed 1. Round to two decimal places unless your committee specifically asks for three.

APA reporting 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 this sentence directly into your Results or Preliminary Analyses section — most committees expect exactly this phrasing.

Shapiro-Wilk vs Kolmogorov-Smirnov Test: Which Should You Use?

AspectShapiro-WilkKolmogorov-Smirnov
R functionshapiro.test()ks.test()
Best sample size3–5,000Works at any size; more reliable for large n
Power at small nHighLower
What it testsSample shape vs. normal distribution specificallySample's empirical distribution vs. any specified distribution
Parameters neededNone — estimated from your dataMust specify distribution parameters, or results are biased
Typical thesis useDefault check before ANOVA, t-test, or regression on small-to-medium samplesComparing two samples, or testing against a fully specified theoretical distribution

For a typical thesis dataset (n under a few hundred), Shapiro-Wilk is the stronger default — it's also what most committees expect to see cited.

Limitations of the Shapiro-Wilk Test

The test is sensitive to dataset size. With a large sample, even minor, practically irrelevant deviations from normality can produce a significant (low) p-value — the test flags non-normality that isn't substantively meaningful. At the other extreme, with fewer than three data points the test cannot run at all. An alternative omnibus approach, the Cauchy combination test, has been proposed specifically to address disagreement between normality tests in these edge cases [6].

Limitations of the Shapiro-Wilk Test

Visualizing Normality: Histogram and Q-Q Plot in R

Always back up the test with a visual check, especially on large or very small samples where the p-value alone can mislead.

Histogram

# Histogram of mpg
hist(mpg_data, main="Histogram of MPG", xlab="Miles per Gallon", col="lightblue")
Histogram for Normality test of mpg data set

Q-Q Plot

A Q-Q plot compares your data's quantiles against a theoretical normal distribution's quantiles. Points following a straight diagonal line indicate normality.
# Q-Q plot of mpg
qqnorm(mpg_data)
qqline(mpg_data, col="red")
Q-Q plot for Normality test

Common Mistakes When Running the Shapiro-Wilk Test in R

Four mistakes show up repeatedly in thesis methodology chapters submitted for review:

  1. Testing the raw outcome variable instead of the model residuals. For ANOVA and regression, the normality assumption applies to the residuals, not necessarily the raw dependent variable. Fit the model first, then run shapiro.test(resid(your_model)).
  2. Testing a pooled variable instead of splitting by group. If you're comparing groups (e.g., treatment vs. control), normality is assumed within each group separately. Subset your data by group before testing, or test the model residuals as above.
  3. Trusting the p-value alone on a large sample. Past roughly n = 300–500, the test can flag statistically significant but practically trivial deviations. Pair it with a histogram or Q-Q plot before deciding your data is unusable.
  4. Re-running the test after every transformation attempt without a stopping rule. Decide in advance — log, then square-root, then non-parametric — rather than trying transformations indefinitely until one happens to pass at p = .06.

Conclusion

The Shapiro-Wilk test is the standard first check for normality before parametric statistics in R. Run shapiro.test(), read the p-value against 0.05, back it up with a histogram or Q-Q plot, and if it fails, either transform your variable or switch to the non-parametric equivalent. Get this step right and the rest of your methodology chapter — and your committee's confidence in it — follows from it.

People also read

Frequently Asked Questions

What is the Shapiro-Wilk test in R used for?

It checks whether a numeric sample plausibly came from a normal distribution, which is a required assumption before running parametric tests like ANOVA, t-tests, or linear regression. Run it with shapiro.test(your_variable).

How do you interpret a Shapiro-Wilk test in R?

Check the p-value: if it's greater than 0.05, your data does not significantly deviate from normal. If it's 0.05 or below, treat it as non-normal. The W statistic tells you how closely the data's shape matches a normal curve — closer to 1 means a stronger match.

What is the difference between the Shapiro-Wilk test and the Kolmogorov-Smirnov test in R?

shapiro.test() is more powerful for small-to-medium samples (n under 5,000) and tests specifically for normality. ks.test() compares your data against any fully specified distribution and is generally better suited to larger samples.

What does it mean if my data fails the Shapiro-Wilk test in R?

A p-value of 0.05 or below means your data significantly deviates from normal. It doesn't mean your analysis is dead — apply a log, square-root, or cube-root transformation and retest, or switch to the non-parametric equivalent of your planned test (e.g., Wilcoxon instead of a t-test).

How do you report the Shapiro-Wilk test in APA format for a thesis?

Italicize W and p, drop the leading zero on both, and round to two decimals: "A Shapiro-Wilk test indicated that [variable] was/was not significantly different from a normal distribution, W = .XX, p = .XX."

How do you perform the test de Shapiro Wilk in R?

The function name doesn't change by language — use shapiro.test(your_variable) the same way regardless of how you searched for it. The output gives you the W statistic and p-value described above.

Is there a Shapiro-Wilk test calculator, or do I need R?

Online calculators exist for quick checks on tiny datasets, but R's shapiro.test() is free, handles datasets of any realistic thesis size, and produces output your committee will recognize and expect to see cited directly.

What sample size do I need for the Shapiro-Wilk test in R?

Between 3 and 5,000 observations. Below 3, the function can't compute a result. Above 5,000, the test becomes overly sensitive to trivial deviations — consider the Kolmogorov-Smirnov or Anderson-Darling test instead, or lean on visual diagnostics.

About the Author

Zubair has a PhD-level background in statistics and runs RStudioDataLab, helping thesis and dissertation researchers run and interpret their analyses in R, SPSS, Minitab, and Excel. If you're stuck on a normality check, an assumption violation, or anything further down your analysis pipeline, message him directly on WhatsApp above.

Reference:
[1] D. Dimitrovski, V. Joukes, S. Rachão, & M. Tibério, "Wine tourism apps as wine destination branding instruments: content and functionality analysis," Journal of Hospitality and Tourism Technology, vol. 10, no. 2, p. 136-152, 2019. https://doi.org/10.1108/jhtt-10-2017-0115

[2] K. Nyakeya, "Trends in water quality in a tropical kenyan river-estuary system: responses to anthropogenic activities", Asian Journal of Biology, vol. 20, no. 6, p. 34-51, 2024. https://doi.org/10.9734/ajob/2024/v20i6413

[3] Z. Baharum, "The critical factors for built-up edge formation in stainless steel milling", International Journal of Advanced Trends in Computer Science and Engineering, vol. 9, no. 1.4, p. 282-288, 2020. https://doi.org/10.30534/ijatcse/2020/4291.42020

[4] A. Owusu, M. Asare, & R. Owusu, "Using gis to understand cervical cancer screening behaviors among women living with HIV (with) in Ghana," Asian Pacific Journal of Environment and Cancer, vol. 5, no. 1, p. 17-23, 2022. https://doi.org/10.31557/apjec.2022.5.1.17-23

[5] R. Rahmalia, "Digital transformation on financial performance: unleashing corporate excellence through mobile banking adoption in Malaysia's public listed banks", International Journal of Academic Research in Business and Social Sciences, vol. 14, no. 1, 2024. https://doi.org/10.6007/ijarbss/v14-i1/20576

[6] Z. Meng and Z. Jiang, "Cauchy combination omnibus test for normality," Plos One, vol. 18, no. 8, p. e0289498, 2023. https://doi.org/10.1371/journal.pone.0289498

[7] R. Evans, "Verifying model assumptions and testing normality," Veterinary Surgery, vol. 53, no. 1, p. 17-17, 2023. https://doi.org/10.1111/vsu.14034

[8] A. Jo, G. Bm, & F. George, "Performances of several univariate tests of normality: an empirical study", Journal of Biometrics & Biostatistics, vol. 07, no. 04, 2016. https://doi.org/10.4172/2155-6180.1000322

[9] R. Souza, "Teaching descriptive statistics and hypothesis tests measuring water density", Journal of Chemical Education, vol. 100, no. 11, p. 4438-4448, 2023. https://doi.org/10.1021/acs.jchemed.3c00402

Session info:

sessionInfo()

R version 4.4.1 (2024-06-14 ucrt)

Platform: x86_64-w64-mingw32/x64

Running under: Windows 11 x64 (build 22631)

Matrix products: default

tzcode source: internal

attached base packages:

[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):

[1] compiler_4.4.1 tools_4.4.1



Stuck on normality, an assumption violation, or anything further down your analysis? Message me on WhatsApp for a fast read on your output, or email contact@rstudiodatalab.com to schedule a discovery call.