| dchisqApprox | R Documentation |
Compute the density function f(x, *) of the (noncentral) chi-squared
distribution.
dnchisqR (x, df, ncp, log = FALSE,
eps = 5e-15, termSml = 1e-10, ncpLarge = 1000)
dnchisqBessel(x, df, ncp, log = FALSE)
dchisqAsym (x, df, ncp, log = FALSE)
dnoncentchisq(x, df, ncp, kmax = floor(ncp/2 + 5 * (ncp/2)^0.5))
x |
non-negative numeric vector. |
df |
degrees of freedom (parameter), a positive number. |
ncp |
non-centrality parameter |
log |
logical indicating if the result is desired on the log scale. |
eps |
positive convergence tolerance for the series expansion: Terms
are added while |
termSml |
positive tolerance: in the series expansion, terms are
added to the sum as long as they are not smaller than |
ncpLarge |
in the case where |
kmax |
the number of terms in the sum for |
dnchisqR() is a pure R implementation of R's own C implementation
in the sources, ‘R/src/nmath/dnchisq.c’, additionally exposing the
three “tuning parameters” eps, termSml, and ncpLarge.
dnchisqBessel() implements Fisher(1928)'s exact closed form formula
based on the Bessel function I_{nu}, i.e., R's
besselI() function;
specifically formula (29.4) in Johnson et al. (1995).
dchisqAsym() is the simple asymptotic approximation from
Abramowitz and Stegun's formula 26.4.27, p. 942.
dnoncentchisq() uses the (typically defining) infinite series expansion
directly, with truncation at kmax, and terms t_k which
are products of a Poisson probability and a central chi-square density, i.e.,
terms t.k := dpois(k, lambda = ncp/2) * dchisq(x, df = 2*k + df)
for k = 0, 1, ..., kmax.
numeric vector similar to x, containing the (logged if
log=TRUE) values of the density f(x,*).
These functions are mostly of historical interest, notably as R's
dchisq() was not always very accurate in the noncentral
case, i.e., for ncp > 0.
R's dchisq() is typically more uniformly
accurate than the approximations nowadays, apart from dnchisqR()
which should behave the same.
There may occasionally exist small differences between dnchisqR(x, *)
and dchisq(x, *) for the same parameters.
Martin Maechler, April 2008
Abramowitz, M. and Stegun, I. A. (1972) Handbook of Mathematical Functions. New York: Dover. https://en.wikipedia.org/wiki/Abramowitz_and_Stegun provides links to the full text which is in public domain.
Johnson, N.L., Kotz, S. and Balakrishnan, N. (1995) Continuous Univariate Distributions Vol~2, 2nd ed.; Wiley; chapter 29, Section 3 Distribution, (29.4), p. 436.
R's own dchisq().
x <- sort(outer(c(1,2,5), 2^(-4:5)))
fRR <- dchisq (x, 10, 2)
f.R <- dnchisqR(x, 10, 2)
all.equal(fRR, f.R, tol = 0) # 64bit Lnx (F 30): 1.723897e-16
stopifnot(all.equal(fRR, f.R, tol = 4e-15))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.