Normality tests are based on skewness and kurtosis.
The normaltest()
function returns the p-value for the null hypothesis:
“X comes from a normal distribution.”
Skewness measures the symmetry of data.
For normal distributions, the skewness is 0.
A negative skew indicates the data is skewed to the left, while a positive skew indicates the data is skewed to the right.
Kurtosis measures whether the data is heavy-tailed or lightly-tailed compared to a normal distribution.
Positive kurtosis indicates heavy tails, while negative kurtosis indicates light tails.
Calculate the skewness and kurtosis of the values in an array.
import numpy as np from scipy.stats import skew, kurtosis v = np.random.normal(size=100) print(skew(v)) print(kurtosis(v)) |
0.11168446328610283 -0.1879320563260931 |
Determine if the data follows a normal distribution.
import numpy as np from scipy.stats import normaltest v = np.random.normal(size=100) print(normaltest(v)) |
NormaltestResult(statistic=4.4783745697002848, pvalue=0.10654505998635538) |