Shapiro-Wilk Test

Shapiro-Wilk Test

Overview

Definition

Shapiro-Wilk Test checks if data comes from a Normal Distribution. It is one of the most powerful normality tests.

  • H0: Data is Normal.
  • H1: Data is Not Normal.
Sample Size

Best for n<50. For large samples, it is too sensitive (flags minor deviations). Use Q-Q Plots for n>50.


1. Python Implementation

from scipy import stats
stat, p = stats.shapiro(data)

if p < 0.05:
    print("Not Normal (Reject H0)")
else:
    print("Normal (Fail to Reject H0)")

2. R Implementation

# Built-in function
shapiro.test(data)

# If p < 0.05, consider non-parametric tests like Wilcoxon.