PearsonChiSquareTest
✖
PearsonChiSquareTest
tests whether data is distributed according to dist using the Pearson test.
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 -values
SignificanceLevel 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 allclose allBasic Examples (4)Summary of the most common use cases
Perform the Pearson test for normality:

https://wolfram.com/xid/0dbjf29egf0adulmli-e2z9oi

https://wolfram.com/xid/0dbjf29egf0adulmli-b6snhw

Test the fit of some data to a particular distribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-erxs41

https://wolfram.com/xid/0dbjf29egf0adulmli-dofsl4

Compare the distributions of two datasets:

https://wolfram.com/xid/0dbjf29egf0adulmli-b8s07g

https://wolfram.com/xid/0dbjf29egf0adulmli-ckwifh

https://wolfram.com/xid/0dbjf29egf0adulmli-ht6wkq

Extract the test statistic from the Pearson test:

https://wolfram.com/xid/0dbjf29egf0adulmli-m3chh3

https://wolfram.com/xid/0dbjf29egf0adulmli-cm7ucc

Scope (9)Survey of the scope of standard use cases
Testing (6)
Perform a Pearson test for normality:

https://wolfram.com/xid/0dbjf29egf0adulmli-lqxbgq
The -value for the normal data is large compared to the
-value for the non-normal data:

https://wolfram.com/xid/0dbjf29egf0adulmli-mks25


https://wolfram.com/xid/0dbjf29egf0adulmli-kjd2s

Test the goodness of fit to a particular distribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-budcm8

https://wolfram.com/xid/0dbjf29egf0adulmli-dtqxca


https://wolfram.com/xid/0dbjf29egf0adulmli-ci5vf

Compare the distributions of two datasets:

https://wolfram.com/xid/0dbjf29egf0adulmli-f1whrm

https://wolfram.com/xid/0dbjf29egf0adulmli-2qof

The two datasets do not have the same distribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-inhd0f

https://wolfram.com/xid/0dbjf29egf0adulmli-bbarau

Test for multivariate normality:

https://wolfram.com/xid/0dbjf29egf0adulmli-67n6h

https://wolfram.com/xid/0dbjf29egf0adulmli-eooal3


https://wolfram.com/xid/0dbjf29egf0adulmli-cn5yan

Test for goodness of fit to any multivariate distribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-gtwavq

https://wolfram.com/xid/0dbjf29egf0adulmli-n3thk6

https://wolfram.com/xid/0dbjf29egf0adulmli-hlhupv


https://wolfram.com/xid/0dbjf29egf0adulmli-ut5c

Create a HypothesisTestData object for repeated property extraction:

https://wolfram.com/xid/0dbjf29egf0adulmli-cdnr2n

https://wolfram.com/xid/0dbjf29egf0adulmli-bolz27

The properties available for extraction:

https://wolfram.com/xid/0dbjf29egf0adulmli-e40fsc

Reporting (3)
Tabulate the results of the Pearson test:

https://wolfram.com/xid/0dbjf29egf0adulmli-cqxopz

https://wolfram.com/xid/0dbjf29egf0adulmli-be6kk1

https://wolfram.com/xid/0dbjf29egf0adulmli-ef4et7


https://wolfram.com/xid/0dbjf29egf0adulmli-bfqugt


https://wolfram.com/xid/0dbjf29egf0adulmli-oi9r56

Retrieve the entries from a Pearson test table for custom reporting:

https://wolfram.com/xid/0dbjf29egf0adulmli-s3qsd

https://wolfram.com/xid/0dbjf29egf0adulmli-ga3bij


https://wolfram.com/xid/0dbjf29egf0adulmli-gg2n22


https://wolfram.com/xid/0dbjf29egf0adulmli-65k71

Report test conclusions using "ShortTestConclusion" and "TestConclusion":

https://wolfram.com/xid/0dbjf29egf0adulmli-bkir6y

https://wolfram.com/xid/0dbjf29egf0adulmli-cd96sm

https://wolfram.com/xid/0dbjf29egf0adulmli-ggy9zn


https://wolfram.com/xid/0dbjf29egf0adulmli-el9mb

The conclusion may differ at a different significance level:

https://wolfram.com/xid/0dbjf29egf0adulmli-c53cri

https://wolfram.com/xid/0dbjf29egf0adulmli-byyexa


https://wolfram.com/xid/0dbjf29egf0adulmli-bc67bi

Options (3)Common values & functionality for each option
Method (3)
Use Monte Carlo-based methods or a computation formula:

https://wolfram.com/xid/0dbjf29egf0adulmli-b56tvj

https://wolfram.com/xid/0dbjf29egf0adulmli-eyrfe


https://wolfram.com/xid/0dbjf29egf0adulmli-evuhgg

Set the number of samples to use for Monte Carlo-based methods:

https://wolfram.com/xid/0dbjf29egf0adulmli-xg6xc

https://wolfram.com/xid/0dbjf29egf0adulmli-499mh
The Monte Carlo estimate converges to the true -value with increasing samples:

https://wolfram.com/xid/0dbjf29egf0adulmli-eli8sg

https://wolfram.com/xid/0dbjf29egf0adulmli-ba5c5u

Set the random seed used in Monte Carlo-based methods:

https://wolfram.com/xid/0dbjf29egf0adulmli-ccet45

https://wolfram.com/xid/0dbjf29egf0adulmli-ip8pt1
The seed affects the state of the generator and has some effect on the resulting -value:

https://wolfram.com/xid/0dbjf29egf0adulmli-go8plt

https://wolfram.com/xid/0dbjf29egf0adulmli-pfg0ok

Applications (2)Sample problems that can be solved with this function
A power curve for the Pearson test:

https://wolfram.com/xid/0dbjf29egf0adulmli-f9ry9j

https://wolfram.com/xid/0dbjf29egf0adulmli-bhp5v

https://wolfram.com/xid/0dbjf29egf0adulmli-fyqopk
Visualize the approximate power curve:

https://wolfram.com/xid/0dbjf29egf0adulmli-eel2vq

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:

https://wolfram.com/xid/0dbjf29egf0adulmli-z6f7c

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:

https://wolfram.com/xid/0dbjf29egf0adulmli-pvmuv

https://wolfram.com/xid/0dbjf29egf0adulmli-bphwu6

Count data is often modeled well by PoissonDistribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-id8isa

Suppose the city collected data over another 30-day period after reducing the speed limit. Compare the distributions before and after the reduction:

https://wolfram.com/xid/0dbjf29egf0adulmli-gkxnd6

https://wolfram.com/xid/0dbjf29egf0adulmli-c8ii08


https://wolfram.com/xid/0dbjf29egf0adulmli-q0toii

The distributions are significantly different:

https://wolfram.com/xid/0dbjf29egf0adulmli-h7dit2

Properties & Relations (10)Properties of the function, and connections to other functions
By default, univariate data is compared to NormalDistribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-in3dv2

https://wolfram.com/xid/0dbjf29egf0adulmli-loot1k

https://wolfram.com/xid/0dbjf29egf0adulmli-ekgpjw

The parameters have been estimated from the data:

https://wolfram.com/xid/0dbjf29egf0adulmli-f3jfr4

Multivariate data is compared to MultinormalDistribution by default:

https://wolfram.com/xid/0dbjf29egf0adulmli-dhffw

https://wolfram.com/xid/0dbjf29egf0adulmli-cddu5a

https://wolfram.com/xid/0dbjf29egf0adulmli-hpjfy5


https://wolfram.com/xid/0dbjf29egf0adulmli-bstr67

The parameters of the test distribution are estimated from the data if not specified:

https://wolfram.com/xid/0dbjf29egf0adulmli-d47mlh

https://wolfram.com/xid/0dbjf29egf0adulmli-io3pky

Specified parameters are not estimated:

https://wolfram.com/xid/0dbjf29egf0adulmli-hxkimc


https://wolfram.com/xid/0dbjf29egf0adulmli-nx9q2m

Maximum likelihood estimates are used for unspecified parameters of the test distribution:

https://wolfram.com/xid/0dbjf29egf0adulmli-ob999

https://wolfram.com/xid/0dbjf29egf0adulmli-ccvtx8


https://wolfram.com/xid/0dbjf29egf0adulmli-lczwnz

PearsonChiSquareTest effectively compares the observed and expected histograms:

https://wolfram.com/xid/0dbjf29egf0adulmli-tvky4

https://wolfram.com/xid/0dbjf29egf0adulmli-dlds3
The data is binned into approximately bins that are equiprobable under
:

https://wolfram.com/xid/0dbjf29egf0adulmli-gnqlxb


https://wolfram.com/xid/0dbjf29egf0adulmli-foynro
Under , each bin will contain an equal number of points:

https://wolfram.com/xid/0dbjf29egf0adulmli-c5nty4

Observed histograms for when is true and false, respectively:

https://wolfram.com/xid/0dbjf29egf0adulmli-e1yw92

The degrees of freedom are equal to the number of non-empty bins minus one:

https://wolfram.com/xid/0dbjf29egf0adulmli-lnhoig

https://wolfram.com/xid/0dbjf29egf0adulmli-ijz3mx

https://wolfram.com/xid/0dbjf29egf0adulmli-o9xubq


https://wolfram.com/xid/0dbjf29egf0adulmli-d9ictj


https://wolfram.com/xid/0dbjf29egf0adulmli-dl3eb9

One degree of freedom is removed for each parameter that is estimated from the data:

https://wolfram.com/xid/0dbjf29egf0adulmli-f48lz3


https://wolfram.com/xid/0dbjf29egf0adulmli-dmv6le

If the parameters are unknown, PearsonChiSquareTest corrects the degrees of freedom:

https://wolfram.com/xid/0dbjf29egf0adulmli-cyr6pp

https://wolfram.com/xid/0dbjf29egf0adulmli-cdmjix

No correction is applied when the parameters are specified:

https://wolfram.com/xid/0dbjf29egf0adulmli-j8jo0o


https://wolfram.com/xid/0dbjf29egf0adulmli-e87ev
The fitted distribution is equivalent, but the degrees of freedom and -value are corrected:

https://wolfram.com/xid/0dbjf29egf0adulmli-voh29


https://wolfram.com/xid/0dbjf29egf0adulmli-bx464

The Pearson statistic asymptotically follows ChiSquareDistribution under
:

https://wolfram.com/xid/0dbjf29egf0adulmli-goz612

https://wolfram.com/xid/0dbjf29egf0adulmli-pbcxh

https://wolfram.com/xid/0dbjf29egf0adulmli-rlsxq

https://wolfram.com/xid/0dbjf29egf0adulmli-eh38ry


https://wolfram.com/xid/0dbjf29egf0adulmli-duxa4p


https://wolfram.com/xid/0dbjf29egf0adulmli-r7sr0j

Independent marginal densities are assumed in tests for multivariate goodness of fit:

https://wolfram.com/xid/0dbjf29egf0adulmli-et8fgp

https://wolfram.com/xid/0dbjf29egf0adulmli-plqmfp

The test statistic is identical when independence is assumed:

https://wolfram.com/xid/0dbjf29egf0adulmli-fpwagd

The Pearson test works with the values only when the input is a TimeSeries:

https://wolfram.com/xid/0dbjf29egf0adulmli-7py5sj

https://wolfram.com/xid/0dbjf29egf0adulmli-57bf57


https://wolfram.com/xid/0dbjf29egf0adulmli-vvd88

Neat Examples (1)Surprising or curious use cases
Compute the statistic when the null hypothesis is true:

https://wolfram.com/xid/0dbjf29egf0adulmli-2qqg3c

https://wolfram.com/xid/0dbjf29egf0adulmli-ywy3ty
The test statistic given a particular alternative:

https://wolfram.com/xid/0dbjf29egf0adulmli-c5cy2n
Compare the distributions of the test statistics:

https://wolfram.com/xid/0dbjf29egf0adulmli-87eb6q

Wolfram Research (2010), PearsonChiSquareTest, Wolfram Language function, https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html.
Text
Wolfram Research (2010), PearsonChiSquareTest, Wolfram Language function, https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html.
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.
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
Wolfram Language. (2010). PearsonChiSquareTest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html
BibTeX
@misc{reference.wolfram_2025_pearsonchisquaretest, author="Wolfram Research", title="{PearsonChiSquareTest}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html}", note=[Accessed: 22-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_pearsonchisquaretest, organization={Wolfram Research}, title={PearsonChiSquareTest}, year={2010}, url={https://reference.wolfram.com/language/ref/PearsonChiSquareTest.html}, note=[Accessed: 22-April-2025
]}