Search in sources :

Example 1 with Exponential

use of edu.cmu.tetrad.util.dist.Exponential in project tetrad by cmu-phil.

the class QQPlot method testPlot.

// ============================ Private Methods =======================//
/**
 * Used to test this class.
 *
 * Generates a continuous test variable and q-q plots it.
 */
private void testPlot() {
    ContinuousVariable c = new ContinuousVariable("test");
    if (dataSet.getVariable("test") == null)
        dataSet.addVariable(c);
    ContinuousVariable c2 = new ContinuousVariable("test2");
    if (dataSet.getVariable("test2") == null)
        dataSet.addVariable(c2);
    this.selectedVariable = c;
    int columnIndex = dataSet.getColumn(c);
    Normal g = new Normal(1, 1);
    Exponential e = new Exponential(1);
    double mean = 0.0;
    double sd = 0.0;
    this.minData = 10000000000000.0;
    this.maxData = 0.0;
    this.minComparison = 1000000000000.0;
    this.maxComparison = 0.0;
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        double value = g.nextRandom();
        double value2 = e.nextRandom();
        dataSet.setDouble(i, columnIndex, value);
        dataSet.setDouble(i, columnIndex + 1, value2);
        mean += value;
        if (value < this.minData)
            this.minData = value;
        if (value > this.maxData)
            this.maxData = value;
    // System.out.println(value);
    // System.out.println(mean);
    }
    // System.out.println(this.dataSet.getNumRows());
    NormalityTests.kolmogorovSmirnov(dataSet, c2);
    // sort the dataset
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        for (int k = i; k < dataSet.getNumRows(); k++) {
            if (dataSet.getDouble(i, columnIndex) > dataSet.getDouble(k, columnIndex)) {
                double temp = dataSet.getDouble(i, columnIndex);
                dataSet.setDouble(i, columnIndex, dataSet.getDouble(k, columnIndex));
                dataSet.setDouble(k, columnIndex, temp);
            }
        }
    }
    if (mean == 0.0)
        mean = 1.0;
    else
        mean /= dataSet.getNumRows();
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        sd += (dataSet.getDouble(i, columnIndex) - mean) * (dataSet.getDouble(i, columnIndex) - mean);
    // System.out.println(dataSet.getDouble(i, columnIndex));
    // System.out.println(sd);
    }
    if (sd == 0.0) {
        sd = 1.0;
    } else {
        sd /= dataSet.getNumRows() - 1.0;
        sd = Math.sqrt(sd);
    }
    // System.out.println("Mean: " + mean + " SD: " + sd + " Min: " + this.minData + " Max: " + this.maxData);
    this.comparison = new cern.jet.random.Normal(mean, sd, new MersenneTwister());
    calculateComparisonSet(this.comparison, this.dataSet);
    if (this.minData < this.minComparison)
        this.min = this.minData;
    else
        this.min = this.minComparison;
    if (this.maxData > this.maxComparison)
        this.max = this.maxData;
    else
        this.max = this.maxComparison;
// end test code
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Exponential(edu.cmu.tetrad.util.dist.Exponential) Normal(edu.cmu.tetrad.util.dist.Normal) MersenneTwister(cern.jet.random.engine.MersenneTwister)

Aggregations

MersenneTwister (cern.jet.random.engine.MersenneTwister)1 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)1 Exponential (edu.cmu.tetrad.util.dist.Exponential)1 Normal (edu.cmu.tetrad.util.dist.Normal)1