public class NonCentralChiSquare extends Object
| Constructor and Description |
|---|
NonCentralChiSquare() |
| Modifier and Type | Method and Description |
|---|---|
static double |
cumulative_raw(double x,
double f,
double theta,
double errmax,
double reltol,
int itrmax,
boolean lower_tail) |
static double |
cumulative(double x,
double df,
double ncp,
boolean lower_tail,
boolean log_p) |
static double |
density(double x,
double df,
double ncp,
boolean give_log) |
static double |
quantile(double p,
double df,
double ncp,
boolean lower_tail,
boolean log_p) |
static double |
random(double df,
double lambda,
QRandomEngine random)
According to Hans R.
|
public static final double density(double x,
double df,
double ncp,
boolean give_log)
public static final double cumulative_raw(double x,
double f,
double theta,
double errmax,
double reltol,
int itrmax,
boolean lower_tail)
public static final double cumulative(double x,
double df,
double ncp,
boolean lower_tail,
boolean log_p)
public static final double quantile(double p,
double df,
double ncp,
boolean lower_tail,
boolean log_p)
public static final double random(double df,
double lambda,
QRandomEngine random)
According to Hans R. Kuensch's suggestion (30 sep 2002):
It should be easy to do the general case (ncp > 0) by decomposing it
as the sum of a central chisquare with df degrees of freedom plus a
noncentral chisquare with zero degrees of freedom (which is a Poisson
mixture of central chisquares with integer degrees of freedom),
see Formula (29.5b-c) in Johnson, Kotz, Balakrishnan (1995).
The noncentral chisquare with arbitary degrees of freedom is of interest
for simulating the Cox-Ingersoll-Ross model for interest rates in
finance.
R code that works is
rchisq0 <- function(n, ncp) {
p <- 0 < (K <- rpois(n, lambda = ncp / 2))
r <- numeric(n)
r[p] <- rchisq(sum(p), df = 2*K[p])
r
}
rchisq <- function(n, df, ncp=0) {
if(missing(ncp)) .Internal(rchisq(n, df))
else rchisq0(n, ncp) + .Internal(rchisq(n, df))
}Copyright © 2013. All rights reserved.