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

	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.countData.contingencyCoefficient;

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

/**
 * A contingency coefficient-based test.
 * 
 * This procedure test that row and columns of a n x m 
 * contingency coefficient are independent or have no association.
 * 
 * Q statistic (approximated to a chi-square distribution) and C and Phi
 * coefficients are computed.
 * 
 * @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
 * @version 1.0
 */
public class ContingencyCoefficient extends StatisticalTest{

	/**
	 * Data to analyze
	 */
	private DataTable data;
	
	/**
	 * Contingency matrix
	 */
	private double contingencyTable [][];
	
	/**
	 * Number of elements
	 */
	private double N;
	
	/**
	 * Q statistic
	 */
	private double Q;

	/**
	 * P-value
	 */
	private double pValue;
	
	/**
	 * C contingency coefficient
	 */
	private double C;
	
	/**
	 * Phi contingency coefficient
	 */
	private double phi;
	
	/**
	 * Default builder
	 */
	public ContingencyCoefficient(){

		setReportFormat();
		clearData();
		
	}//end-method
	
	/**
	 * Clears the data stored in the test
	 */
	public void clearData(){
		
		data=new DataTable();
		
		performed=false;
		dataReady=false;
		
		Q=0.0;
		C=0.0;
		phi=0.0;
		
		contingencyTable=null;
		
		pValue=-1.0;
		
	}//end-method
	
	/**
	 * Builder. Load data to test.
	 * 
	 * @param newData data to test.
	 */
	public ContingencyCoefficient(DataTable newData){
		
		setReportFormat();
		
		data=DataTable.newInstance(newData);
		
		for(int i=0;i0){
				System.out.println("No null values allowed in this test.");
				clearData();
				return;
			}
		}
		
		contingencyTable=new double[data.getRows()][data.getColumns()];
		
		for(int i=0;i0){
				System.out.println("No null values allowed in this test.");
				clearData();
				return;
			}
		}
		
		contingencyTable=new double[data.getRows()][data.getColumns()];
		
		for(int i=0;i 

Ads help maintain this website.