Example usage for org.apache.commons.math3.distribution ChiSquaredDistribution inverseCumulativeProbability

List of usage examples for org.apache.commons.math3.distribution ChiSquaredDistribution inverseCumulativeProbability

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution ChiSquaredDistribution inverseCumulativeProbability.

Prototype

public double inverseCumulativeProbability(final double p) throws OutOfRangeException 

Source Link

Document

The default implementation returns
  • #getSupportLowerBound() for p = 0 ,
  • #getSupportUpperBound() for p = 1 .

Usage

From source file:ch.unil.genescore.vegas.test.AnalyticVegasTest.java

public void computeTestStatisticRealTest() {

    DenseMatrix ld = new DenseMatrix(3, 3);
    ld.set(0, 0, 1);/*from   w  w  w .ja va 2s  .c om*/
    ld.set(1, 1, 1);
    ld.set(2, 2, 1);
    ld.set(0, 1, 0.9);
    ld.set(1, 2, 0.9);
    ld.set(1, 0, 0.9);
    ld.set(2, 1, 0.9);
    ld.set(0, 2, 0.81);
    ld.set(2, 0, 0.81);

    //double delta = 0.00001;
    Snp fakeSnp1 = new Snp("fakeId1", 0.7641772, 0);
    Snp fakeSnp2 = new Snp("fakeId2", 0.4237108, 0);
    Snp fakeSnp3 = new Snp("fakeId3", 0.1615133, 0);
    Pascal.set.withZScore_ = false;
    ArrayList<Snp> geneSnps = new ArrayList<Snp>();
    geneSnps.add(fakeSnp1);
    geneSnps.add(fakeSnp2);
    geneSnps.add(fakeSnp3);
    //
    ChiSquaredDistribution chiSquareDist1 = new ChiSquaredDistribution(1);
    ArrayList<Double> chiSquaredVals = new ArrayList<Double>();
    chiSquaredVals.add(chiSquareDist1.inverseCumulativeProbability(1 - fakeSnp1.getPval()));
    chiSquaredVals.add(chiSquareDist1.inverseCumulativeProbability(1 - fakeSnp2.getPval()));
    chiSquaredVals.add(chiSquareDist1.inverseCumulativeProbability(1 - fakeSnp3.getPval()));
    //cumulativeProbability(chiStat);
    double[] emptyWeights = { 1, 1, 1 };
    AnalyticVegas myAnalyticObj = new AnalyticVegas(chiSquaredVals, ld, emptyWeights);
    myAnalyticObj.computeScore();

    myAnalyticObj.computeTestStatisticReal();
    double firstRes = myAnalyticObj.getTestStatisticReal();

    //Snp fakeSnp1_1 = new Snp("fakeId1", 0, 0.3);
    //Snp fakeSnp2_1 = new Snp("fakeId2", 0, 0.8);
    //Snp fakeSnp3_1 = new Snp("fakeId3", 0, 1.4);
    Pascal.set.withZScore_ = false;
    ArrayList<Double> zscores = new ArrayList<Double>();
    zscores.add(0.3);
    zscores.add(0.8);
    zscores.add(1.4);

    //geneSnps_1.add(fakeSnp1_1);geneSnps_1.add(fakeSnp2_1);geneSnps_1.add(fakeSnp3_1);
    AnalyticVegas myAnalyticObj_1 = new AnalyticVegas(zscores, ld, emptyWeights);
    myAnalyticObj.computeScore();
    myAnalyticObj_1.computeTestStatisticReal();
    double secRes = myAnalyticObj_1.getTestStatisticReal();
    assertEquals(firstRes, secRes, 1E-4);
}

From source file:net.atos.ari.vital.taastrustcalculator.StatisticsCalculator.java

public boolean calculateNumericVariance(double[] values) {
    double alpha = 0.05;
    double mean = StatUtils.mean(values);
    double variance = StatUtils.variance(values);
    double expected = Math.pow(mean * 0.05, 2);
    //double expected = 0.01;
    double degFreedom = values.length - 1.0;

    double T = (degFreedom * variance) / expected;
    logger.debug("Mean = " + mean);
    logger.debug("Standard Deviation = " + Math.sqrt(variance));
    logger.debug("Test Statistic calculated T = " + T);

    if (degFreedom <= 0)
        return false;
    ChiSquaredDistribution myDist = new ChiSquaredDistribution(degFreedom);
    double myTLeft = myDist.inverseCumulativeProbability(alpha / 2.0);
    double myTRight = myDist.inverseCumulativeProbability(1.0 - alpha / 2.0);

    logger.debug("Boundaries: " + myTLeft + " to " + myTRight);

    // Determine if z score is in the region of acceptance
    if ((myTLeft <= T) && (T <= myTRight)) {
        // H0 -> Variance of the data is equal to the expected one
        return true;
    }/*  w ww.  ja  v  a  2 s  . c om*/

    // H1 -> Variance of the data is different to the expected one
    return false;
}

From source file:eu.betaas.taas.securitymanager.taastrustmanager.taastrustcalculator.StatisticsCalculator.java

public boolean calculateNumericVariance(double[] values) {
    double alpha = 0.05;
    double mean = StatUtils.mean(values);
    double variance = StatUtils.variance(values);
    double expected = Math.pow(mean * 0.05, 2);
    //double expected = 0.01;
    double degFreedom = values.length - 1.0;

    double T = (degFreedom * variance) / expected;
    logger.debug("Mean = " + mean);
    logger.debug("Standard Deviation = " + Math.sqrt(variance));
    logger.debug("Test Statistic calculated T = " + T);

    ChiSquaredDistribution myDist = new ChiSquaredDistribution(degFreedom);
    double myTLeft = myDist.inverseCumulativeProbability(alpha / 2.0);
    double myTRight = myDist.inverseCumulativeProbability(1.0 - alpha / 2.0);

    logger.debug("Boundaries: " + myTLeft + " to " + myTRight);

    // Determine if z score is in the region of acceptance
    if ((myTLeft <= T) && (T <= myTRight)) {
        // H0 -> Variance of the data is equal to the expected one
        return true;
    }//from  www  .j av  a2  s.c o  m

    // H1 -> Variance of the data is different to the expected one
    return false;
}

From source file:ID3Chi.java

/**
 * Method for building an ID3Chi tree./* w ww  .  j a  v  a  2 s. c o  m*/
 *
 * @param data
 *            the training data
 * @exception Exception
 *                if decision tree can't be built successfully
 */
private void makeTree(Instances data) throws Exception {

    // Check if no instances have reached this node.
    /*
    if (data.numInstances() == 0) {
       m_Attribute = null;
       m_ClassValue = Instance.missingValue();
       m_Distribution = new double[data.numClasses()];
       return;
    }
    /**/
    if (data.numInstances() == 0) {
        SetNullDistribution(data);
    }

    // Compute attribute with maximum information gain.
    double[] infoGains = new double[data.numAttributes()];
    Enumeration attEnum = data.enumerateAttributes();
    double entropyOfAllData = computeEntropy(data);

    while (attEnum.hasMoreElements()) {
        Attribute att = (Attribute) attEnum.nextElement();
        infoGains[att.index()] = computeInfoGain(data, att, entropyOfAllData);
    }
    m_Attribute = data.attribute(Utils.maxIndex(infoGains));

    double chiSquare = computeChiSquare(data, m_Attribute);

    int degreesOfFreedom = m_Attribute.numValues() - 1;
    ChiSquaredDistribution chi = new ChiSquaredDistribution(degreesOfFreedom);
    double threshold = chi.inverseCumulativeProbability(m_confidenceLevel);

    // Make leaf if information gain is zero.
    // Otherwise create successors.
    if (Utils.eq(infoGains[m_Attribute.index()], 0)) {
        MakeALeaf(data);
    } else {
        // Discard unknown values for selected attribute
        //data.deleteWithMissing(m_Attribute);
        Instances[] subset = splitData(data, m_Attribute);

        if (CheckIfCanApplyChiSquare(subset) && (chiSquare <= threshold)) {
            MakeALeaf(data);
            return;
        }

        m_Successors = new ID3Chi[m_Attribute.numValues()];
        for (int j = 0; j < m_Attribute.numValues(); j++) {
            m_Successors[j] = new ID3Chi(this.m_confidenceLevel);
            m_Successors[j].m_Ratio = (double) subset[j].numInstances() / (double) data.numInstances();
            m_Successors[j].makeTree(subset[j]);
        }
    }
}

From source file:org.apache.sysml.runtime.compress.estim.CompressedSizeEstimatorSample.java

private static void computeCriticalValue(int sampleSize) {
    ChiSquaredDistribution chiSqr = new ChiSquaredDistribution(sampleSize - 1);
    uniformityCriticalValue = chiSqr.inverseCumulativeProbability(SHLOSSER_JACKKNIFE_ALPHA);
    usedSampleSize = sampleSize;/*from   w  w w  . j  a  v a2  s . c  om*/
}