2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.math.distribution;
21
* Test cases for FDistribution.
22
* Extends ContinuousDistributionAbstractTest. See class javadoc for
23
* ContinuousDistributionAbstractTest for details.
25
* @version $Revision: 762087 $ $Date: 2009-04-05 10:20:18 -0400 (Sun, 05 Apr 2009) $
27
public class FDistributionTest extends ContinuousDistributionAbstractTest {
30
* Constructor for FDistributionTest.
33
public FDistributionTest(String name) {
37
//-------------- Implementations for abstract methods -----------------------
39
/** Creates the default continuous distribution instance to use in tests. */
41
public ContinuousDistribution makeDistribution() {
42
return new FDistributionImpl(5.0, 6.0);
45
/** Creates the default cumulative probability distribution test input values */
47
public double[] makeCumulativeTestPoints() {
48
// quantiles computed using R version 1.8.1 (linux version)
49
return new double[] {0.03468084d ,0.09370091d, 0.1433137d,
50
0.2020084d, 0.2937283d, 20.80266d, 8.745895d, 5.987565d,
51
4.387374d, 3.107512d};
54
/** Creates the default cumulative probability density test expected values */
56
public double[] makeCumulativeTestValues() {
57
return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d,
58
0.990d, 0.975d, 0.950d, 0.900d};
61
// --------------------- Override tolerance --------------
63
protected void setUp() throws Exception {
68
//---------------------------- Additional test cases -------------------------
70
public void testCumulativeProbabilityExtremes() throws Exception {
71
setCumulativeTestPoints(new double[] {-2, 0});
72
setCumulativeTestValues(new double[] {0, 0});
73
verifyCumulativeProbabilities();
76
public void testInverseCumulativeProbabilityExtremes() throws Exception {
77
setInverseCumulativeTestPoints(new double[] {0, 1});
78
setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY});
79
verifyInverseCumulativeProbabilities();
82
public void testDfAccessors() {
83
FDistribution distribution = (FDistribution) getDistribution();
84
assertEquals(5d, distribution.getNumeratorDegreesOfFreedom(), Double.MIN_VALUE);
85
distribution.setNumeratorDegreesOfFreedom(4d);
86
assertEquals(4d, distribution.getNumeratorDegreesOfFreedom(), Double.MIN_VALUE);
87
assertEquals(6d, distribution.getDenominatorDegreesOfFreedom(), Double.MIN_VALUE);
88
distribution.setDenominatorDegreesOfFreedom(4d);
89
assertEquals(4d, distribution.getDenominatorDegreesOfFreedom(), Double.MIN_VALUE);
91
distribution.setNumeratorDegreesOfFreedom(0d);
92
fail("Expecting IllegalArgumentException for df = 0");
93
} catch (IllegalArgumentException ex) {
97
distribution.setDenominatorDegreesOfFreedom(0d);
98
fail("Expecting IllegalArgumentException for df = 0");
99
} catch (IllegalArgumentException ex) {
104
public void testLargeDegreesOfFreedom() throws Exception {
105
org.apache.commons.math.distribution.FDistributionImpl fd =
106
new org.apache.commons.math.distribution.FDistributionImpl(
108
double p = fd.cumulativeProbability(.999);
109
double x = fd.inverseCumulativeProbability(p);
110
assertEquals(.999, x, 1.0e-5);
113
public void testSmallDegreesOfFreedom() throws Exception {
114
org.apache.commons.math.distribution.FDistributionImpl fd =
115
new org.apache.commons.math.distribution.FDistributionImpl(
117
double p = fd.cumulativeProbability(0.975);
118
double x = fd.inverseCumulativeProbability(p);
119
assertEquals(0.975, x, 1.0e-5);
121
fd.setDenominatorDegreesOfFreedom(2.0);
122
p = fd.cumulativeProbability(0.975);
123
x = fd.inverseCumulativeProbability(p);
124
assertEquals(0.975, x, 1.0e-5);