/***********************************************************************
This file is part of JavaNPST, a Java library of NonParametric
Statistical Tests.
Copyright (C) 2011
J. Derrac (jderrac@decsai.ugr.es)
S. Garcia (sglopez@ujaen.es)
F. Herrera (herrera@decsai.ugr.es)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
**********************************************************************/
package javanpst.tests.goodness.lillieforsTest;
import javanpst.data.structures.sequence.NumericSequence;
import javanpst.distributions.DistributionDefinitions;
import javanpst.distributions.common.continuous.ExponentialDistribution;
import javanpst.distributions.common.continuous.NormalDistribution;
import javanpst.distributions.tests.LillieforsDistribution;
import javanpst.tests.StatisticalTest;
/**
* The Lilliefors test.
*
* This goodness of fit test can be used to adjust a given
* sample to a Normal distribution, with unknown mean and
* sigma parameters. Adjustment to an Exponential distribution,
* with unknown mean, is also possible.
*
* @author Joaquin
* @version 1.0
*/
public class LillieforsTest extends StatisticalTest{
/**
* Distribution of the test
*/
private LillieforsDistribution distribution;
/**
* Sample to adjust
*/
private NumericSequence sequence;
/**
* Sequence quantiles
*/
private double Sn [];
/**
* True distribution selected
*/
private double F0 [];
/**
* Test statistic
*/
private double Dn;
/**
* Tests if the distribution to adjust is defined
*/
private boolean distributionReady;
/**
* Distribution to adjust
*/
private int typeDist;
/**
* Normal distribution
*/
private NormalDistribution normal;
/**
* P-value of the adjustment
*/
private double pValue;
/**
* Exponential distribution
*/
private ExponentialDistribution exponential;
/**
* Default builder
*/
public LillieforsTest(){
distribution= LillieforsDistribution.getInstance();
setReportFormat();
clearData();
}//end-method
/**
* Clears the data stored in the test
*/
public void clearData(){
sequence=new NumericSequence();
performed=false;
dataReady=false;
distributionReady=false;
typeDist=-1;
Dn=0.0;
F0=null;
Sn=null;
pValue=-1.0;
}//end-method
/**
* Builder. Load data to test.
*
* @param newSequence data to test.
*/
public LillieforsTest(NumericSequence newSequence){
distribution= LillieforsDistribution.getInstance();
setReportFormat();
sequence=new NumericSequence(newSequence);
sequence.sort();
Sn=new double [sequence.size()];
F0=new double [sequence.size()];
performed=false;
dataReady=true;
distributionReady=false;
}//end-method
/**
* Load data to test.
*
* @param newSequence data to test.
*/
public void setData(NumericSequence newSequence){
sequence=new NumericSequence(newSequence);
sequence.sort();
Sn=new double [sequence.size()];
F0=new double [sequence.size()];
performed=false;
dataReady=true;
distributionReady=false;
}//end-method
/**
* Sets adjustment to a normal distribution
*/
public void adjustNormal(){
typeDist=DistributionDefinitions.NORMAL;
distributionReady=true;
}//end-method
/**
* Sets adjustment to a exponential distribution
*/
public void adjustExponential(){
typeDist=DistributionDefinitions.EXPONENTIAL;
distributionReady=true;
}//end-method
/**
* Performs the test
*/
public void doTest(){
double value,value2;
if(!dataReady){
System.out.println("Data is not ready");
return;
}
if(!distributionReady){
System.out.println("Distribution to fit is not set");
return;
}
Dn=0.0;
//fill Sn
for(int i=0;i
Ads help maintain this website.