chiSquaredNormalityTest¶
Performs a chi-squared test for normality.
Synopsis¶
chiSquaredNormalityTest (nCategories, x)
Required Arguments¶
- int
nCategories
(Input) - Number of cells into which the observations are to be tallied.
nCategories
must be at least 2. - float
x[]
(Input) - Array of size
nObservations
containing the observations.
Return Value¶
The p-value for the chi-squared test for normality. An approximate probability is computed.
Optional Arguments¶
chiSquared
(Output)- If specified, the chi-squared test statistic is returned in
chiSquared
. degreesOfFreedom
(Output)- If specified, the degrees of freedom for the chi-squared goodness-of-fit
test is returned in
degreesOfFreedom
.
Description¶
This function computes the chi-squared statistic, its p-value, and the
degrees of freedom of the test. Argument nCategories
finds the number of
intervals into which the observations are to be divided. The intervals are
equiprobable except for the first and last interval, which are infinite in
length.
If more flexibility is desired for the specification of intervals, the same test can be performed with a call to function chiSquaredTest using the optional arguments described for that function.
Example¶
This example is taken from Conover (1980, pp. 195, 364). The data consists
of 50 two-digit numbers taken from a telephone book. Since pValue
is
greater than 0.1 the chi-squared test fails to reject the null hypothesis of
normality.
from __future__ import print_function
from numpy import *
from pyimsl.stat.chiSquaredNormalityTest import chiSquaredNormalityTest
n_categories = 6
x = [23.0, 36.0, 54.0, 61.0, 73.0, 23.0,
37.0, 54.0, 61.0, 73.0, 24.0, 40.0,
56.0, 62.0, 74.0, 27.0, 42.0, 57.0,
63.0, 75.0, 29.0, 43.0, 57.0, 64.0,
77.0, 31.0, 43.0, 58.0, 65.0, 81.0,
32.0, 44.0, 58.0, 66.0, 87.0, 33.0,
45.0, 58.0, 68.0, 89.0, 33.0, 48.0,
58.0, 68.0, 93.0, 35.0, 48.0, 59.0,
70.0, 97.0]
df = []
chi_squared = []
# ChiSquared test
p_value = chiSquaredNormalityTest(n_categories, x,
degreesOfFreedom=df,
chiSquared=chi_squared)
print("p-value = %11.4f" % (p_value))
print("Degrees of freedom = %11.4f" % (df[0]))
print("Chi squared test = %11.4f" % (chi_squared[0]))
Output¶
p-value = 0.4208
Degrees of freedom = 5.0000
Chi squared test = 4.9600