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

	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.multiple.pageTest;

import java.util.Arrays;
import javanpst.data.structures.dataTable.DataTable;
import javanpst.distributions.tests.PageDistribution;
import javanpst.tests.StatisticalTest;

/**
 * The Page's test.
 * 
 * This test can be applied to reject as null hypothesis that the n medians
 * of the treatments (columns) are equal when applied to k blocks (rows).
 * 
 * Alternative states that treatments' median are set in increasing order
 * 
 * Ties are broken by the midrank method (e.g. a tie in ranks 6 and 7 is assumed
 * as a 6.5 rank for both values).   
 * 
 * @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
 * @version 1.0
 */
public class PageTest extends StatisticalTest{

	/**
	 * Distribution of the test
	 */
	private PageDistribution distribution;
	
	/**
	 * Data to analyze
	 */
	private DataTable data;
	
	/**
	 * Populations samples
	 */
	private double samples [][];
	
	/**
	 * Array of ranks
	 */
	private double ranks [][];
	
	/**
	 * Sum of ranks for each population
	 */
	private double sumRanks[];
	
	/**
	 * L statistic
	 */
	private double L;
	
	/**
	 * Asymptotic p-value
	 */
	private double asymptoticPValue;
	
	/**
	 * Exact p-value
	 */
	private double exactPValue;

	/**
	 * Default builder
	 */
	public PageTest(){

		distribution=PageDistribution.getInstance();
		setReportFormat();
		clearData();
		
	}//end-method
	
	/**
	 * Clears the data stored in the test
	 */
	public void clearData(){
		
		data=new DataTable();
		
		performed=false;
		dataReady=false;
		
		L=0.0;

		samples=null;
		ranks=null;
		sumRanks=null;
		
		asymptoticPValue=-1.0;
		exactPValue=-1.0;
		
	}//end-method
	
	/**
	 * Builder. Load data to test.
	 * 
	 * @param newData data to test.
	 */
	public PageTest(DataTable newData){
		
		distribution=PageDistribution.getInstance();
		setReportFormat();
		
		data=DataTable.newInstance(newData);
		
		if(data.getColumns()<3){
			System.out.println("Extended median test only can be employed with more than two samples");
			clearData();
			return;
		}
		
		for(int i=0;i0){
				System.out.println("No null values allowed in this test.");
				clearData();
				return;
			}
		}
		
		samples=new double[data.getRows()][data.getColumns()];
		ranks=new double[data.getRows()][data.getColumns()];
		sumRanks=new double[data.getColumns()];
		
		for(int i=0;i0){
				System.out.println("No null values allowed in this test.");
				clearData();
				return;
			}
		}
		
		samples=new double[data.getRows()][data.getColumns()];
		ranks=new double[data.getRows()][data.getColumns()];
		sumRanks=new double[data.getColumns()];
		
		for(int i=0;i 

Ads help maintain this website.