/***********************************************************************
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.mcNemarTest;
import javanpst.data.structures.dataTable.DataTable;
import javanpst.distributions.tests.McNemarDistribution;
import javanpst.tests.StatisticalTest;
/**
* The McNemar test.
*
* This test can be applied to determine whether the row and column marginal frequencies
* of a 2 x 2 contingency table are equal.
*
* Three approximations are provided:
*
* - Exact p-value (through a binomial distribution)
* - Asymptotic p-value (through a normal distribution)
* - Asymptotic p-value (through a chi-square distribution)
*
* @author Joaqu�n Derrac Rus (jderrac@decsai.ugr.es)
* @version 1.0
*/
public class McNemarTest extends StatisticalTest{
/**
* Distribution of the test
*/
private McNemarDistribution distribution;
/**
* Data to analyze
*/
private DataTable data;
/**
* Contingency matrix
*/
private double contingencyTable [][];
/**
* S statistic (Binomial)
*/
private double S;
/**
* Exact p-value
*/
private double exactPValue;
/**
* Z statistic (Normal)
*/
private double Z;
/**
* Asymptotic p-value (Normal)
*/
private double asymptoticNormalPValue;
/**
* T statistic (Chi-square)
*/
private double T;
/**
* Asymptotic p-value (Chi-square)
*/
private double asymptoticChiPValue;
/**
* Default builder
*/
public McNemarTest(){
distribution=McNemarDistribution.getInstance();
setReportFormat();
clearData();
}//end-method
/**
* Clears the data stored in the test
*/
public void clearData(){
data=new DataTable();
performed=false;
dataReady=false;
T=0.0;
Z=0.0;
S=0.0;
contingencyTable=null;
asymptoticChiPValue=-1.0;
asymptoticNormalPValue=-1.0;
exactPValue=-1.0;
}//end-method
/**
* Builder. Load data to test.
*
* @param newData data to test.
*/
public McNemarTest(DataTable newData){
distribution=McNemarDistribution.getInstance();
setReportFormat();
data=DataTable.newInstance(newData);
if((data.getColumns()>2)||(data.getColumns()<2)||(data.getRows()>2)||(data.getRows()<2)){
System.out.println("Data must be represented in two rows and two columns");
clearData();
return;
}
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;i2)||(data.getColumns()<2)||(data.getRows()>2)||(data.getRows()<2)){
System.out.println("Data must be represented in two rows and two columns");
clearData();
return;
}
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.