Categories &

Functions List

Function Reference: ncx2inv

statistics: x = ncx2inv (p, df, lambda)

Inverse of the noncentral chi-squared cumulative distribution function (iCDF).

For each element of p, compute the quantile (the inverse of the CDF) of the noncentral chi-squared distribution with df degrees of freedom and noncentrality parameter mu. The size of x is the common size of p, df, and mu. A scalar input functions as a constant matrix of the same size as the other inputs.

ncx2inv uses Newton’s method to converge to the solution.

Further information about the noncentral chi-squared distribution can be found at https://en.wikipedia.org/wiki/Noncentral_chi-squared_distribution

See also: ncx2cdf, ncx2pdf, ncx2rnd, ncx2stat, chi2inv

Source Code: ncx2inv

Example: 1

 

 ## Plot various iCDFs from the noncentral chi-squared distribution
 p = 0.001:0.001:0.999;
 x1 = ncx2inv (p, 2, 1);
 x2 = ncx2inv (p, 2, 2);
 x3 = ncx2inv (p, 2, 3);
 x4 = ncx2inv (p, 4, 1);
 x5 = ncx2inv (p, 4, 2);
 x6 = ncx2inv (p, 4, 3);
 plot (p, x1, "-r", p, x2, "-g", p, x3, "-k", ...
       p, x4, "-m", p, x5, "-c", p, x6, "-y")
 grid on
 ylim ([0, 10])
 legend ({"df = 2, λ = 1", "df = 2, λ = 2", ...
          "df = 2, λ = 3", "df = 4, λ = 1", ...
          "df = 4, λ = 2", "df = 4, λ = 3"}, "location", "northwest")
 title ("Noncentral chi-squared iCDF")
 xlabel ("probability")
 ylabel ("values in x")

                    
plotted figure

Example: 2

 

 ## Compare the noncentral chi-squared CDF with LAMBDA = 2 to the
 ## chi-squared CDF with the same number of degrees of freedom (4).

 p = 0.001:0.001:0.999;
 x1 = ncx2inv (p, 4, 2);
 x2 = chi2inv (p, 4);
 plot (p, x1, "-", p, x2, "-");
 grid on
 ylim ([0, 10])
 legend ({"Noncentral χ^2(4,2)", "χ^2(4)"}, "location", "northwest")
 title ("Noncentral chi-squared vs chi-squared quantile functions")
 xlabel ("probability")
 ylabel ("values in x")

                    
plotted figure