Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Pearson's chi-squared test

From Wikipedia, the free encyclopedia
Evaluates how likely it is that any difference between data sets arose by chance
For broader coverage of this topic, seeChi-squared test.

Pearson's chi-squared test orPearson'sχ2{\displaystyle \chi ^{2}} test is astatistical test applied to sets ofcategorical data to evaluate how likely it is that any observed difference between the sets arose by chance. It is the most widely used of manychi-squared tests (e.g.,Yates,likelihood ratio,portmanteau test in time series, etc.) –statistical procedures whose results are evaluated by reference to thechi-squared distribution. Its properties were first investigated byKarl Pearson in 1900.[1] In contexts where it is important to improve a distinction between thetest statistic and its distribution, names similar toPearson χ-squared test or statistic are used.It is ap-value test.

A simple example is testing the hypothesis that an ordinary six-sided die is "fair" (i. e., all six outcomes are equally likely to occur). In this case, the observed data is(O1,O2,...,O6){\displaystyle (O_{1},O_{2},...,O_{6})}, the number of times that the dice has fallen on each number. The null hypothesis isMultinomial(N;1/6,...,1/6){\displaystyle \mathrm {Multinomial} (N;1/6,...,1/6)}, andχ2:=i=16(OiN/6)2N/6{\textstyle \chi ^{2}:=\sum \limits _{i=1}^{6}{\frac {{\left(O_{i}-N/6\right)}^{2}}{N/6}}}. As detailed below, ifχ2>11.07{\displaystyle \chi ^{2}>11.07}, then the fairness of dice can be rejected at the level ofp<0.05{\displaystyle p<0.05}.

Procedure

[edit]

The setup is as follows:[2][3]

Usage

[edit]

Pearson's chi-squared test is used to assess three types of comparison:goodness of fit,homogeneity, andindependence.

  • A test of goodness of fit establishes whether an observedfrequency distribution differs from a theoretical distribution.
  • A test of homogeneity compares the distribution of counts for two or more groups using the same categorical variable (e.g. choice of activity—college, military, employment, travel—of graduates of a high school reported a year after graduation, sorted by graduation year, to see if number of graduates choosing a given activity has changed from class to class, or from decade to decade).[4]
  • A test of independence assesses whether observations consisting of measures on two variables, expressed in acontingency table, are independent of each other (e.g. polling responses from people of different nationalities to see if one's nationality is related to the response).

For all three tests, the computational procedure includes the following steps:

  1. Calculate the chi-squared teststatistic,χ2{\displaystyle \chi ^{2}}, which resembles anormalized sum of squared deviations between observed and theoreticalfrequencies (see below).
  2. Determine thedegrees of freedom,df, of that statistic.
    1. For a test of goodness-of-fit,df = Cats − Params, whereCats is the number of observation categories recognized by the model, andParams is the number of parameters in the model adjusted to make the model best fit the observations: The number of categories reduced by the number of fitted parameters in the distribution.
    2. For a test of homogeneity,df = (Rows − 1)×(Cols − 1), whereRows corresponds to the number of categories (i.e. rows in the associated contingency table), andCols corresponds to the number of independent groups (i.e. columns in the associated contingency table).[4]
    3. For a test of independence,df = (Rows − 1)×(Cols − 1), where in this case,Rows corresponds to the number of categories in one variable, andCols corresponds to the number of categories in the second variable.[4]
  3. Select a desired level of confidence (significance level,p-value, or the correspondingalpha level) for the result of the test.
  4. Compareχ2{\displaystyle \chi ^{2}} to the critical value from thechi-squared distribution withdf degrees of freedom and the selected confidence level (one-sided, since the test is only in one direction, i.e. is the test value greater than the critical value?), which in many cases gives a good approximation of the distribution ofχ2{\displaystyle \chi ^{2}}.
  5. Sustain or reject the null hypothesis that the observed frequency distribution is the same as the theoretical distribution based on whether the test statistic exceeds the critical value ofχ2{\displaystyle \chi ^{2}}. If the test statistic exceeds the critical value ofχ2{\displaystyle \chi ^{2}}, the null hypothesis (H0{\displaystyle H_{0}} = there isno difference between the distributions) can be rejected, and the alternative hypothesis (H1{\displaystyle H_{1}} = thereis a difference between the distributions) can be accepted, both with the selected level of confidence. If the test statistic falls below the thresholdχ2{\displaystyle \chi ^{2}} value, then no clear conclusion can be reached, and the null hypothesis is sustained (we fail to reject the null hypothesis), though not necessarily accepted.

Test for fit of a distribution

[edit]

Discrete uniform distribution

[edit]

In this caseN{\displaystyle N} observations are divided amongn{\displaystyle n} cells. A simple application is to test the hypothesis that, in the general population, values would occur in each cell with equal frequency. The "theoretical frequency" for any cell (under the null hypothesis of adiscrete uniform distribution) is thus calculated asEi=Nn,{\displaystyle E_{i}={\frac {N}{n}}\,,}and the reduction in the degrees of freedom isp=1{\displaystyle p=1}, notionally because the observed frequenciesOi{\displaystyle O_{i}} are constrained to sum toN{\displaystyle N}.

One specific example of its application would be its application for log-rank test.

Other distributions

[edit]

When testing whether observations are random variables whose distribution belongs to a given family of distributions, the "theoretical frequencies" are calculated using a distribution from that family fitted in some standard way. The reduction in the degrees of freedom is calculated asp=s+1{\displaystyle p=s+1}, wheres{\displaystyle s} is the number of parameters used in fitting the distribution. For instance, when checking a three-parameterGeneralized gamma distribution,p=4{\displaystyle p=4}, and when checking a normal distribution (where the parameters are mean and standard deviation),p=3{\displaystyle p=3}, and when checking a Poisson distribution (where the parameter is the expected value),p=2{\displaystyle p=2}. Thus, there will benp{\displaystyle n-p} degrees of freedom, wheren{\displaystyle n} is the number of categories.

The degrees of freedom are not based on the number of observations as with aStudent's t orF-distribution. For example, if testing for a fair, six-sided die, there would be five degrees of freedom because there are six categories or parameters (each number); the number of times the die is rolled does not influence the number of degrees of freedom.

Calculating the test-statistic

[edit]
Chi-squared distribution, showingX2 on the x-axis and P-value on the y-axis.
Upper-tail critical values of chi-square distribution[5]
Degrees
of
freedom
Probability less than the critical value
0.900.950.9750.990.999
12.7063.8415.0246.63510.828
24.6055.9917.3789.21013.816
36.2517.8159.34811.34516.266
47.7799.48811.14313.27718.467
59.23611.07012.83315.08620.515
610.64512.59214.44916.81222.458
712.01714.06716.01318.47524.322
813.36215.50717.53520.09026.125
914.68416.91919.02321.66627.877
1015.98718.30720.48323.20929.588
1117.27519.67521.92024.72531.264
1218.54921.02623.33726.21732.910
1319.81222.36224.73627.68834.528
1421.06423.68526.11929.14136.123
1522.30724.99627.48830.57837.697
1623.54226.29628.84532.00039.252
1724.76927.58730.19133.40940.790
1825.98928.86931.52634.80542.312
1927.20430.14432.85236.19143.820
2028.41231.41034.17037.56645.315
2129.61532.67135.47938.93246.797
2230.81333.92436.78140.28948.268
2332.00735.17238.07641.63849.728
2433.19636.41539.36442.98051.179
2534.38237.65240.64644.31452.620
2635.56338.88541.92345.64254.052
2736.74140.11343.19546.96355.476
2837.91641.33744.46148.27856.892
2939.08742.55745.72249.58858.301
3040.25643.77346.97950.89259.703
3141.42244.98548.23252.19161.098
3242.58546.19449.48053.48662.487
3343.74547.40050.72554.77663.870
3444.90348.60251.96656.06165.247
3546.05949.80253.20357.34266.619
3647.21250.99854.43758.61967.985
3748.36352.19255.66859.89369.347
3849.51353.38456.89661.16270.703
3950.66054.57258.12062.42872.055
4051.80555.75859.34263.69173.402
4152.94956.94260.56164.95074.745
4254.09058.12461.77766.20676.084
4355.23059.30462.99067.45977.419
4456.36960.48164.20168.71078.750
4557.50561.65665.41069.95780.077
4658.64162.83066.61771.20181.400
4759.77464.00167.82172.44382.720
4860.90765.17169.02373.68384.037
4962.03866.33970.22274.91985.351
5063.16767.50571.42076.15486.661
5164.29568.66972.61677.38687.968
5265.42269.83273.81078.61689.272
5366.54870.99375.00279.84390.573
5467.67372.15376.19281.06991.872
5568.79673.31177.38082.29293.168
5669.91974.46878.56783.51394.461
5771.04075.62479.75284.73395.751
5872.16076.77880.93685.95097.039
5973.27977.93182.11787.16698.324
6074.39779.08283.29888.37999.607
6175.51480.23284.47689.591100.888
6276.63081.38185.65490.802102.166
6377.74582.52986.83092.010103.442
6478.86083.67588.00493.217104.716
6579.97384.82189.17794.422105.988
6681.08585.96590.34995.626107.258
6782.19787.10891.51996.828108.526
6883.30888.25092.68998.028109.791
6984.41889.39193.85699.228111.055
7085.52790.53195.023100.425112.317
7186.63591.67096.189101.621113.577
7287.74392.80897.353102.816114.835
7388.85093.94598.516104.010116.092
7489.95695.08199.678105.202117.346
7591.06196.217100.839106.393118.599
7692.16697.351101.999107.583119.850
7793.27098.484103.158108.771121.100
7894.37499.617104.316109.958122.348
7995.476100.749105.473111.144123.594
8096.578101.879106.629112.329124.839
8197.680103.010107.783113.512126.083
8298.780104.139108.937114.695127.324
8399.880105.267110.090115.876128.565
84100.980106.395111.242117.057129.804
85102.079107.522112.393118.236131.041
86103.177108.648113.544119.414132.277
87104.275109.773114.693120.591133.512
88105.372110.898115.841121.767134.746
89106.469112.022116.989122.942135.978
90107.565113.145118.136124.116137.208
91108.661114.268119.282125.289138.438
92109.756115.390120.427126.462139.666
93110.850116.511121.571127.633140.893
94111.944117.632122.715128.803142.119
95113.038118.752123.858129.973143.344
96114.131119.871125.000131.141144.567
97115.223120.990126.141132.309145.789
98116.315122.108127.282133.476147.010
99117.407123.225128.422134.642148.230
100118.498124.342129.561135.807149.449

The value of the test-statistic is

χ2=i=1n(OiEi)2Ei=Ni=1n(Oi/Npi)2pi{\displaystyle \chi ^{2}=\sum _{i=1}^{n}{\frac {{\left(O_{i}-E_{i}\right)}^{2}}{E_{i}}}=N\sum _{i=1}^{n}{\frac {\left(O_{i}/N-p_{i}\right)^{2}}{p_{i}}}}

where

The chi-squared statistic can then be used to calculate ap-value bycomparing the value of the statistic to achi-squared distribution. The number ofdegrees of freedom is equal to the number of cellsn{\displaystyle n}, minus the reduction in degrees of freedom,p{\displaystyle p}.

The chi-squared statistic can be also calculated as

χ2=i=1nOi2EiN.{\displaystyle \chi ^{2}=\sum _{i=1}^{n}{\frac {O_{i}^{2}}{E_{i}}}-N.}

This result is the consequence of the Binomial theorem.

The result about the numbers of degrees of freedom is valid when the original data are multinomial and hence the estimated parameters are efficient for minimizing the chi-squared statistic. More generally however, when maximum likelihood estimation does not coincide with minimum chi-squared estimation, the distribution will lie somewhere between a chi-squared distribution withn1p{\displaystyle n-1-p} andn1{\displaystyle n-1} degrees of freedom (See for instance Chernoff and Lehmann, 1954).

The chi-squared test indicates a statistically significant association between the level of education completed and routine check-up attendance (chi2(3) = 14.6090, p = 0.002). The proportions suggest that as the level of education increases, so does the proportion of individuals attending routine check-ups. Specifically, individuals who have graduated from college or university attend routine check-ups at a higher proportion (31.52%) compared to those who have not graduated high school (8.44%). This finding may suggest that higher educational attainment is associated with a greater likelihood of engaging in health-promoting behaviors such as routine check-ups.

Bayesian method

[edit]
Further information:Categorical distribution § Bayesian inference using conjugate prior

InBayesian statistics, one would instead use aDirichlet distribution asconjugate prior. If one took a uniform prior, then themaximum likelihood estimate for the population probability is the observed probability, and one may compute acredible region around this or another estimate.

Testing for statistical independence

[edit]

In this case, an "observation" consists of the values of two outcomes and the null hypothesis is that the occurrence of these outcomes isstatistically independent. Each observation is allocated to one cell of a two-dimensional array of cells (called acontingency table) according to the values of the two outcomes. If there arer rows andc columns in the table, the "theoretical frequency" for a cell, given the hypothesis of independence, is

Ei,j=Npipj,{\displaystyle E_{i,j}=Np_{i\cdot }p_{\cdot j},}

whereN{\displaystyle N} is the total sample size (the sum of all cells in the table), and

pi=OiN=j=1cOi,jN,{\displaystyle p_{i\cdot }={\frac {O_{i\cdot }}{N}}=\sum _{j=1}^{c}{\frac {O_{i,j}}{N}},}

is the fraction of observations of typei ignoring the column attribute (fraction of row totals), andpj=OjN=i=1rOi,jN{\displaystyle p_{\cdot j}={\frac {O_{\cdot j}}{N}}=\sum _{i=1}^{r}{\frac {O_{i,j}}{N}}}

is the fraction of observations of typej ignoring the row attribute (fraction of column totals). The term "frequencies" refers to absolute numbers rather than already normalized values.

The value of the test-statistic is

χ2=i=1rj=1c(Oi,jEi,j)2Ei,j=Ni,jpipj((Oi,j/N)pipjpipj)2{\displaystyle {\begin{aligned}\chi ^{2}&=\sum _{i=1}^{r}\sum _{j=1}^{c}{\frac {{\left(O_{i,j}-E_{i,j}\right)}^{2}}{E_{i,j}}}\\[1ex]&=N\sum _{i,j}p_{i\cdot }p_{\cdot j}{\left({\frac {\left(O_{i,j}/N\right)-p_{i\cdot }p_{\cdot j}}{p_{i\cdot }p_{\cdot j}}}\right)}^{2}\end{aligned}}}

Note thatχ2{\displaystyle \chi ^{2}} is 0 if and only ifOi,j=Ei,ji,j{\displaystyle O_{i,j}=E_{i,j}\forall i,j}, i.e. only if the expected and true number of observations are equal in all cells.

Fitting the model of "independence" reduces the number of degrees of freedom byp =r +c − 1. The number ofdegrees of freedom is equal to the number of cellsrc, minus the reduction in degrees of freedom,p, which reduces to (r − 1)(c − 1).

For the test of independence, also known as the test of homogeneity, a chi-squared probability of less than or equal to 0.05 (or the chi-squared statistic being at or larger than the 0.05 critical point) is commonly interpreted by applied workers as justification for rejecting the null hypothesis that the row variable is independent of the column variable.[6]Thealternative hypothesis corresponds to the variables having an association or relationship where the structure of this relationship is not specified.

Assumptions

[edit]

The chi-squared test, when used with the standard approximation that a chi-squared distribution is applicable, has the following assumptions:[7]

Simple random sample
The sample data is a random sampling from a fixed distribution or population where every collection of members of the population of the given sample size has an equal probability of selection. Variants of the test have been developed for complex samples, such as where the data is weighted. Other forms can be used such aspurposive sampling.[8]
Sample size (whole table)
A sample with a sufficiently large size is assumed. If a chi squared test is conducted on a sample with a smaller size, then the chi squared test will yield an inaccurate inference. The researcher, by using chi squared test on small samples, might end up committing aType II error. For small sample sizes theCash test is preferred.[9][10]
Expected cell count
Adequate expected cell counts. Some require 5 or more, and others require 10 or more. A common rule is 5 or more in all cells of a 2-by-2 table, and 5 or more in 80% of cells in larger tables, but no cells with zero expected count. When this assumption is not met,Yates's correction is applied.
Independence
The observations are always assumed to be independent of each other. This means chi-squared cannot be used to test correlated data (like matched pairs or panel data). In those cases,McNemar's test may be more appropriate.

A test that relies on different assumptions isFisher's exact test; if its assumption of fixed marginal distributions is met it is substantially more accurate in obtaining a significance level, especially with few observations. In the vast majority of applications this assumption will not be met, and Fisher's exact test will be over conservative and not have correct coverage.[11]

Derivation

[edit]
Derivation using central limit theorem

The null distribution of the Pearson statistic withj rows andk columns is approximated by thechi-squared distribution with(k − 1)(j − 1) degrees of freedom.[12]

This approximation arises as the true distribution, under the null hypothesis, if the expected value is given by amultinomial distribution. For large sample sizes, thecentral limit theorem says this distribution tends toward a certainmultivariate normal distribution.

Two cells

[edit]

In the special case where there are only two cells in the table, the expected values follow abinomial distribution,OBin(n,p),{\displaystyle O\sim \operatorname {Bin} (n,p),}where

p = probability, under the null hypothesis,
n = number of observations in the sample.

In the above example the hypothesised probability of a male observation is 0.5, with 100 samples. Thus we expect to observe 50 males.

Ifn is sufficiently large, the above binomial distribution may be approximated by a Gaussian (normal) distribution and thus the Pearson test statistic approximates a chi-squared distribution,Bin(n,p)N(np,np(1p)).{\displaystyle \operatorname {Bin} (n,p)\approx {\mathcal {N}}{\big (}np,np(1-p){\big )}.}

LetO1 be the number of observations from the sample that are in the first cell. The Pearson test statistic can be expressed as(O1np)2np+(nO1n(1p))2n(1p),{\displaystyle {\frac {(O_{1}-np)^{2}}{np}}+{\frac {{\big (}n-O_{1}-n(1-p){\big )}^{2}}{n(1-p)}},}which can in turn be expressed as(O1npnp(1p))2.{\displaystyle \left({\frac {O_{1}-np}{\sqrt {np(1-p)}}}\right)^{2}.}

By the normal approximation to a binomial, this is the squared of one standard normal variate, and hence is distributed as chi-squared with 1 degree of freedom. Note that the denominator is one standard deviation of the Gaussian approximation, so can be written(O1μ)2σ2.{\displaystyle {\frac {(O_{1}-\mu )^{2}}{\sigma ^{2}}}.}

So as consistent with the meaning of the chi-squared distribution, we are measuring how probable the observed number of standard deviations away from the mean is under the Gaussian approximation (which is a good approximation for largen).

The chi-squared distribution is then integrated on the right of the statistic value to obtain thep-value, which is equal to the probability of getting a statistic equal or bigger than the observed one, assuming the null hypothesis.

Two-by-two contingency tables

[edit]

When the test is applied to acontingency table containing two rows and two columns, the test is equivalent to aZ-test of proportions.[citation needed]

Many cells

[edit]

Broadly similar arguments as above lead to the desired result, though the details are more involved. One may apply an orthogonal change of variables to turn the limiting summands in the test statistic into one fewer squares of i.i.d. standard normal random variables.[13]

Let us now prove that the distribution indeed approaches asymptotically theχ2{\displaystyle \chi ^{2}} distribution as the number of observations approaches infinity.

Letn{\displaystyle n} be the number of observations,m{\displaystyle m} the number of cells andpi{\displaystyle p_{i}} the probability of an observation to fall in thei-th cell, for1im{\displaystyle 1\leq i\leq m}. We denote by{ki}{\displaystyle \{k_{i}\}} the configuration where for eachi there areki{\displaystyle k_{i}} observations in thei-th cell. Note thati=1mki=nandi=1mpi=1.{\displaystyle \sum _{i=1}^{m}k_{i}=n\quad {\text{and}}\quad \sum _{i=1}^{m}p_{i}=1.}

LetχP2({ki},{pi}){\displaystyle \chi _{P}^{2}(\{k_{i}\},\{p_{i}\})} be Pearson's cumulative test statistic for such a configuration, and letχP2({pi}){\displaystyle \chi _{P}^{2}(\{p_{i}\})} be the distribution of this statistic. We will show that the latter probability approaches theχ2{\displaystyle \chi ^{2}} distribution withm1{\displaystyle m-1} degrees of freedom, asn.{\displaystyle n\to \infty .}

For any arbitrary value T:P(χP2({pi})>T)={kiχP2({ki},{pi})>T}n!k1!km!i=1mpiki.{\displaystyle P{\big (}\chi _{P}^{2}(\{p_{i}\})>T{\big )}=\sum _{\{k_{i}\mid \chi _{P}^{2}(\{k_{i}\},\{p_{i}\})>T\}}{\frac {n!}{k_{1}!\cdots k_{m}!}}\prod _{i=1}^{m}{p_{i}}^{k_{i}}.}

We will use a procedure similar to the approximation inde Moivre–Laplace theorem. Contributions from smallki{\displaystyle k_{i}} are of subleading order inn{\displaystyle n} and thus for largen{\displaystyle n} we may useStirling's formula for bothn!{\displaystyle n!} andki!{\displaystyle k_{i}!} to get the following:P(χP2({pi})>T){kiχP2({ki},{pi})>T}i=1m(npiki)ki2πni=1m2πki.{\displaystyle P{\big (}\chi _{P}^{2}(\{p_{i}\})>T{\big )}\sim \sum _{\{k_{i}\mid \chi _{P}^{2}(\{k_{i}\},\{p_{i}\})>T\}}\prod _{i=1}^{m}\left({\frac {np_{i}}{k_{i}}}\right)^{k_{i}}{\sqrt {\frac {2\pi n}{\prod _{i=1}^{m}2\pi k_{i}}}}.}

By substituting forxi=kinpin,i=1,,m1,{\displaystyle x_{i}={\frac {k_{i}-np_{i}}{\sqrt {n}}},\quad i=1,\cdots ,m-1,}we may approximate for largen{\displaystyle n} the sum over theki{\displaystyle k_{i}} by an integral over thexi{\displaystyle x_{i}}. Noting thatkm=npmni=1m1xi,{\displaystyle k_{m}=np_{m}-{\sqrt {n}}\sum _{i=1}^{m-1}x_{i},}we arrive atP(χP2({pi})>T)2πni=1m2πkiΩ[i=1m1ndxi]××{i=1m1(1+xinpi)(npi+nxi)(1i=1m1xinpm)(npmni=1m1xi)}=2πni=1m(2πnpi+2πnxi)Ω{i=1m1ndxi}××{i=1m1exp[(npi+nxi)ln(1+xinpi)]exp[(npmni=1m1xi)ln(1i=1m1xinpm)]},{\displaystyle {\begin{aligned}P{\big (}\chi _{P}^{2}(\{p_{i}\}{\big )}>T)&\sim {\sqrt {\frac {2\pi n}{\prod _{i=1}^{m}2\pi k_{i}}}}\int _{\Omega }\left[\prod _{i=1}^{m-1}{\sqrt {n}}dx_{i}\right]\times \\&\qquad \times \left\{\prod _{i=1}^{m-1}\left(1+{\frac {x_{i}}{{\sqrt {n}}p_{i}}}\right)^{-(np_{i}+{\sqrt {n}}x_{i})}\left(1-{\frac {\sum _{i=1}^{m-1}x_{i}}{{\sqrt {n}}p_{m}}}\right)^{-\left(np_{m}-{\sqrt {n}}\sum _{i=1}^{m-1}x_{i}\right)}\right\}\\&={\sqrt {\frac {2\pi n}{\prod _{i=1}^{m}\left(2\pi np_{i}+2\pi {\sqrt {n}}x_{i}\right)}}}\int _{\Omega }\left\{\prod _{i=1}^{m-1}{{\sqrt {n}}dx_{i}}\right\}\times \\&\qquad \times \left\{\prod _{i=1}^{m-1}\exp \left[-\left(np_{i}+{\sqrt {n}}x_{i}\right)\ln \left(1+{\frac {x_{i}}{{\sqrt {n}}p_{i}}}\right)\right]\exp \left[-\left(np_{m}-{\sqrt {n}}\sum _{i=1}^{m-1}x_{i}\right)\ln \left(1-{\frac {\sum _{i=1}^{m-1}x_{i}}{{\sqrt {n}}p_{m}}}\right)\right]\right\},\end{aligned}}}whereΩ{\displaystyle \Omega } is the set defined throughχP2({ki},{pi})=χP2({nxi+npi},{pi})>T{\displaystyle \chi _{P}^{2}(\{k_{i}\},\{p_{i}\})=\chi _{P}^{2}(\{{\sqrt {n}}x_{i}+np_{i}\},\{p_{i}\})>T}.[clarification needed]

Byexpanding the logarithm and taking the leading terms inn{\displaystyle n}, we getP(χP2({pi})>T)1(2π)m1i=1mpiΩ[i=1m1dxi]i=1m1exp[12i=1m1xi2pi12pm(i=1m1xi)2].{\displaystyle P{\big (}\chi _{P}^{2}(\{p_{i}\})>T{\big )}\sim {\frac {1}{\sqrt {(2\pi )^{m-1}\prod _{i=1}^{m}p_{i}}}}\int _{\Omega }\left[\prod _{i=1}^{m-1}dx_{i}\right]\prod _{i=1}^{m-1}\exp \left[-{\frac {1}{2}}\sum _{i=1}^{m-1}{\frac {x_{i}^{2}}{p_{i}}}-{\frac {1}{2p_{m}}}\left(\sum _{i=1}^{m-1}x_{i}\right)^{2}\right].}

Pearson's chi,χP2({ki},{pi})=χP2({nxi+npi},{pi}){\displaystyle \chi _{P}^{2}(\{k_{i}\},\{p_{i}\})=\chi _{P}^{2}(\{{\sqrt {n}}x_{i}+np_{i}\},\{p_{i}\})}, is precisely the argument of the exponent (except for the −1/2; note that the final term in the exponent's argument is equal to(kmnpm)2/(npm){\displaystyle (k_{m}-np_{m})^{2}/(np_{m})}).

This argument can be written as12i,j=1m1xiAijxj,Aij=δijpi+1pm,i,j=1,,m1.{\displaystyle -{\frac {1}{2}}\sum _{i,j=1}^{m-1}x_{i}A_{ij}x_{j},\quad A_{ij}={\frac {\delta _{ij}}{p_{i}}}+{\frac {1}{p_{m}}},\quad i,j=1,\cdots ,m-1.}

A{\displaystyle A} is a regular symmetric(m1)×(m1){\displaystyle (m-1)\times (m-1)} matrix, and hencediagonalizable. It is therefore possible to make a linear change of variables in{xi}{\displaystyle \{x_{i}\}} so as to getm1{\displaystyle m-1} new variables{yi}{\displaystyle \{y_{i}\}} so thati,j=1m1xiAijxj=i=1m1yi2.{\displaystyle \sum _{i,j=1}^{m-1}x_{i}A_{ij}x_{j}=\sum _{i=1}^{m-1}y_{i}^{2}.}

This linear change of variables merely multiplies the integral by a constantJacobian, so we getP(χP2({pi})>T)Ci=1m1yi2>T{i=1m1dyi}i=1m1exp[12(i=1m1yi2)],{\displaystyle P{\big (}\chi _{P}^{2}(\{p_{i}\})>T{\big )}\sim C\int _{\sum _{i=1}^{m-1}y_{i}^{2}>T}\left\{\prod _{i=1}^{m-1}dy_{i}\right\}\prod _{i=1}^{m-1}\exp \left[-{\frac {1}{2}}\left(\sum _{i=1}^{m-1}y_{i}^{2}\right)\right],}whereC is a constant.

This is the probability that squared sum ofm1{\displaystyle m-1} independent normally distributed variables of zero mean and unit variance will be greater thanT, namely thatχ2{\displaystyle \chi ^{2}} withm1{\displaystyle m-1} degrees of freedom is larger thanT.

We have thus shown that at the limit wheren,{\displaystyle n\to \infty ,} the distribution of Pearson's chi approaches the chi distribution withm1{\displaystyle m-1} degrees of freedom.

An alternative derivation is on themultinomial distribution page.

Examples

[edit]

Fairness of dice

[edit]

A 6-sided die is thrown 60 times. The number of times it lands with 1, 2, 3, 4, 5 and 6 face up is 5, 8, 9, 8, 10 and 20, respectively. Is the die biased, according to the Pearson's chi-squared test at a significance level of 95% and/or 99%?

The null hypothesis is that the die is unbiased, hence each number is expected to occur the same number of times, in this case,60/n = 10. The outcomes can be tabulated as follows:

i{\displaystyle i}Oi{\displaystyle O_{i}}Ei{\displaystyle E_{i}}OiEi{\displaystyle O_{i}-E_{i}}(OiEi)2{\displaystyle (O_{i}-E_{i})^{2}}
1510−525
2810−24
3910−11
4810−24
5101000
6201010100
Sum134

We then consult anUpper-tail critical values of chi-square distribution table, the tabular value refers to the sum of the squared variables each divided by the expected outcomes. For the present example, this meansχ2=2510+410+110+410+010+10010=13.4.{\displaystyle \chi ^{2}={\frac {25}{10}}+{\frac {4}{10}}+{\frac {1}{10}}+{\frac {4}{10}}+{\frac {0}{10}}+{\frac {100}{10}}=13.4.}

This is the experimental result whose unlikeliness (with a fair die) we wish to estimate.

Degrees
of
freedom
Probability less than the critical value
0.900.950.9750.990.999
59.23611.07012.83315.08620.515

The experimental sum of 13.4 is between the critical values of 97.5% and 99% significance or confidence (p-value). Specifically, getting 20 rolls of 6, when the expectation is only 10 such values, is unlikely with a fair die.

Chi-squared goodness of fit test

[edit]
Main article:Goodness of fit

In this context, thefrequencies of both theoretical and empirical distributions are unnormalised counts, and for a chi-squared test the total sample sizesN{\displaystyle N} of both these distributions (sums of all cells of the correspondingcontingency tables) have to be the same.

For example, to test the hypothesis that a random sample of 100 people has been drawn from a population in which men and women are equal in frequency, the observed number of men and women would be compared to the theoretical frequencies of 50 men and 50 women. If there were 44 men in the sample and 56 women, then

χ2=(4450)250+(5650)250=1.44.{\displaystyle \chi ^{2}={\frac {{\left(44-50\right)}^{2}}{50}}+{\frac {{\left(56-50\right)}^{2}}{50}}=1.44.}

If the null hypothesis is true (i.e., men and women are chosen with equal probability), the test statistic will be drawn from a chi-squared distribution with onedegree of freedom (because if the male frequency is known, then the female frequency is determined).

Consultation of thechi-squared distribution for 1 degree of freedom shows that theprobability of observing this difference (or a more extreme difference than this) if men and women are equally numerous in the population is approximately 0.23. This probability is higher than conventional criteria forstatistical significance (0.01 or 0.05), so normally we would not reject the null hypothesis that the number of men in the population is the same as the number of women (i.e., we would consider our sample within the range of what we would expect for a 50/50 male–female ratio.)

Chi-squared test for homogeneity

[edit]
Main article:Homogeneity and heterogeneity (statistics)

The chi-squared test for homogeneity of proportions (that is, comparing proportions across groups in a contingency table) is frequently used to verify if the rows of a given nonnegativem×n{\displaystyle m\times n} contingency matrixA{\displaystyle A} are proportional.

ConsiderT{\displaystyle T} outcomes of multinomial trials classified according to two criteria: membership in one ofn{\displaystyle n} groups and assignment to one ofm{\displaystyle m} categories. The outcomes may be arranged in anm×n{\displaystyle m\times n} contingency table, whereOij{\displaystyle O_{ij}} denotes the observed frequency in rowi{\displaystyle i} and columnj{\displaystyle j}, with row totalsOi{\displaystyle O_{i\cdot }}, column totalsOj{\displaystyle O_{\cdot j}} and grand totalT{\displaystyle T}.

LetOij{\displaystyle O_{ij}} denote the observed frequency in the cell corresponding to rowi{\displaystyle i} and columnj{\displaystyle j}, fori=1,2,,m{\displaystyle i=1,2,\dots ,m} andj=1,2,,n{\displaystyle j=1,2,\dots ,n}. Define the row sums

Ri=j=1nOij,i=1,,m,{\displaystyle R_{i}=\sum _{j=1}^{n}O_{ij},\quad i=1,\dots ,m,}

the column sums

Cj=i=1mOij,j=1,,n,{\displaystyle C_{j}=\sum _{i=1}^{m}O_{ij},\quad j=1,\dots ,n,}

and the grand total

T=i=1mj=1nOij.{\displaystyle T=\sum _{i=1}^{m}\sum _{j=1}^{n}O_{ij}.}

The null hypothesis is

H0:π1j=π2j==πmj,j1,,n,{\displaystyle H_{0}:\pi _{1j}=\pi _{2j}=\cdots =\pi _{mj},\quad \forall j\in {1,\dots ,n},}

whereπij[0,1]{\displaystyle \pi _{ij}\in [0,1]} denotes the proportion of individuals in groupi{\displaystyle i} falling into categoryj{\displaystyle j}, withj=1nπij=1{\displaystyle \sum _{j=1}^{n}\pi _{ij}=1} for eachi{\displaystyle i}.

UnderH0{\displaystyle H_{0}}, the expected frequency in cell(i,j){\displaystyle (i,j)} is

Eij=RiCjT,i=1,,m;;j=1,,n.{\displaystyle E_{ij}={\tfrac {R_{i}C_{j}}{T}},\quad i=1,\dots ,m;;j=1,\dots ,n.}

The Pearson chi-squared test statistic is then

χstat2=i=1mj=1n(OijEij)2Eij.{\displaystyle \chi _{\text{stat}}^{2}=\sum _{i=1}^{m}\sum _{j=1}^{n}{\frac {(O_{ij}-E_{ij})^{2}}{E_{ij}}}.}

For example, suppose there are two groups of students (Group 1 and Group 2) and three study preferences (Alone, With peers, Tutoring). LetOij{\displaystyle O_{ij}} denote the observed frequency in rowi{\displaystyle i} (preference) and columnj{\displaystyle j} (group).

The observed frequencies are as follows:

PreferenceGroup 1Group 2Row total
Alone12820
With peers182240
Tutoring103040
Column total4060100

Under the null hypothesisH0{\displaystyle H_{0}}, the rows are proportional across groups.

The expected frequencies are computed using:

Eij=RiCjT,{\displaystyle E_{ij}={\frac {R_{i}\cdot C_{j}}{T}},}

whereRi{\displaystyle R_{i}} is the row total,Cj{\displaystyle C_{j}} is the column total, andT{\displaystyle T} is the grand total.

For example, for the first row and first column:

E11=2040100=8.{\displaystyle E_{11}={\frac {20\cdot 40}{100}}=8.}

The expected frequencies are:

PreferenceGroup 1Group 2
Alone812
With peers1624
Tutoring1624

The Pearson chi-squared statistic is then:

χstat2=i=13j=12(OijEij)2Eij=7.5.{\displaystyle \chi _{\text{stat}}^{2}=\sum _{i=1}^{3}\sum _{j=1}^{2}{\frac {(O_{ij}-E_{ij})^{2}}{E_{ij}}}=7.5.}

With(31)(21)=2{\displaystyle (3-1)(2-1)=2} degrees of freedom, this value can be compared to the chi-squared distribution to test the null hypothesis.

Pitfalls of the test

[edit]

The approximation to the chi-squared distribution breaks down if expected frequencies are too low.[14][15]

It will normally be acceptable so long as no more than 20% of the events have expected frequencies below 5.[7] Where there is only 1 degree of freedom, the approximation is not reliable if expected frequencies are below 10. In this case, a better approximation can be obtained by reducing the absolute value of each difference between observed and expected frequencies by 0.5 before squaring; this is calledYates's correction for continuity.

In cases where the expected value, E, is found to be small (indicating a small underlying population probability, and/or a small number of observations), the normal approximation of the multinomial distribution can fail, and in such cases it is found to be more appropriate to use theG-test, alikelihood ratio-based test statistic. When the total sample size is small, it is necessary to use an appropriate exact test, typically either thebinomial test or, forcontingency tables,Fisher's exact test. This test uses the conditional distribution of the test statistic given the marginal totals, and thus assumes that the margins were determined before the study; alternatives such asBoschloo's test which do not make this assumption areuniformly more powerful.

In Pearson's test of homogeneity, if all entries of a matrixA{\displaystyle A} are multiplied by a positive constantc{\displaystyle c}, the Pearson chi-squared statistic is also multiplied byc{\displaystyle c}:

χstat2(cA)=cχstat2(A).{\displaystyle \chi _{\text{stat}}^{2}(cA)=c\chi _{\text{stat}}^{2}(A).}

Therefore, if all rows ofA{\displaystyle A} are exactly proportional,

χstat2(cA)=cχstat2(A)=0{\displaystyle \chi _{\text{stat}}^{2}(cA)=c\chi _{\text{stat}}^{2}(A)=0}

for anyc{\displaystyle c} and any significance levelα{\displaystyle \alpha }. Otherwise,χstat2(cA){\displaystyle \chi _{\text{stat}}^{2}(cA)} can become arbitrarily large or small asc{\displaystyle c} increases or decreases. Hence, at a fixed significance levelα{\displaystyle \alpha }, the null hypothesisH0{\displaystyle H_{0}} will be rejected with confidence1α{\displaystyle 1-\alpha } whenc{\displaystyle c} is sufficiently large, and not rejected whenc{\displaystyle c} is sufficiently small.[15] That is, the chi-squared statistic increases linearly when the entire contingency table is multiplied by a constant factor, reflecting the proportional scaling of observed and expected frequencies.

It can be shown that theχ2{\displaystyle \chi ^{2}} test is a low order approximation of theΨ{\displaystyle \Psi } test.[16] The above reasons for the above issues become apparent when the higher order terms are investigated.

See also

[edit]

Notes

[edit]
  1. ^Pearson, Karl (1900)."On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling".Philosophical Magazine. Series 5.50 (302):157–175.doi:10.1080/14786440009463897.
  2. ^Loukas, Orestis; Chung, Ho Ryun (2022). "Entropy-based Characterization of Modeling Constraints".arXiv:2206.14105 [stat.ME].
  3. ^Loukas, Orestis; Chung, Ho Ryun (2023). "Total Empiricism: Learning from Data".arXiv:2311.08315 [math.ST].
  4. ^abcDavid E. Bock, Paul F. Velleman, Richard D. De Veaux (2007). "Stats, Modeling the World," pp. 606-627, Pearson Addison Wesley, Boston,ISBN 0-13-187621-X
  5. ^"1.3.6.7.4. Critical Values of the Chi-Square Distribution". Retrieved14 October 2014.
  6. ^"Critical Values of the Chi-Squared Distribution".NIST/SEMATECH e-Handbook of Statistical Methods. National Institute of Standards and Technology.
  7. ^abMcHugh, Mary (15 June 2013)."The chi-square test of independence".Biochemia Medica.23 (2):143–149.doi:10.11613/BM.2013.018.PMC 3900058.PMID 23894860.
  8. ^SeeField, Andy.Discovering Statistics Using SPSS. for assumptions on Chi Square.
  9. ^Cash, W. (1979)."Parameter estimation in astronomy through application of the likelihood ratio".The Astrophysical Journal.228: 939.Bibcode:1979ApJ...228..939C.doi:10.1086/156922.ISSN 0004-637X.
  10. ^"The Cash Statistic and Forward Fitting".hesperia.gsfc.nasa.gov. Retrieved19 October 2021.
  11. ^"A Bayesian Formulation for Exploratory Data Analysis and Goodness-of-Fit Testing"(PDF). International Statistical Review. p. 375.
  12. ^Statistics for Applications.MIT OpenCourseWare.Lecture 23. Pearson's Theorem. Retrieved 21 March 2007.
  13. ^Benhamou, Eric; Melot, Valentin (3 September 2018). "Seven Proofs of the Pearson Chi-Squared Independence Test and its Graphical Interpretation". pp. 5–6.arXiv:1808.09171 [math.ST].
  14. ^Franke, T.M.; Ho, T; Christie, C.A. (2012). "The chi-square test: Often used and more often misinterpreted".American Journal of Evaluation.33 (3):448–458.
  15. ^abGurvich, V.; Naumova, M. (2025)."Critical issues with the Pearson's chi-square test".Modern Mathematical Methods.3 (2):101–109.doi:10.64700/mmm.75.
  16. ^Jaynes, E.T. (2003).Probability Theory: The Logic of Science. C. University Press. p. 298.ISBN 978-0-521-59271-0. (Link is to a fragmentary edition of March 1996.)

References

[edit]
Continuous data
Center
Dispersion
Shape
Count data
Summary tables
Dependence
Graphics
Study design
Survey methodology
Controlled experiments
Adaptive designs
Observational studies
Statistical theory
Frequentist inference
Point estimation
Interval estimation
Testing hypotheses
Parametric tests
Specific tests
Goodness of fit
Rank statistics
Bayesian inference
Correlation
Regression analysis
Linear regression
Non-standard predictors
Generalized linear model
Partition of variance
Categorical
Multivariate
Time-series
General
Specific tests
Time domain
Frequency domain
Survival
Survival function
Hazard function
Test
Biostatistics
Engineering statistics
Social statistics
Spatial statistics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Pearson%27s_chi-squared_test&oldid=1332112583"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp