Example usage for org.apache.commons.math.distribution DistributionFactory createTDistribution

List of usage examples for org.apache.commons.math.distribution DistributionFactory createTDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math.distribution DistributionFactory createTDistribution.

Prototype

public abstract TDistribution createTDistribution(double degreesOfFreedom);

Source Link

Document

Create a new t distribution with the given degrees of freedom.

Usage

From source file:clus.statistic.RegressionStatBase.java

/**
 * Computes a 2-sample t statistic, without the hypothesis of equal sub-population variances,
 * and returns the p-value of a t test./*from   w  w  w  .  jav a  2 s  .  c  o  m*/
 * t = (m1 - m2) / sqrt(var1/n1 + var2/n2);
 * @param att attribute index
 * @return t p-value
 * @throws MathException
 */
public double getTTestPValue(int att, ClusStatManager stat_manager) throws MathException {
    double global_mean = ((CombStat) stat_manager.getTrainSetStat()).m_RegStat.getMean(att);
    double global_var = ((CombStat) stat_manager.getTrainSetStat()).m_RegStat.getVariance(att);
    double global_n = ((CombStat) stat_manager.getTrainSetStat()).getTotalWeight();
    double local_mean = getMean(att);
    double local_var = getVariance(att);
    double local_n = getTotalWeight();
    double t = Math.abs(local_mean - global_mean) / Math.sqrt(local_var / local_n + global_var / global_n);
    double degreesOfFreedom = 0;
    degreesOfFreedom = df(local_var, global_var, local_n, global_n);
    DistributionFactory distributionFactory = DistributionFactory.newInstance();
    TDistribution tDistribution = distributionFactory.createTDistribution(degreesOfFreedom);
    return 1.0 - tDistribution.cumulativeProbability(-t, t);
}