liveBook · Manning

Shapiro–Wilk test

As explained in Statistics Slam Dunk

The Shapiro-Wilk test is a statistical test that evaluates whether a sample is consistent with a normal distribution.

The Shapiro–Wilk test evaluates whether a sample is consistent with a normal distribution. Its null hypothesis states that the data is normally distributed. Using a 0.05 significance cutoff, a p-value above 0.05 supports assuming normality, while a p-value at or below 0.05 supports rejecting normality. section 5.5

Use the test alongside a density plot rather than relying on visual inspection alone. In regression preparation, normally distributed variables can remain candidates, while variables flagged as non-normal may be withheld because linear regression assumes Gaussian distributions. section 5.5.2 section 14.3

Testing NBA deflections

In R, run `shapiro.test(hustle$deflections)`. The result `W = 0.98557, p-value = 0.4235` exceeds 0.05, so deflections can be treated as normally distributed for this screening step. Pair the result with a density plot to inspect the distribution’s shape. section 5.5.1

A visually deceptive distribution

For NBA points per game, a histogram may appear approximately Gaussian, but `shapiro.test(nba_stats$PTS)` returns `W = 0.99016, p-value = 0.04124`. Because the p-value is below 0.05, assume the distribution is not quite normal. section 14.3

options(scipen = 999)

shapiro.test(hustle$deflections)
## 
##  Shapiro-Wilk normality test
## 
## data:  hustle$deflections
## W = 0.98557, p-value = 0.4235
dp1 <- ggplot(hustle, aes(x = deflections)) +
 geom_density(alpha = .3, fill = "dodgerblue4") +
 labs(title = "Deflections",
      subtitle = "Shapiro-Wilk test of normality: p-value = 0.42",
      x = "", 
      y = "Density") +
 theme(plot.title = element_text(face = "bold")) 
print(dp1)

Inspect the executable R call, reported W statistic, p-value, and matching density plot for the deflections example. section 5.5.1

How Statistics Slam Dunk covers it

How deep it goes
Defines the null hypothesis and cutoff, demonstrates R output, and stops short of deriving the test statistic.
Examples
Tests NBA hustle variables such as deflections, charges, wins, and points per game.
What it assumes
Assumes basic variables and p-values while defining normality, null hypotheses, and significance thresholds.
What you can do after
Diagnose distributional assumptions with base R and decide which variables remain regression candidates.
How it connects
Connects density plots, histograms, p-values, null hypotheses, outliers, and linear regression.

Also explained in

Compare how 2 books explain Shapiro–Wilk test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.