PearsonChiSquareTest[data]
tests whether data is normally distributed using the Pearson
test.
PearsonChiSquareTest[data,dist]
tests whether data is distributed according to dist using the Pearson
test.
PearsonChiSquareTest[data,dist,"property"]
returns the value of "property".
PearsonChiSquareTest
PearsonChiSquareTest[data]
tests whether data is normally distributed using the Pearson
test.
PearsonChiSquareTest[data,dist]
tests whether data is distributed according to dist using the Pearson
test.
PearsonChiSquareTest[data,dist,"property"]
returns the value of "property".
Details and Options
- PearsonChiSquareTest performs the Pearson
goodness-of-fit test with null hypothesis
that data was drawn from a population with distribution dist, and alternative hypothesis
that it was not. - By default, a probability value or
-value is returned. - A small
-value suggests that it is unlikely that the data came from dist. - The dist can be any symbolic distribution with numeric and symbolic parameters or a dataset.
- The data can be univariate {x1,x2,…} or multivariate {{x1,y1,…},{x2,y2,…},…}.
- The Pearson
test effectively compares a histogram of data to a theoretical histogram based on dist. The bins are chosen to have equal probability in dist. » - For univariate data, the test statistic is given by
, where
and
are the observed and expected counts for the 
histogram bin, respectively. - For multivariate tests, the sum of the univariate marginal
-values is used and is assumed to follow a UniformSumDistribution under
. - PearsonChiSquareTest[data,dist,"HypothesisTestData"] returns a HypothesisTestData object htd that can be used to extract additional test results and properties using the form htd["property"].
- PearsonChiSquareTest[data,dist,"property"] can be used to directly give the value of "property".
- Properties related to the reporting of test results include:
-
"DegreesOfFreedom" the degrees of freedom used in a test "PValue"
-value"PValueTable" formatted version of "PValue" "ShortTestConclusion" a short description of the conclusion of a test "TestConclusion" a description of the conclusion of a test "TestData" test statistic and
-value"TestDataTable" formatted version of "TestData" "TestStatistic" test statistic "TestStatisticTable" formatted "TestStatistic" - The following properties are independent of which test is being performed.
- Properties related to the data distribution include:
-
"FittedDistribution" fitted distribution of data "FittedDistributionParameters" distribution parameters of data - The following options can be given:
-
Method Automatic the method to use for computing
-valuesSignificanceLevel 0.05 cutoff for diagnostics and reporting - For a test for goodness of fit, a cutoff
is chosen such that
is rejected only if
. The value of
used for the "TestConclusion" and "ShortTestConclusion" properties is controlled by the SignificanceLevel option. By default,
is set to 0.05. - With the setting Method->"MonteCarlo",
datasets of the same length as the input
are generated under
using the fitted distribution. The EmpiricalDistribution from PearsonChiSquareTest[si,dist,"TestStatistic"] is then used to estimate the
-value.
Examples
open all close allBasic Examples (4)
Perform the Pearson
test for normality:
data = RandomVariate[NormalDistribution[], 10^4];PearsonChiSquareTest[data]Test the fit of some data to a particular distribution:
data = RandomVariate[LaplaceDistribution[1, 2], 10^3];PearsonChiSquareTest[data, LaplaceDistribution[1, 2]]Compare the distributions of two datasets:
data1 = RandomVariate[NormalDistribution[], 100];data2 = RandomVariate[NormalDistribution[], 150];PearsonChiSquareTest[data1, data2]Extract the test statistic from the Pearson
test:
data = RandomVariate[NormalDistribution[], 10^3];PearsonChiSquareTest[data, NormalDistribution[], "TestStatistic"]Scope (9)
Testing (6)
Perform a Pearson
test for normality:
data1 = RandomVariate[NormalDistribution[], 10^4];
data2 = RandomVariate[StudentTDistribution[3], 10^4];The
-value for the normal data is large compared to the
-value for the non-normal data:
PearsonChiSquareTest[data1]PearsonChiSquareTest[data2]Test the goodness of fit to a particular distribution:
data1 = RandomVariate[NormalDistribution[], 10^3];
data2 = RandomVariate[CauchyDistribution[0, 1], 10^3];PearsonChiSquareTest[data1, CauchyDistribution[0, 1]]PearsonChiSquareTest[data2, CauchyDistribution[0, 1]]Compare the distributions of two datasets:
data1 = RandomVariate[NormalDistribution[], 10^3];
data2 = RandomVariate[NormalDistribution[], 10^3];PearsonChiSquareTest[data1, data2]The two datasets do not have the same distribution:
data3 = RandomVariate[NormalDistribution[0, 1.25], 10^3];PearsonChiSquareTest[data1, data3]Test for multivariate normality:
data1 = RandomVariate[BinormalDistribution[.5], 10^3];
data2 = RandomVariate[LaplaceDistribution[1, 2], {10^3, 2}];PearsonChiSquareTest[data1]PearsonChiSquareTest[data2]Test for goodness of fit to any multivariate distribution:
data1 = RandomVariate[BinormalDistribution[.5], 10^3];
data2 = RandomVariate[𝒹 = LaplaceDistribution[1, 2], {10^3, 2}];𝒟 = ProductDistribution[𝒹, 𝒹];PearsonChiSquareTest[data1, 𝒟]PearsonChiSquareTest[data2, 𝒟]Create a HypothesisTestData object for repeated property extraction:
data = RandomVariate[NormalDistribution[], 10^5];ℋ = PearsonChiSquareTest[data, Automatic, "HypothesisTestData"]The properties available for extraction:
ℋ["Properties"]Reporting (3)
Tabulate the results of the Pearson
test:
data = RandomVariate[NormalDistribution[], 100];ℋ = PearsonChiSquareTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]ℋ["PValueTable"]ℋ["TestStatisticTable"]Retrieve the entries from a Pearson
test table for custom reporting:
data1 = RandomVariate[NormalDistribution[], 100];
data2 = RandomVariate[NormalDistribution[], 100];ℋ1 = PearsonChiSquareTest[data1, Automatic, "TestStatistic"]ℋ2 = PearsonChiSquareTest[data2, Automatic, "TestStatistic"]BarChart[{Labeled[ℋ1, "Set 1"], Labeled[ℋ2, "Set 2"]}]Report test conclusions using "ShortTestConclusion" and "TestConclusion":
data = BlockRandom[SeedRandom[1];RandomVariate[ParetoDistribution[1.05, 2], 100]];ℋ = PearsonChiSquareTest[data, ParetoDistribution[1, 2], "HypothesisTestData"];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormThe conclusion may differ at a different significance level:
ℋ = PearsonChiSquareTest[data, ParetoDistribution[1, 2], "HypothesisTestData", SignificanceLevel -> .001];ℋ["ShortTestConclusion"]ℋ["TestConclusion"]//TraditionalFormOptions (3)
Method (3)
Use Monte Carlo-based methods or a computation formula:
data = RandomVariate[NormalDistribution[], 100];PearsonChiSquareTest[data, NormalDistribution[], Method -> "MonteCarlo"]PearsonChiSquareTest[data, NormalDistribution[], Method -> Automatic]Set the number of samples to use for Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, PearsonChiSquareTest[data, NormalDistribution[], Method -> {"MonteCarlo", "MonteCarloSamples" -> i}]}, {i, Range[5, 100, 5]}];The Monte Carlo estimate converges to the true
-value with increasing samples:
pval = PearsonChiSquareTest[data, NormalDistribution[]];Show[ListLinePlot[pts, PlotRange -> {0, 1}, FrameLabel -> {"Samples", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {100, pval}}]}]]Set the random seed used in Monte Carlo-based methods:
data = RandomVariate[NormalDistribution[], 100];pts = Table[{i, PearsonChiSquareTest[data, NormalDistribution[], Method -> {"MonteCarlo", "RandomSeed" -> i, "MonteCarloSamples" -> 50}]}, {i, Range[1, 10]}];The seed affects the state of the generator and has some effect on the resulting
-value:
pval = PearsonChiSquareTest[data, NormalDistribution[]];Show[ListLinePlot[pts, PlotRange -> {Min[pts[[All, 2]]], Max[pts[[All, 2]]]}, FrameLabel -> {"Seed", "P-Value"}, Frame -> True, AxesOrigin -> {0, 0}], Graphics[{Dashed, Line[{{0, pval}, {10, pval}}]}]]Applications (2)
A power curve for the Pearson
test:
data = Table[RandomVariate[UniformDistribution[{-4, 4}], {500, i}], {i, n = {5, 7, 10, 15, 20, 25, 30}}];ℋ = Table[PearsonChiSquareTest[data[[i, j]], NormalDistribution[]], {i, Length[data]}, {j, Length[data[[i]]]}];pC = Interpolation[Transpose[{n, Table[Probability[x ≤ 0.05, xi], {i, ℋ}]}], InterpolationOrder -> 1];Visualize the approximate power curve:
Plot[pC[x], {x, 5, 30}, PlotRange -> {0, 1}, Ticks -> {n, Automatic}, AxesOrigin -> {0, 0}]Estimate the power of the Pearson
test when the underlying distribution is UniformDistribution[{-4,4}], the test size is 0.05, and the sample size is 12:
pC[12.]The number of auto accidents was recorded for a city over the course of 30 days. The city council is planning on lowering speed limits in the city and wants a model of the accident rate as a baseline for later comparison:
auto30 = {98, 90, 111, 91, 107, 103, 109, 122, 95, 112, 114, 97, 101, 118, 96, 102, 101, 107, 116, 97, 89, 108, 96, 105, 108, 114, 91, 98, 87, 87};μ1 = Mean[auto30]//NCount data is often modeled well by PoissonDistribution:
PearsonChiSquareTest[auto30, PoissonDistribution[μ1], "TestDataTable"]Suppose the city collected data over another 30-day period after reducing the speed limit. Compare the distributions before and after the reduction:
newData = {83, 84, 85, 80, 76, 91, 96, 101, 93, 84, 75, 89, 94, 91, 96, 84, 74, 102, 86, 97, 84, 80, 89, 92, 84, 98, 84, 93, 92, 81};μ2 = Mean[newData]//NHistogram[{auto30, newData}, ChartStyle -> {Red, Blue}]The distributions are significantly different:
PearsonChiSquareTest[auto30, newData, "TestDataTable"]Properties & Relations (10)
By default, univariate data is compared to NormalDistribution:
data = RandomVariate[NormalDistribution[2, 3], 10^4];ℋ = PearsonChiSquareTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]The parameters have been estimated from the data:
ℋ["FittedDistribution"]Multivariate data is compared to MultinormalDistribution by default:
data = RandomVariate[MultinormalDistribution[{1, 2, 3}, IdentityMatrix[3]], 1000];ℋ = PearsonChiSquareTest[data, Automatic, "HypothesisTestData"];ℋ["TestDataTable"]ℋ["FittedDistribution"]//TraditionalFormThe parameters of the test distribution are estimated from the data if not specified:
data = RandomVariate[NormalDistribution[1, 2], 1000];PearsonChiSquareTest[data, NormalDistribution[μ, σ], "FittedDistribution"]Specified parameters are not estimated:
PearsonChiSquareTest[data, NormalDistribution[μ, 2], "FittedDistribution"]PearsonChiSquareTest[data, NormalDistribution[1, 2], "FittedDistribution"]Maximum likelihood estimates are used for unspecified parameters of the test distribution:
data = RandomVariate[ExponentialDistribution[3], 10^3];ℋ = PearsonChiSquareTest[data, ExponentialDistribution[λ], "FittedDistribution"]PearsonChiSquareTest[data, ExponentialDistribution[λ]]PearsonChiSquareTest effectively compares the observed and expected histograms:
n = 10^4;data = RandomVariate[NormalDistribution[3, 4], n];The data is binned into approximately
bins that are equiprobable under
:
nbins = 2n^2 / 5//CeilingbDelim = Quantile[NormalDistribution[3, 4], Range[0., 1, 1 / nbins]];Under
, each bin will contain an equal number of points:
Histogram[Quantile[NormalDistribution[3, 4], Range[0., 1, 1 / 10^4]], {Most@Rest@bDelim}, PlotLabel -> "Expected"]Observed histograms for when
is true and false, respectively:
{Histogram[data, {Most@Rest@bDelim}, PlotLabel -> "SubscriptBox[H, 0] -> True"], Histogram[RandomVariate[CauchyDistribution[0, 1], 10^4], {Most@Rest@bDelim}, PlotLabel -> "SubscriptBox[H, 0] -> False"]}The degrees of freedom are equal to the number of non-empty bins minus one:
n = 10^4;data = RandomVariate[NormalDistribution[3, 4], n];nbins = 2n^2 / 5//Ceilingdf = nbins - 1PearsonChiSquareTest[data, NormalDistribution[3, 4], "DegreesOfFreedom"]One degree of freedom is removed for each parameter that is estimated from the data:
PearsonChiSquareTest[data, NormalDistribution[a, 4], "DegreesOfFreedom"]PearsonChiSquareTest[data, NormalDistribution[a, b], "DegreesOfFreedom"]If the parameters are unknown, PearsonChiSquareTest corrects the degrees of freedom:
data = RandomVariate[NormalDistribution[3, 4], 10^4];est = EstimatedDistribution[data, NormalDistribution[μ, σ]]No correction is applied when the parameters are specified:
PearsonChiSquareTest[data, est, {"PValue", "DegreesOfFreedom"}]ℋ = PearsonChiSquareTest[data, NormalDistribution[μ, σ], "HypothesisTestData"];The fitted distribution is equivalent, but the degrees of freedom and
-value are corrected:
ℋ["FittedDistribution"]ℋ["PValue", "DegreesOfFreedom"]The Pearson
statistic asymptotically follows ChiSquareDistribution under
:
data = RandomVariate[NormalDistribution[], {250, 1000}];t = Table[PearsonChiSquareTest[i, NormalDistribution[], "TestStatistic"], {i, data}];edist = EstimatedDistribution[t, ChiSquareDistribution[ν]];Show[Histogram[t, Automatic, "ProbabilityDensity"], Plot[PDF[edist, x], {x, 0, 60}, PlotRange -> All]]DistributionFitTest[t, ChiSquareDistribution[ν], "TestDataTable"]DistributionFitTest[t, ChiSquareDistribution[ν], "ShortTestConclusion"]Independent marginal densities are assumed in tests for multivariate goodness of fit:
data = RandomVariate[MultinormalDistribution[{0, 0}, {{0.118, 0.252}, {0.252, 0.665}}], 100];PearsonChiSquareTest[data, MultinormalDistribution[{0, 0}, {{0.118, 0.252}, {0.252, 0.665}}], "TestStatistic"]The test statistic is identical when independence is assumed:
PearsonChiSquareTest[data, MultinormalDistribution[{0, 0}, {{0.118, 0}, {0, 0.665}}], "TestStatistic"]The Pearson
test works with the values only when the input is a TimeSeries:
ts = TemporalData[TimeSeries, {{{1.224578634529677, 0.47929635789978015, 0.6572781300178168,
0.21496048742669355, 0.7299608014554928, -0.2495111111278263, -1.3286551762002712,
0.552725018274874, 0.19272112205837066, 1.1809144012420882, -1.1671 ... 40938613662046, 1.052394590214582, 0.9345044123980388, 0.38537803109557855,
-0.48660931166089394, -0.71203560340161}}, {{0, 100, 1}}, 1, {"Continuous", 1},
{"Discrete", 1}, 1, {ValueDimensions -> 1, ResamplingMethod -> None}}, False, 10.1];PearsonChiSquareTest[ts]PearsonChiSquareTest[ts["Values"]]Neat Examples (1)
Compute the statistic when the null hypothesis
is true:
data = RandomVariate[NormalDistribution[], {2500, 100}];T1 = PearsonChiSquareTest[#, NormalDistribution[], "TestStatistic"]& /@ data;The test statistic given a particular alternative:
T2 = PearsonChiSquareTest[#, NormalDistribution[1, 2], "TestStatistic"]& /@ data;Compare the distributions of the test statistics:
SmoothHistogram[{T1, T2}, Filling -> Axis, PlotLegends -> {"SubscriptBox[H, 0] is True", "SubscriptBox[H, 0] is False"}, PlotStyle -> Thick]Related Guides
History
Text
Wolfram Research (2010), PearsonChiSquareTest, Wolfram Language function, https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html.
CMS
Wolfram Language. 2010. "PearsonChiSquareTest." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html.
APA
Wolfram Language. (2010). PearsonChiSquareTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html
BibTeX
@misc{reference.wolfram_2026_pearsonchisquaretest, author="Wolfram Research", title="{PearsonChiSquareTest}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_pearsonchisquaretest, organization={Wolfram Research}, title={PearsonChiSquareTest}, year={2010}, url={https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html}, note=[Accessed: 13-June-2026]}