/***********************************************************************

	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.siegel_TukeyTest;

import java.util.Arrays;

import javanpst.data.DataDefinitions;
import javanpst.data.structures.dataTable.DataTable;
import javanpst.distributions.DistributionDefinitions;
import javanpst.distributions.common.continuous.NormalDistribution;
import javanpst.distributions.tests.WilcoxonRankSumDistribution;
import javanpst.tests.StatisticalTest;

/**
 * The Siegel-Tukey 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 Siegel-Tukey test ranks elements using the same set of weights 
 * defined for the Wilcoxon Ranks-Sum test. 
 *
 * An approximation to the Normal distribution is employed to 
 * compute asymptotic p-values. Exact p-values, if the size of
 * both samples is lower than 10, are also computed
 * 
 * @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
 * @version 1.0
 */
public class Siegel_TukeyTest extends StatisticalTest{

	/**
	 * Wilcoxon distribution for exact version of the test
	 */
	private WilcoxonRankSumDistribution distribution;
	
	/**
	 * 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 int weights [];
	
	/**
	 * Sum of weights
	 */
	private double sumWeights;
	
	/**
	 * Test statistics for first and second samples
	 */
	private double ST1,ST2;
	
	/**
	 * Left tail exact p-value
	 */
	private double exactLeftTail;
	
	/**
	 * Right tail exact p-value
	 */
	private double exactRightTail;
	
	/**
	 * Double tail exact p-value
	 */
	private double exactDoubleTail;
	
	/**
	 * Left tail p-value
	 */
	private double asymptoticLeftTail;
	
	/**
	 * Right tail p-value
	 */
	private double asymptoticRightTail;
	
	/**
	 * Double tail p-value
	 */
	private double asymptoticDoubleTail;
	
	/**
	 * Default builder
	 */
	public Siegel_TukeyTest(){
		
		distribution=WilcoxonRankSumDistribution.getInstance();
		setReportFormat();
		clearData();
		
	}//end-method	
	
	/**
	 * Clears the data stored in the test
	 */
	public void clearData(){
		
		data=new DataTable();
		
		performed=false;
		dataReady=false;
		
		ST1=0.0;
		ST2=0.0;
		
		sample1=null;
		sample2=null;
		weights=null;
		
		exactLeftTail=-1.0;
		exactRightTail=-1.0;
		exactDoubleTail=-1.0;
		asymptoticLeftTail=-1.0;
		asymptoticRightTail=-1.0;
		asymptoticDoubleTail=-1.0;
		
	}//end-method

	/**
	 * Builder. Load data to test.
	 * 
	 * @param newData data to test.
	 */
	public Siegel_TukeyTest(DataTable newData){
		
		int nulls;
		int counter1, counter2;
		double value;
		
		setReportFormat();
		distribution=WilcoxonRankSumDistribution.getInstance();

		data=DataTable.newInstance(newData);
		
		if(data.getColumns()!=2){
			System.out.println("Siegel-Tukey 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.