Girish Mahajan (Editor)

Chi squared distribution

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Chi-squared distribution

Notation
  
χ 2 ( k ) {displaystyle chi ^{2}(k)!} or χ k 2 {displaystyle chi _{k}^{2}!}

Parameters
  
k ∈ N > 0     {displaystyle kin mathbb {N} _{>0}~~} (known as "degrees of freedom")

Support
  
x ∈ [ 0 , + ∞ ) {displaystyle xin [0,+infty )}

PDF
  
1 2 k 2 Γ ( k 2 ) x k 2 − 1 e − x 2 {displaystyle { rac {1}{2^{ rac {k}{2}}Gamma left({ rac {k}{2}} ight)}};x^{{ rac {k}{2}}-1}e^{-{ rac {x}{2}}},}

CDF
  
1 Γ ( k 2 ) γ ( k 2 , x 2 ) {displaystyle { rac {1}{Gamma left({ rac {k}{2}} ight)}};gamma left({ frac {k}{2}},,{ rac {x}{2}} ight)}

Mean
  
k {displaystyle k}

In probability theory and statistics, the chi-squared distribution (also chi-square or χ2-distribution) with k degrees of freedom is the distribution of a sum of the squares of k independent standard normal random variables. It is a special case of the gamma distribution and is one of the most widely used probability distributions in inferential statistics, e. g., in hypothesis testing or in construction of confidence intervals. When it is being distinguished from the more general noncentral chi-squared distribution, this distribution is sometimes called the central chi-squared distribution.

Contents

The chi-squared distribution is used in the common chi-squared tests for goodness of fit of an observed distribution to a theoretical one, the independence of two criteria of classification of qualitative data, and in confidence interval estimation for a population standard deviation of a normal distribution from a sample standard deviation. Many other statistical tests also use this distribution, like Friedman's analysis of variance by ranks.

Definition

If Z1, ..., Zk are independent, standard normal random variables, then the sum of their squares,

Q   = i = 1 k Z i 2 ,

is distributed according to the chi-squared distribution with k degrees of freedom. This is usually denoted as

Q     χ 2 ( k )     or     Q     χ k 2 .

The chi-squared distribution has one parameter: k — a positive integer that specifies the number of degrees of freedom (i. e. the number of Zi’s)

Introduction

The chi-squared distribution is used primarily in hypothesis testing. Unlike more widely known distributions such as the normal distribution and the exponential distribution, the chi-squared distribution is rarely used to model natural phenomena. It arises in the following hypothesis tests, among others.

  • Chi-squared test of independence in contingency tables
  • Chi-squared test of goodness of fit of observed data to hypothetical distributions
  • Likelihood-ratio test for nested models
  • Log-rank test in survival analysis
  • Cochran–Mantel–Haenszel test for stratified contingency tables
  • It is also a component of the definition of the t-distribution and the F-distribution used in t-tests, analysis of variance, and regression analysis.

    The primary reason that the chi-squared distribution is used extensively in hypothesis testing is its relationship to the normal distribution. Many hypothesis tests use a test statistic, such as the t statistic in a t-test. For these hypothesis tests, as the sample size, n, increases, the sampling distribution of the test statistic approaches the normal distribution (Central Limit Theorem). Because the test statistic (such as t) is asymptotically normally distributed, provided the sample size is sufficiently large, the distribution used for hypothesis testing may be approximated by a normal distribution. Testing hypotheses using a normal distribution is well understood and relatively easy. The simplest chi-squared distribution is the square of a standard normal distribution. So wherever a normal distribution could be used for a hypothesis test, a chi-squared distribution could be used.

    Specifically, suppose that Z is a standard normal random variable, with mean = 0 and variance = 1. Z ~ N(0,1). A sample drawn at random from Z is a sample from the distribution shown in the graph of the standard normal distribution. Define a new random variable Q. To generate a random sample from Q, take a sample from Z and square the value. The distribution of the squared values is given by the random variable Q = Z2. The distribution of the random variable Q is an example of a chi-squared distribution:   Q     χ 1 2 . The subscript 1 indicates that this particular chi-squared distribution is constructed from only 1 standard normal distribution. A chi-squared distribution constructed by squaring a single standard normal distribution is said to have 1 degree of freedom. Thus, as the sample size for a hypothesis test increases, the distribution of the test statistic approaches a normal distribution, and the distribution of the square of the test statistic approaches a chi-squared distribution. Just as extreme values of the normal distribution have low probability (and give small p-values), extreme values of the chi-squared distribution have low probability.

    An additional reason that the chi-squared distribution is widely used is that it is a member of the class of likelihood ratio tests (LRT). LRT's have several desirable properties; in particular, LRT's commonly provide the highest power to reject the null hypothesis (Neyman–Pearson lemma). However, the normal and chi-squared approximations are only valid asymptotically. For this reason, it is preferable to use the t distribution rather than the normal approximation or the chi-squared approximation for small sample size. Similarly, in analyses of contingency tables, the chi-squared approximation will be poor for small sample size, and it is preferable to use Fisher's exact test. Ramsey and Ramsey show that the exact binomial test is always more powerful than the normal approximation.

    Lancaster shows the connections among the binomial, normal, and chi-squared distributions, as follows. De Moivre and Laplace established that a binomial distribution could be approximated by a normal distribution. Specifically they showed the asymptotic normality of the random variable

    χ = m N p ( N p q )

    where m is the observed number of successes in N trials, where the probability of success is p, and q = 1 − p.

    Squaring both sides of the equation gives

    χ 2 = ( m N p ) 2 ( N p q )

    Using N = Np + N(1 − p), N = m + (Nm), and q = 1 − p, this equation simplifies to

    χ 2 = ( m N p ) 2 ( N p ) + ( N m N q ) 2 ( N q )

    The expression on the right is of the form that Pearson would generalize to the form:

    χ 2 = i = 1 n ( O i E i ) 2 E i

    where

    χ 2 = Pearson's cumulative test statistic, which asymptotically approaches a χ 2 distribution. O i = the number of observations of type i. E i = N p i = the expected (theoretical) frequency of type i, asserted by the null hypothesis that the fraction of type i in the population is p i n = the number of cells in the table.

    In the case of a binomial outcome (flipping a coin), the binomial distribution may be approximated by a normal distribution (for sufficiently large n). Because the square of a standard normal distribution is the chi-squared distribution with one degree of freedom, the probability of a result such as 1 heads in 10 trials can be approximated either by the normal or the chi-squared distribution. However, many problems involve more than the two possible outcomes of a binomial, and instead require 3 or more categories, which leads to the multinomial distribution. Just as de Moivre and Laplace sought for and found the normal approximation to the binomial, Pearson sought for and found a multivariate normal approximation to the multinomial distribution. Pearson showed that the chi-squared distribution, the sum of multiple normal distributions, was such an approximation to the multinomial distribution

    Characteristics

    Further properties of the chi-squared distribution can be found in the box at the upper right corner of this article.

    Probability density function

    The probability density function (pdf) of the chi-square distribution is

    f ( x ; k ) = { x ( k / 2 1 ) e x / 2 2 k / 2 Γ ( k 2 ) , x > 0 ; 0 , otherwise .

    where Γ ( k / 2 ) denotes the Gamma function, which has closed-form values for integer k.

    For derivations of the pdf in the cases of one, two and k degrees of freedom, see Proofs related to chi-squared distribution.

    Differential equation

    The pdf of the chi-squared distribution is a solution to the following differential equation:

    2 x f ( x ) + f ( x ) ( k + x + 2 ) = 0

    Therefore, f ( x ) f ( x ) = k 2 x 2 x = k 2 1 x 1 2

    Integrating both sides, log ( f ( x ) ) = ( k 2 1 ) log ( x ) x 2 + log ( C )

    Therefore, f ( x ) = C x k / 2 1 e x / 2 = C 2 k / 2 ( x / 2 ) k / 2 1 e x / 2 / 2

    Total probability (i.e. area under the curve y = f(x) from -Infinity to +Infinity) needs to be 1.

    Therefore, Total Probability P = C 2 k / 2 0 ( x / 2 ) k / 2 1 e x / 2 d ( x / 2 ) = C 2 k / 2 Γ ( k / 2 ) = 1

    Hence, PDF χ k 2 = f ( x ) = C x k / 2 1 e x / 2 = x k / 2 1 e x / 2 2 k / 2 Γ ( k / 2 ) (and 0 when x < 0)

    Cumulative distribution function

    Its cumulative distribution function is:

    F ( x ; k ) = γ ( k 2 , x 2 ) Γ ( k 2 ) = P ( k 2 , x 2 ) ,

    where γ ( s , t ) is the lower incomplete Gamma function and P ( s , t ) is the regularized Gamma function.

    In a special case of k = 2 this function has a simple form:

    F ( x ; 2 ) = 1 e x / 2

    and the form is not much more complicated for other small even k.

    Tables of the chi-squared cumulative distribution function are widely available and the function is included in many spreadsheets and all statistical packages.

    Letting z x / k , Chernoff bounds on the lower and upper tails of the CDF may be obtained. For the cases when 0 < z < 1 (which include all of the cases when this CDF is less than half):

    F ( z k ; k ) ( z e 1 z ) k / 2 .

    The tail bound for the cases when z > 1 , similarly, is

    1 F ( z k ; k ) ( z e 1 z ) k / 2 .

    For another approximation for the CDF modeled after the cube of a Gaussian, see under Noncentral chi-squared distribution.

    Additivity

    It follows from the definition of the chi-squared distribution that the sum of independent chi-squared variables is also chi-squared distributed. Specifically, if {Xi}i=1n are independent chi-squared variables with {ki}i=1n degrees of freedom, respectively, then Y = X1 + ⋯ + Xn is chi-squared distributed with k1 + ⋯ + kn degrees of freedom.

    Sample mean

    The sample mean of n i.i.d. chi-squared variables of degree k is distributed according to a gamma distribution with shape α and scale θ parameters:

    X ¯ = 1 n i = 1 n X i Gamma ( α = n k / 2 , θ = 2 / n ) where  X i χ 2 ( k )

    Asymptotically, given that for a scale parameter α going to infinity, a Gamma distribution converges towards a normal distribution with expectation μ = α θ and variance σ 2 = α θ 2 , the sample mean converges towards:

    X ¯ n N ( μ = k , σ 2 = 2 k / n )

    Note that we would have obtained the same result invoking instead the central limit theorem, noting that for each chi-squared variable of degree k the expectation is k , and its variance 2 k (and hence the variance of the sample mean X ¯ being σ 2 = 2 k / n ).

    Entropy

    The differential entropy is given by

    h = f ( x ; k ) ln f ( x ; k ) d x = k 2 + ln [ 2 Γ ( k 2 ) ] + ( 1 k 2 ) ψ [ k 2 ] ,

    where ψ(x) is the Digamma function.

    The chi-squared distribution is the maximum entropy probability distribution for a random variate X for which E ( X ) = k and E ( ln ( X ) ) = ψ ( k / 2 ) + ln ( 2 ) are fixed. Since the chi-squared is in the family of gamma distributions, this can be derived by substituting appropriate values in the Expectation of the Log moment of Gamma. For derivation from more basic principles, see the derivation in moment generating function of the sufficient statistic.

    Noncentral moments

    The moments about zero of a chi-squared distribution with k degrees of freedom are given by

    E ( X m ) = k ( k + 2 ) ( k + 4 ) ( k + 2 m 2 ) = 2 m Γ ( m + k 2 ) Γ ( k 2 ) .

    Cumulants

    The cumulants are readily obtained by a (formal) power series expansion of the logarithm of the characteristic function:

    κ n = 2 n 1 ( n 1 ) ! k

    Asymptotic properties

    By the central limit theorem, because the chi-squared distribution is the sum of k independent random variables with finite mean and variance, it converges to a normal distribution for large k. For many practical purposes, for k > 50 the distribution is sufficiently close to a normal distribution for the difference to be ignored. Specifically, if X ~ χ2(k), then as k tends to infinity, the distribution of ( X k ) / 2 k tends to a standard normal distribution. However, convergence is slow as the skewness is 8 / k and the excess kurtosis is 12/k.

    The sampling distribution of ln(χ2) converges to normality much faster than the sampling distribution of χ2, as the logarithm removes much of the asymmetry. Other functions of the chi-squared distribution converge more rapidly to a normal distribution. Some examples are:

  • If X ~ χ2(k) then 2 X is approximately normally distributed with mean 2 k 1 and unit variance (result credited to R. A. Fisher).
  • If X ~ χ2(k) then X / k 3 is approximately normally distributed with mean 1 2 / ( 9 k ) and variance 2 / ( 9 k ) . This is known as the Wilson–Hilferty transformation.
  • Relation to other distributions

  • As k , ( χ k 2 k ) / 2 k   d   N ( 0 , 1 ) (normal distribution)
  • χ k 2 χ k 2 ( 0 ) (noncentral chi-squared distribution with non-centrality parameter λ = 0 )
  • If Y F ( ν 1 , ν 2 ) then X = lim ν 2 ν 1 Y has the chi-squared distribution χ ν 1 2
  • As a special case, if Y F ( 1 , ν 2 ) then X = lim ν 2 Y has the chi-squared distribution χ 1 2
  • N i = 1 , , k ( 0 , 1 ) 2 χ k 2 (The squared norm of k standard normally distributed variables is a chi-squared distribution with k degrees of freedom)
  • If X χ 2 ( ν ) and c > 0 , then c X Γ ( k = ν / 2 , θ = 2 c ) . (gamma distribution)
  • If X χ k 2 then X χ k (chi distribution)
  • If X χ 2 ( 2 ) , then X Exp ( 1 / 2 ) is an exponential distribution. (See Gamma distribution for more.)
  • If X Rayleigh ( 1 ) (Rayleigh distribution) then X 2 χ 2 ( 2 )
  • If X Maxwell ( 1 ) (Maxwell distribution) then X 2 χ 2 ( 3 )
  • If X χ 2 ( ν ) then 1 X I n v - χ 2 ( ν ) (Inverse-chi-squared distribution)
  • The chi-squared distribution is a special case of type 3 Pearson distribution
  • If X χ 2 ( ν 1 ) and Y χ 2 ( ν 2 ) are independent then X X + Y Beta ( ν 1 2 , ν 2 2 ) (beta distribution)
  • If X U ( 0 , 1 ) (uniform distribution) then 2 log ( X ) χ 2 ( 2 )
  • χ 2 ( 6 ) is a transformation of Laplace distribution
  • If X i Laplace ( μ , β ) then i = 1 n 2 | X i μ | β χ 2 ( 2 n )
  • chi-squared distribution is a transformation of Pareto distribution
  • Student's t-distribution is a transformation of chi-squared distribution
  • Student's t-distribution can be obtained from chi-squared distribution and normal distribution
  • Noncentral beta distribution can be obtained as a transformation of chi-squared distribution and Noncentral chi-squared distribution
  • Noncentral t-distribution can be obtained from normal distribution and chi-squared distribution
  • A chi-squared variable with k degrees of freedom is defined as the sum of the squares of k independent standard normal random variables.

    If Y is a k-dimensional Gaussian random vector with mean vector μ and rank k covariance matrix C, then X = (Yμ)TC−1(Y − μ) is chi-squared distributed with k degrees of freedom.

    The sum of squares of statistically independent unit-variance Gaussian variables which do not have mean zero yields a generalization of the chi-squared distribution called the noncentral chi-squared distribution.

    If Y is a vector of k i.i.d. standard normal random variables and A is a k×k symmetric, idempotent matrix with rank k−n then the quadratic form YTAY is chi-squared distributed with k−n degrees of freedom.

    The chi-squared distribution is also naturally related to other distributions arising from the Gaussian. In particular,

  • Y is F-distributed, Y ~ F(k1,k2) if Y = X 1 / k 1 X 2 / k 2 where X1 ~ χ²(k1) and X2  ~ χ²(k2) are statistically independent.
  • If X is chi-squared distributed, then X is chi distributed.
  • If X1  ~  χ2k1 and X2  ~  χ2k2 are statistically independent, then X1 + X2  ~ χ2k1+k2. If X1 and X2 are not independent, then X1 + X2 is not chi-squared distributed.
  • Generalizations

    The chi-squared distribution is obtained as the sum of the squares of k independent, zero-mean, unit-variance Gaussian random variables. Generalizations of this distribution can be obtained by summing the squares of other types of Gaussian random variables. Several such distributions are described below.

    Linear combination

    If X 1 , , X n are chi square random variables and a 1 , , a n R > 0 , then a closed expression for the distribution of X = i = 1 n a i X i is not known. It may be, however, calculated using the property of characteristic functions of the chi-squared random variable.

    Noncentral chi-squared distribution

    The noncentral chi-squared distribution is obtained from the sum of the squares of independent Gaussian random variables having unit variance and nonzero means.

    Generalized chi-squared distribution

    The generalized chi-squared distribution is obtained from the quadratic form z′Az where z is a zero-mean Gaussian vector having an arbitrary covariance matrix, and A is an arbitrary matrix.

    The chi-squared distribution X χ k 2 is a special case of the gamma distribution, in that X Γ ( k 2 , 1 2 ) using the rate parameterization of the gamma distribution (or X Γ ( k 2 , 2 ) using the scale parameterization of the gamma distribution) where k is an integer.

    Because the exponential distribution is also a special case of the Gamma distribution, we also have that if X χ 2 2 , then X Exp ( 1 2 ) is an exponential distribution.

    The Erlang distribution is also a special case of the Gamma distribution and thus we also have that if X χ k 2 with even k, then X is Erlang distributed with shape parameter k/2 and scale parameter 1/2.

    Occurrence and applications

    The chi-squared distribution has numerous applications in inferential statistics, for instance in chi-squared tests and in estimating variances. It enters the problem of estimating the mean of a normally distributed population and the problem of estimating the slope of a regression line via its role in Student’s t-distribution. It enters all analysis of variance problems via its role in the F-distribution, which is the distribution of the ratio of two independent chi-squared random variables, each divided by their respective degrees of freedom.

    Following are some of the most common situations in which the chi-squared distribution arises from a Gaussian-distributed sample.

  • if X1, ..., Xn are i.i.d. N(μ, σ2) random variables, then i = 1 n ( X i X ¯ ) 2 σ 2 χ n 1 2 where X ¯ = 1 n i = 1 n X i .
  • The box below shows some statistics based on Xi ∼ Normal(μi, σ2i), i = 1, ⋯, k, independent random variables that have probability distributions related to the chi-squared distribution:
  • The chi-squared distribution is also often encountered in Magnetic Resonance Imaging.

    Table of χ2 values vs p-values

    The p-value is the probability of observing a test statistic at least as extreme in a chi-squared distribution. Accordingly, since the cumulative distribution function (CDF) for the appropriate degrees of freedom (df) gives the probability of having obtained a value less extreme than this point, subtracting the CDF value from 1 gives the p-value. The table below gives a number of p-values matching to χ2 for the first 10 degrees of freedom.

    A low p-value indicates greater statistical significance, i. e., greater confidence that the observed deviation from the null hypothesis is significant. A p-value of 0.05 is often used as a cutoff between significant and not-significant results.

    These values can be calculated evaluating the quantile function (also known as “inverse CDF” or “ICDF”) of the chi-squared distribution; e. g., the χ2 ICDF for p = 1 − 0.95 and df = 7 yields 14.067 ≈ 14.07 as in the table above. In Python, this can be calculated using SciPy via scipy.stats.chi2.isf(0.05, 7).

    History and name

    This distribution was first described by the German statistician Friedrich Robert Helmert in papers of 1875–6, where he computed the sampling distribution of the sample variance of a normal population. Thus in German this was traditionally known as the Helmert'sche ("Helmertian") or "Helmert distribution".

    The distribution was independently rediscovered by the English mathematician Karl Pearson in the context of goodness of fit, for which he developed his Pearson's chi-squared test, published in 1900, with computed table of values published in (Elderton 1902), collected in (Pearson 1914, pp. xxxi–xxxiii, 26–28, Table XII). The name "chi-squared" ultimately derives from Pearson's shorthand for the exponent in a multivariate normal distribution with the Greek letter Chi, writing −½χ2 for what would appear in modern notation as −½xTΣ−1x (Σ being the covariance matrix). The idea of a family of "chi-squared distributions", however, is not due to Pearson but arose as a further development due to Fisher in the 1920s.

    References

    Chi-squared distribution Wikipedia