All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.maizegenetics.stats.statistics.ChiSquareTest Maven / Gradle / Ivy

Go to download

TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage disequilibrium.

There is a newer version: 5.2.94
Show newest version
// ChiSquareTest.java
//
// (c) 1999-2001 PAL Development Core Team
//
// This package may be distributed under the
// terms of the Lesser GNU General Public License (LGPL)


package net.maizegenetics.stats.statistics;




/**
 * chi-square test
 *
 * @version $Id: ChiSquareTest.java,v 1.1 2007/01/12 03:26:16 tcasstevens Exp $
 *
 * @author Korbinian Strimmer
 */
public class ChiSquareTest
{
	//
	// Public stuff
	//
	
	/** 
	 * chi square test
	 *
	 * @param  ef      expected frequencies (sum up to 1 !!)
	 * @param  of      observed frequencies (sum up to the number of samples)
	 *
	 * @return critical significance level (negative if in chi2 test may be invalid)
	 */
	public static double compare(double[] ef, int[] of)
	{	
		int samples;
		boolean chi2failed = false;
		
		/* compute number of samples */
		samples = 0;
		for (int i = 0; i  0)
		{
			chi2failed = true;
		}
		/* no more than 1/5 of the frequency categories below 5.0 */
		if (below5 > (int) Math.floor(samples/5.0))
		{
			chi2failed = true;
		}
	
		if (chi2failed)
		{
			return -criticals;
		}
		else
		{
			return criticals;
		}
	}
	
	/**
	 * probability that the observed chi-square
	 * exceeds chi2 even if model is correct
	 *
	 * @param deg degrees of freedom
	 * @param chi2 chi-square
	 *
	 * @return probability
	 */
	private static double chi2prob (int deg, double chi2)
	{
		return 1.0-ChiSquareDistribution.cdf(chi2, deg);
	}	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy