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

	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.location.normalScoresTest;

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 Normal scores test.
 * 
 * The Normal scores test (van der Warden test) uses
 * inverse normal scores to asign ranks to data, before
 * testing the null hypothesis of equal location.
 * 
 * P-value is computed through a normal approximation.
 * 
 * Ties are handled by the midranks method, and an appropriate
 * reduction of variance is considered.
 *  
 * @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
 * @version 1.0
 */
public class NormalScoresTest 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 [];
	
	/**
	 * Ties array
	 */
	private boolean ties [];
	
	/**
	 * Test statistic for the first sample
	 */
	private double normalStatistic;
	
	/**
	 * Test statistic for the second sample
	 */
	private double normalStatistic2;
	
	/**
	 * Left tail p-value
	 */
	private double asymptoticLeft;
	
	/**
	 * Right tail p-value
	 */
	private double asymptoticRight;
	
	/**
	 * Double tail p-value
	 */
	private double asymptoticDouble;
	
	/**
	 * A normal distribution is used to asign the ranks
	 */
	private NormalDistribution normal;
	
	/**
	 * Default builder
	 */
	public NormalScoresTest(){
		
		setReportFormat();
		clearData();
		
	}//end-method
	
	/**
	 * Clears the data stored in the test
	 */
	public void clearData(){
		
		data=new DataTable();
		
		performed=false;
		dataReady=false;
		
		normalStatistic=0.0;
		normalStatistic2=0.0;
		
		sample1=null;
		sample2=null;
		
		asymptoticLeft=-1.0;
		asymptoticRight=-1.0;
		asymptoticDouble=-1.0;
		
	}//end-method
	
	/**
	 * Builder. Load data to test.
	 * 
	 * @param newData data to test.
	 */
	public NormalScoresTest(DataTable newData){
		
		int nulls;
		int counter1, counter2;
		double value;
		
		setReportFormat();
		
		data=DataTable.newInstance(newData);
		
		if(data.getColumns()!=2){
			System.out.println("Normal Scores 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.