NORMALTEST
Overview
The NORMALTEST
function tests whether a sample differs from a normal distribution using D’Agostino and Pearson’s omnibus test. This test combines measures of skewness and kurtosis to determine if the data significantly deviates from normality. It is commonly used in statistics to check the normality assumption before applying parametric tests. For more details, see the scipy.stats.normaltest documentation .
This example function is provided as-is without any representation of accuracy.
Usage
To use the function in Excel:
=NORMALTEST(data)
data
(2D list, required): Sample data to test for normality. Must contain at least 8 elements (as a column or row vector).
The function returns a 2D list with two values: the test statistic and the p-value. If the input is invalid, it returns a string error message.
Examples
Example 1: Normal Data
Inputs:
data |
---|
0.1 |
0.2 |
0.0 |
-0.1 |
0.05 |
-0.05 |
0.15 |
-0.2 |
Excel formula:
=NORMALTEST({0.1;0.2;0.0;-0.1;0.05;-0.05;0.15;-0.2})
Expected output:
Statistic | P-value |
---|---|
0.2669 | 0.8751 |
Example 2: Non-Normal Data (Bimodal)
Inputs:
data |
---|
1.0 |
1.1 |
1.2 |
1.3 |
5.0 |
5.1 |
5.2 |
5.3 |
Excel formula:
=NORMALTEST({1.0;1.1;1.2;1.3;5.0;5.1;5.2;5.3})
Expected output:
Statistic | P-value |
---|---|
8.3802 | 0.0151 |
Example 3: Slightly Skewed Data
Inputs:
data |
---|
0.5 |
0.6 |
0.7 |
0.8 |
0.9 |
1.0 |
1.1 |
1.2 |
Excel formula:
=NORMALTEST({0.5;0.6;0.7;0.8;0.9;1.0;1.1;1.2})
Expected output:
Statistic | P-value |
---|---|
0.6787 | 0.7122 |
Example 4: Uniform Data
Inputs:
data |
---|
0.1 |
0.3 |
0.5 |
0.7 |
0.9 |
1.1 |
1.3 |
1.5 |
Excel formula:
=NORMALTEST({0.1;0.3;0.5;0.7;0.9;1.1;1.3;1.5})
Expected output:
Statistic | P-value |
---|---|
0.6787 | 0.7122 |
Python Code
from scipy.stats import normaltest as scipy_normaltest
def normaltest(data):
"""
Test whether a sample differs from a normal distribution (omnibus test).
Args:
data: 2D list. Sample data (must contain at least 8 elements).
Returns:
2D list. Test statistic and p-value, or a string error message if input is invalid.
This example function is provided as-is without any representation of accuracy.
"""
# Validate input is a list
if not isinstance(data, list):
return "Invalid input: data must be a 2D list."
# Flatten if 2D list
try:
flat = []
for row in data:
if isinstance(row, list):
flat.extend(row)
else:
flat.append(row)
arr = [float(x) for x in flat]
except Exception:
return "Invalid input: data must be numeric."
if len(arr) < 8:
return "Invalid input: data must contain at least 8 elements."
try:
stat, pval = scipy_normaltest(arr)
except Exception as e:
return f"scipy.stats.normaltest error: {e}"
# Check for nan/inf
if any([x is None or isinstance(x, str) for x in [stat, pval]]):
return "Invalid output: statistic or p-value is not a number."
if hasattr(stat, 'tolist'):
stat = float(stat)
if hasattr(pval, 'tolist'):
pval = float(pval)
if not (isinstance(stat, (int, float)) and isinstance(pval, (int, float))):
return "Invalid output: statistic or p-value is not a number."
if stat != stat or pval != pval or stat == float('inf') or pval == float('inf') or stat == float('-inf') or pval == float('-inf'):
return "Invalid output: statistic or p-value is nan or inf."
return [[stat, pval]]