/***********************************************************************
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.scale.freund_Ansari_BradleyTest;
import java.util.Arrays;
import javanpst.data.DataDefinitions;
import javanpst.data.structures.dataTable.DataTable;
import javanpst.distributions.common.continuous.NormalDistribution;
import javanpst.tests.StatisticalTest;
/**
* The Freund-Ansari-Bradley test.
*
* Assuming the scale model (equal medians), this test can be
* employed to test whether the two distributions selected have
* equal scale parameter (with the null hypothesis of equality).
*
* The Freund-Ansari-Bradley test ranks elements with the following weights:
*
* 1,2,3 ... N/2 ... 3,2,1 for N even
* 1,2,3 ... (N+1/2) ... 3,2,1 for N odd
*
* An approximation to the Normal distribution is employed to
* compute p-values.
*
* @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
* @version 1.0
*/
public class Freund_Ansari_BradleyTest extends StatisticalTest{
/**
* Data to analyze
*/
private DataTable data;
/**
* First sample
*/
private double sample1 [];
/**
* Second sample
*/
private double sample2 [];
/**
* Number of values of each sample
*/
private int values1,values2;
/**
* Array of combined sample
*/
private double combined [];
/**
* Number of values in both samples
*/
private int N;
/**
* Array of weights
*/
private double weights [];
/**
* Sum of weights
*/
private double sumWeights;
/**
* Test statistics
*/
private double MNx,MNy;
/**
* Left tail p-value
*/
private double asymptoticLeftTail;
/**
* Right tail p-value
*/
private double asymptoticRightTail;
/**
* Double tail p-value
*/
private double asymptoticDoubleTail;
/**
* Default builder
*/
public Freund_Ansari_BradleyTest(){
setReportFormat();
clearData();
}//end-method
/**
* Clears the data stored in the test
*/
public void clearData(){
data=new DataTable();
performed=false;
dataReady=false;
MNx=0.0;
MNy=0.0;
sample1=null;
sample2=null;
weights=null;
asymptoticLeftTail=-1.0;
asymptoticRightTail=-1.0;
asymptoticDoubleTail=-1.0;
}//end-method
/**
* Builder. Load data to test.
*
* @param newData data to test.
*/
public Freund_Ansari_BradleyTest(DataTable newData){
int nulls;
int counter1, counter2;
double value;
setReportFormat();
data=DataTable.newInstance(newData);
if(data.getColumns()!=2){
System.out.println("Freund-Ansari-Bradley test only can be employed with two samples");
clearData();
return;
}
nulls=data.getColumnNulls(0);
values1=data.getRows()-nulls;
sample1=new double [values1];
nulls=data.getColumnNulls(1);
values2=data.getRows()-nulls;
sample2=new double [values2];
counter1=0;
counter2=0;
for(int i=0;i
Ads help maintain this website.