/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
package umontreal.iro.lecuyer.probdist;
import umontreal.iro.lecuyer.probdist.BetaDist;
import umontreal.iro.lecuyer.util.*;
/**
* Extends the class {@link ContinuousDistribution} for
* the Fisher F distribution with n and m
* degrees of freedom, where n and m are positive integers.
* Its density is
*
*
*
* f (x) = Γ((n + m)/2)nn/2mm/2/[Γ(n/2)Γ(m/2)]x(n-2)/2/(m + nx)(n+m)/2, for x > 0.
*
* where Γ(x) is the gamma function defined in
* {@link GammaDist}.
*
*/
public class FisherFDist extends ContinuousDistribution {
protected int n;
protected int m;
protected double C1;
/**
* Constructs a Fisher F distribution with n and m degrees of freedom.
*
*/
public FisherFDist (int n, int m) {
setParams (n, m);
}
public double density (double x) {
if (x <= 0.0)
return 0.0;
return Math.exp (C1 + 0.5 * (n - 2) * Math.log (x) -
(0.5 * (n + m) * Math.log (m + n * x)));
}
public double cdf (double x) {
return FisherFDist.cdf (n, m, decPrec, x);
}
public double barF (double x) {
return FisherFDist.barF (n, m, decPrec, x);
}
public double inverseF (double u) {
return FisherFDist.inverseF (n, m, decPrec, u);
}
public double getMean() {
return FisherFDist.getMean (n, m);
}
public double getVariance() {
return FisherFDist.getVariance (n, m);
}
public double getStandardDeviation() {
return FisherFDist.getStandardDeviation (n, m);
}
/**
* Computes the density function
* for a Fisher F distribution with n and m degrees of freedom.
*
*/
public static double density (int n, int m, double x) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 0)
throw new IllegalArgumentException ("m <= 0");
if (x <= 0.0)
return 0.0;
return Math.exp (((n / 2.0) * Math.log (n) + (m / 2.0) * Math.log (m) +
((n - 2) / 2.0) * Math.log (x)) -
(Num.lnBeta (n / 2.0, m / 2.0) + ((n + m) / 2.0) * Math.log (m + n * x)));
}
/**
* Computes the distribution function of the Fisher F distribution with parameters
* n and m, evaluated at x, with roughly d decimal digits of precision.
*
*/
public static double cdf (int n, int m, int d, double x) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 0)
throw new IllegalArgumentException ("m <= 0");
if (x <= 0.0)
return 0.0;
return BetaDist.cdf ((n / 2.0), (m / 2.0), d, ((n * x) / (n * x + m)));
}
/**
* Computes the complementary distribution function of the Fisher F distribution
* with parameters n and m, evaluated at x, with roughly d decimal digits of precision.
*
*/
public static double barF (int n, int m, int d, double x) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 0)
throw new IllegalArgumentException ("m <= 0");
if (x <= 0.0)
return 1.0;
return BetaDist.barF ((n / 2.0), (m / 2.0), d, ((n * x) / (n * x + m)));
}
/**
* Computes the inverse of the Fisher F distribution
* with parameters n and m, evaluated at x, with roughly d
* decimal digits of precision.
*
*/
public static double inverseF (int n, int m, int d, double u) {
double z;
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 0)
throw new IllegalArgumentException ("m <= 0");
if (u > 1.0 || u < 0.0)
throw new IllegalArgumentException ("u < 0 or u > 1");
if (u <= 0.0)
return 0.0;
if (u >= 1.0)
return Double.POSITIVE_INFINITY;
z = BetaDist.inverseF ((n / 2.0), (m / 2.0), d, u);
return ((m * z) / (n * (1 - z)));
}
/**
* Computes and returns the mean
* E[X] = m/(m - 2) of the
* Fisher F distribution with parameters n and m.
*
* @return the mean of the Fisher F distribution
*
*/
public static double getMean (int n, int m) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 2)
throw new IllegalArgumentException ("m <= 2");
return (m / (m - 2.0));
}
/**
* Computes and returns the variance
* of the Fisher F distribution with parameters n and m.
*
* @return the variance of the Fisher F distribution
*
* Var[X] = (2m2(m + n - 2))/(n(m - 2)2(m - 4))
*
*/
public static double getVariance (int n, int m) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 4)
throw new IllegalArgumentException ("m <= 4");
return ((2.0 * m * m * (m + n - 2)) / (n * (m - 2.0) * (m - 2.0) * (m - 4.0)));
}
/**
* Computes and returns the standard deviation
* of the Fisher F distribution with parameters n and m.
*
* @return the standard deviation of the Fisher F distribution
*
*/
public static double getStandardDeviation (int n, int m) {
return Math.sqrt (FisherFDist.getVariance (n, m));
}
/**
* Returns the parameter n of this object.
*
*/
public int getN() {
return n;
}
/**
* Returns the parameter m of this object.
*
*/
public int getM() {
return m;
}
/**
* Sets the parameters n and m of this object.
*
*/
public void setParams (int n, int m) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
if (m <= 0)
throw new IllegalArgumentException ("m <= 0");
this.n = n;
this.m = m;
supportA = 0;
C1 = (n / 2.0) * Math.log (n) + (m / 2.0) * Math.log (m) -
Num.lnBeta (n / 2.0, m / 2.0);
}
/**
* Return a table containing the parameters of the current distribution.
* This table is put in regular order: [n, m].
*
*
*/
public double[] getParams () {
double[] retour = {n, m};
return retour;
}
public String toString () {
return getClass().getSimpleName() + " : n = " + n + ", m = " + m;
}
}
Ads help maintain this website.