SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
FisherFDist.java
1/*
2 * Class: FisherFDist
3 * Description: Fisher F-distribution
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.probdist;
26
27import umontreal.ssj.probdist.BetaDist;
28import umontreal.ssj.util.*;
29
47public class FisherFDist extends ContinuousDistribution {
48 protected int n1;
49 protected int n2;
50 protected double C1;
51 private static final int DECPREC = 15; // decimal precision
52
57 public FisherFDist(int n1, int n2) {
58 setParams(n1, n2);
59 }
60
61 public double density(double x) {
62 if (x <= 0.0)
63 return 0.0;
64 return Math.exp(C1 + 0.5 * (n1 - 2) * Math.log(x) - (0.5 * (n1 + n2) * Math.log(n2 + n1 * x)));
65 }
66
67 public double cdf(double x) {
68 return FisherFDist.cdf(n1, n2, x);
69 }
70
71 public double barF(double x) {
72 return FisherFDist.barF(n1, n2, x);
73 }
74
75 public double inverseF(double u) {
76 return FisherFDist.inverseF(n1, n2, u);
77 }
78
79 public double getMean() {
80 return FisherFDist.getMean(n1, n2);
81 }
82
83 public double getVariance() {
84 return FisherFDist.getVariance(n1, n2);
85 }
86
87 public double getStandardDeviation() {
88 return FisherFDist.getStandardDeviation(n1, n2);
89 }
90
96 public static double density(int n1, int n2, double x) {
97 if (n1 <= 0)
98 throw new IllegalArgumentException("n1 <= 0");
99 if (n2 <= 0)
100 throw new IllegalArgumentException("n2 <= 0");
101 if (x <= 0.0)
102 return 0.0;
103
104 return Math.exp(((n1 / 2.0) * Math.log(n1) + (n2 / 2.0) * Math.log(n2) + ((n1 - 2) / 2.0) * Math.log(x))
105 - (Num.lnBeta(n1 / 2.0, n2 / 2.0) + ((n1 + n2) / 2.0) * Math.log(n2 + n1 * x)));
106 }
107
113 @Deprecated
114 public static double cdf(int n1, int n2, int d, double x) {
115 if (n1 <= 0)
116 throw new IllegalArgumentException("n1 <= 0");
117 if (n2 <= 0)
118 throw new IllegalArgumentException("n2 <= 0");
119 if (x <= 0.0)
120 return 0.0;
121 return BetaDist.cdf(n1 / 2.0, n2 / 2.0, (n1 * x) / (n1 * x + n2));
122 }
123
128 public static double cdf(int n1, int n2, double x) {
129 return cdf(n1, n2, DECPREC, x);
130 }
131
138 @Deprecated
139 public static double barF(int n1, int n2, int d, double x) {
140 if (n1 <= 0)
141 throw new IllegalArgumentException("n1 <= 0");
142 if (n2 <= 0)
143 throw new IllegalArgumentException("n2 <= 0");
144 if (x <= 0.0)
145 return 1.0;
146 return BetaDist.barF(n1 / 2.0, n2 / 2.0, (n1 * x) / (n1 * x + n2));
147 }
148
154 public static double barF(int n1, int n2, double x) {
155 return barF(n1, n2, DECPREC, x);
156 }
157
163 @Deprecated
164 public static double inverseF(int n1, int n2, int d, double u) {
165 if (n1 <= 0)
166 throw new IllegalArgumentException("n1 <= 0");
167 if (n2 <= 0)
168 throw new IllegalArgumentException("n2 <= 0");
169 if (u > 1.0 || u < 0.0)
170 throw new IllegalArgumentException("u < 0 or u > 1");
171 if (u <= 0.0)
172 return 0.0;
173 if (u >= 1.0)
174 return Double.POSITIVE_INFINITY;
175
176 double z = BetaDist.inverseF(n1 / 2.0, n2 / 2.0, d, u);
177 return ((n2 * z) / (n1 * (1 - z)));
178 }
179
184 public static double inverseF(int n1, int n2, double u) {
185 return inverseF(n1, n2, DECPREC, u);
186 }
187
194 public static double getMean(int n1, int n2) {
195 if (n1 <= 0)
196 throw new IllegalArgumentException("n1 <= 0");
197 if (n2 <= 2)
198 throw new IllegalArgumentException("n2 <= 2");
199
200 return (n2 / (n2 - 2.0));
201 }
202
211 public static double getVariance(int n1, int n2) {
212 if (n1 <= 0)
213 throw new IllegalArgumentException("n1 <= 0");
214 if (n2 <= 4)
215 throw new IllegalArgumentException("n2 <= 4");
216
217 return ((2.0 * n2 * n2 * (n2 + n1 - 2)) / (n1 * (n2 - 2.0) * (n2 - 2.0) * (n2 - 4.0)));
218 }
219
226 public static double getStandardDeviation(int n1, int n2) {
227 return Math.sqrt(FisherFDist.getVariance(n1, n2));
228 }
229
233 public int getN1() {
234 return n1;
235 }
236
240 public int getN2() {
241 return n2;
242 }
243
247 public void setParams(int n1, int n2) {
248 if (n1 <= 0)
249 throw new IllegalArgumentException("n1 <= 0");
250 if (n2 <= 0)
251 throw new IllegalArgumentException("n2 <= 0");
252
253 this.n1 = n1;
254 this.n2 = n2;
255 supportA = 0;
256 C1 = (n1 / 2.0) * Math.log(n1) + (n2 / 2.0) * Math.log(n2) - Num.lnBeta(n1 / 2.0, n2 / 2.0);
257 }
258
263 public double[] getParams() {
264 double[] retour = { n1, n2 };
265 return retour;
266 }
267
271 public String toString() {
272 return getClass().getSimpleName() + " : n1 = " + n1 + ", n2 = " + n2;
273 }
274
275}
Extends the class ContinuousDistribution for the beta distribution.
Definition BetaDist.java:54
double inverseF(double u)
Returns the inverse distribution function .
double barF(double x)
Returns the complementary distribution function.
double cdf(double x)
Returns the distribution function .
Classes implementing continuous distributions should inherit from this base class.
static double cdf(int n1, int n2, int d, double x)
Computes the distribution function of the Fisher distribution with parameters n1 and n2,...
int getN1()
Returns the parameter n1 of this object.
static double density(int n1, int n2, double x)
Computes the density function ( FisherF ) for a Fisher distribution with n1 and n2 degrees of freedo...
double cdf(double x)
Returns the distribution function .
static double barF(int n1, int n2, int d, double x)
Computes the complementary distribution function of the Fisher.
static double inverseF(int n1, int n2, int d, double u)
Computes the inverse of the Fisher distribution with parameters n1 and n2, evaluated at ,...
static double barF(int n1, int n2, double x)
Computes the complementary distribution function of the Fisher.
FisherFDist(int n1, int n2)
Constructs a Fisher distribution with n1 and n2 degrees of freedom.
double density(double x)
Returns , the density evaluated at .
static double inverseF(int n1, int n2, double u)
Computes the inverse of the Fisher distribution with parameters n1 and n2, evaluated at .
double barF(double x)
Returns the complementary distribution function.
double getStandardDeviation()
Returns the standard deviation.
double[] getParams()
Return a table containing the parameters of the current distribution.
static double getStandardDeviation(int n1, int n2)
Computes and returns the standard deviation of the Fisher distribution with parameters n1 and n2.
void setParams(int n1, int n2)
Sets the parameters n1 and n2 of this object.
double inverseF(double u)
Returns the inverse distribution function .
static double cdf(int n1, int n2, double x)
Computes the distribution function of the Fisher distribution with parameters n1 and n2,...
static double getVariance(int n1, int n2)
Computes and returns the variance.
static double getMean(int n1, int n2)
Computes and returns the mean of the Fisher distribution with parameters n1 and n2.
String toString()
Returns a String containing information about the current distribution.
double getMean()
Returns the mean.
double getVariance()
Returns the variance.
int getN2()
Returns the parameter n2 of this object.
This class provides various constants and methods to compute numerical quantities such as factorials,...
Definition Num.java:35
static double lnBeta(double lam, double nu)
Computes the natural logarithm of the Beta function .
Definition Num.java:475