Main Content

chi2pdf

Chi-square probability density function

Description

example

y = chi2pdf(x,nu) returns the probability density function (pdf) of the chi-square distribution with nu degrees of freedom, evaluated at the values in x.

Examples

collapse all

Compute the density of the observed value 2 in the chi-square distribution with 3 degrees of freedom.

y1 = chi2pdf(2,3)
y1 = 0.2076

Compute the density of the observed value 4 in the chi-square distributions with degrees of freedom 1 through 6.

y2 = chi2pdf(4,1:6)
y2 = 1×6

    0.0270    0.0677    0.1080    0.1353    0.1440    0.1353

The mean of the chi-square distribution is equal to the degrees of freedom. Compute the density of the mean for the chi-square distributions with degrees of freedom 1 through 6.

nu = 1:6;
x = nu;
y3 = chi2pdf(x,nu)
y3 = 1×6

    0.2420    0.1839    0.1542    0.1353    0.1220    0.1120

As the degrees of freedom increase, the density of the mean decreases.

Input Arguments

collapse all

Values at which to evaluate the pdf, specified as a nonnegative scalar value or an array of nonnegative scalar values.

  • To evaluate the pdf at multiple values, specify x using an array.

  • To evaluate the pdfs of multiple distributions, specify nu using an array.

If either or both of the input arguments x and nu are arrays, then the array sizes must be the same. In this case, chi2pdf expands each scalar input into a constant array of the same size as the array inputs. Each element in y is the pdf value of the distribution specified by the corresponding element in nu, evaluated at the corresponding element in x.

Example: [3 4 7 9]

Data Types: single | double

Degrees of freedom for the chi-square distribution, specified as a positive scalar value or an array of positive scalar values.

  • To evaluate the pdf at multiple values, specify x using an array.

  • To evaluate the pdfs of multiple distributions, specify nu using an array.

If either or both of the input arguments x and nu are arrays, then the array sizes must be the same. In this case, chi2pdf expands each scalar input into a constant array of the same size as the array inputs. Each element in y is the pdf value of the distribution specified by the corresponding element in nu, evaluated at the corresponding element in x.

Example: [9 19 49 99]

Data Types: single | double

Output Arguments

collapse all

pdf values evaluated at the values in x, returned as a scalar value or an array of scalar values. p is the same size as x and nu after any necessary scalar expansion. Each element in y is the pdf value of the distribution specified by the corresponding element in nu, evaluated at the corresponding element in x.

More About

collapse all

Chi-Square pdf

The chi-square distribution is a one-parameter family of curves. The parameter ν is the degrees of freedom.

The pdf of the chi-square distribution is

y=f(x|ν)=x(ν2)/2ex/22ν2Γ(ν/2),

where ν is the degrees of freedom and Γ( · ) is the Gamma function.

For more information, see Chi-Square Distribution.

Alternative Functionality

  • chi2pdf is a function specific to the chi-square distribution. Statistics and Machine Learning Toolbox™ also offers the generic function pdf, which supports various probability distributions. To use pdf, specify the probability distribution name and its parameters. Note that the distribution-specific function chi2pdf is faster than the generic function pdf.

  • Use the Probability Distribution Function app to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a