package com.imsl.test.example.stat; import com.imsl.stat.*; /** *
* Generates a pseudorandom sample from a normal distribution and performs a * goodness of fit test. *
* * In this example, a normal random sample of size 1000 is generated via *Random.nextGaussian
. Random.setSeed
is first used
* to set the seed. After the ChiSquaredTest
constructor is called,
* the random observations are added to the test one at a time to simulate
* streaming data. The Chi-squared test is performed using
* Cdf.normal
as the cumulative distribution function object to see
* how well the random numbers fit the normal distribution.
*
*
* @see Code
* @see Output
*/
public class RandomEx1 implements CdfFunction {
@Override
public double cdf(double x) {
return Cdf.normal(x);
}
public static void main(String args[]) throws Exception {
int nObservations = 1000;
Random r = new Random(123457L);
ChiSquaredTest test = new ChiSquaredTest(new RandomEx1(), 10, 0);
for (int k = 0; k < nObservations; k++) {
test.update(r.nextNormal(), 1.0);
}
double p = test.getP();
System.out.println("The P-value is " + p);
}
}