Package jdistlib

Class NonCentralChiSquare


public class NonCentralChiSquare extends GenericDistribution
  • Field Details

    • df

      protected double df
    • ncp

      protected double ncp
  • Constructor Details

    • NonCentralChiSquare

      public NonCentralChiSquare(double df, double ncp)
  • Method Details

    • density

      public static final double density(double x, double df, double ncp, boolean give_log)
    • cumulative_raw

      public static final double cumulative_raw(double x, double f, double theta, double errmax, double reltol, int itrmax, boolean lower_tail, boolean log_p)
    • cumulative

      public static final double cumulative(double x, double df, double ncp, boolean lower_tail, boolean log_p)
    • quantile

      public static final double quantile(double p, double df, double ncp, boolean lower_tail, boolean log_p)
    • random

      public static final double random(double df, double lambda, RandomEngine 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))
                  }
    • random

      public static final double[] random(int n, double df, double lambda, RandomEngine random)
    • density

      public double density(double x, boolean log)
      Specified by:
      density in class GenericDistribution
    • cumulative

      public double cumulative(double p, boolean lower_tail, boolean log_p)
      Specified by:
      cumulative in class GenericDistribution
    • quantile

      public double quantile(double q, boolean lower_tail, boolean log_p)
      Specified by:
      quantile in class GenericDistribution
    • random

      public double random()
      Specified by:
      random in class GenericDistribution