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

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

import java.util.Arrays;

import javanpst.data.structures.dataTable.DataTable;
import javanpst.distributions.common.continuous.ChiSquareDistribution;
import javanpst.distributions.common.continuous.NormalDistribution;
import javanpst.tests.StatisticalTest;

/**
 * The Friedman'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).
 * 
 * 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). Variance of the statistic is adjusted as a 
 * consequence of ties 
 * 
 * A multiple-comparisons procedure (Bonferroni-Dunn), applied at 0.10 and 0.05
 * levels of significance is also provided.  
 * 
 * @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
 * @version 1.0
 */
public class FriedmanTest extends StatisticalTest{

	/**
	 * 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[];
	
	/**
	 * Average rank for each population
	 */
	private double avgRanks[];
	
	/**
	 * S statistic
	 */
	private double S;
	
	/**
	 * Q statistic
	 */
	private double Q;
	
	/**
	 * Reduction to variance of Q due to ties
	 */
	private double tiesWeight;
	
	/**
	 * P-value
	 */
	private double pValue;
	
	/**
	 * Critical value at 0.90 confidence level
	 */
	private double criticalZ90;
	
	/**
	 * Critical value at 0.95 confidence level
	 */
	private double criticalZ95;
	
	/**
	 * Default builder
	 */
	public FriedmanTest(){

		setReportFormat();
		clearData();
		
	}//end-method
	
	/**
	 * Clears the data stored in the test
	 */
	public void clearData(){
		
		data=new DataTable();
		
		performed=false;
		dataReady=false;
		
		S=0.0;
		Q=0.0;
		
		samples=null;
		ranks=null;
		sumRanks=null;
		avgRanks=null;
		
		pValue=-1.0;
		
	}//end-method
	
	/**
	 * Builder. Load data to test.
	 * 
	 * @param newData data to test.
	 */
	public FriedmanTest(DataTable newData){
		
		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()];
		avgRanks=new double [sumRanks.length];
		
		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()];
		avgRanks=new double [sumRanks.length];
		
		for(int i=0;i-1)&&((pop-1) 

Ads help maintain this website.