normaltest() combines tests of skewness, asymmetry, and kurtosis, tail heaviness, into a single combined statistic and p-value — a small p-value suggests the data significantly deviates from normality in at least one of those two respects. It requires a reasonably large sample size, the underlying test isn't well-behaved for very small samples, generally recommended for at least 20 observations, to produce reliable results, and like other normality tests, it can flag statistically significant but practically minor deviations for very large datasets.
1Understanding stats.normaltest()
normaltest() combines tests of skewness, asymmetry, and kurtosis, tail heaviness, into a single combined statistic and p-value — a small p-value suggests the data significantly deviates from normality in at least one of those two respects. It requires a reasonably large sample size, the underlying test isn't well-behaved for very small samples, generally recommended for at least 20 observations, to produce reliable results, and like other normality tests, it can flag statistically significant but practically minor deviations for very large datasets.
normaltest() isn't reliable for very small sample sizes, the documentation recommends at least 20 observations — for smaller samples, visual methods, like a Q-Q plot, or other tests better suited to small-sample sizes are more appropriate than trusting normaltest()'s p-value.
from scipy import stats
import numpy as np
np.random.seed(0)
data = np.random.normal(0, 1, 100)
statistic, p_value = stats.normaltest(data)
print(p_value > 0.05)2Practical Example
Here is a real-world application of stats.normaltest() showing how it is used in production SciPy code.
from scipy import stats
import numpy as np
np.random.seed(0)
data = np.random.exponential(1, 100)
statistic, p_value = stats.normaltest(data)
print(p_value > 0.05)3Best Practices
Follow these guidelines when working with stats.normaltest():
1. Ensure a reasonably large sample size, generally at least 20 observations, before relying on normaltest()'s result, since it's not well-behaved for very small samples
2. Combine a formal normality test with a visual check, like a histogram or Q-Q plot, rather than relying purely on a p-value threshold
3. Remember many statistical methods are reasonably robust to mild non-normality — a significant normaltest() result doesn't automatically mean a normality-assuming method can't be used at all
Tip: normaltest() isn't reliable for very small sample sizes, the documentation recommends at least 20 observations — for smaller samples, visual methods, like a Q-Q plot, or other tests better suited to small-sample sizes are more appropriate than trusting normaltest()'s p-value.
from scipy import stats
import numpy as np
np.random.seed(0)
data = np.random.normal(0, 1, 100)
statistic, p_value = stats.normaltest(data)
print(p_value > 0.05)