🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEscipy

scipy Documentation

LOADING ENGINE...

stats.normaltest()

AI & DATA SCIENCE // stats-normaltest

scipy.stats.normaltest() tests whether a sample of data significantly deviates from a normal distribution, based on its skewness and kurtosis.

Syntax

scipy.stats.normaltest(a)

Deep Dive Course

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.

editor.html
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)
localhost:3000

2Practical Example

Here is a real-world application of stats.normaltest() showing how it is used in production SciPy code.

editor.html
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)
localhost:3000

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.

editor.html
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)
localhost:3000

Examples

Example 01Basic Usage
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)
Example 02Advanced Example
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)

Best Practices

  • 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
  • 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
  • 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

Interview Question

Why does scipy.stats.normaltest() specifically require a reasonably large sample size to give a reliable result?

Hint: Think about what statistics, skewness and kurtosis, the test relies on, and how reliably those can be estimated from very few data points.

normaltest() bases its result on the sample's estimated skewness and kurtosis, both of which are themselves statistics computed from the data and therefore have their own sampling variability — with very few data points, those estimates can be wildly unreliable and unrepresentative of the true underlying distribution's actual shape, purely due to random sampling noise. With too small a sample, the test can't reliably distinguish genuine non-normality from noisy skewness/kurtosis estimates that would look unusual even for data that's genuinely normally distributed, which is exactly why the test's documentation recommends a reasonably large sample size, generally at least 20 observations, before trusting its result.

Exercises

MediumPractice using stats.normaltest() in a real scenario.
View Solution
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)

Frequently Asked Questions

Why does scipy.stats.normaltest() specifically require a reasonably large sample size to give a reliable result?

normaltest() bases its result on the sample's estimated skewness and kurtosis, both of which are themselves statistics computed from the data and therefore have their own sampling variability — with very few data points, those estimates can be wildly unreliable and unrepresentative of the true underlying distribution's actual shape, purely due to random sampling noise. With too small a sample, the test can't reliably distinguish genuine non-normality from noisy skewness/kurtosis estimates that would look unusual even for data that's genuinely normally distributed, which is exactly why the test's documentation recommends a reasonably large sample size, generally at least 20 observations, before trusting its result.

Related Functions

stats-ksteststats-normnp-random-normal