Search in sources :

Example 1 with TetradMatrix

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

the class ScatterPlot method getCorrelationCoeff.

public double getCorrelationCoeff() {
    DataSet dataSet = getDataSet();
    TetradMatrix data = dataSet.getDoubleData();
    int _x = dataSet.getColumn(dataSet.getVariable(x));
    int _y = dataSet.getColumn(dataSet.getVariable(y));
    double[] xdata = data.getColumn(_x).toArray();
    double[] ydata = data.getColumn(_y).toArray();
    double correlation = StatUtils.correlation(xdata, ydata);
    if (correlation > 1)
        correlation = 1;
    else if (correlation < -1)
        correlation = -1;
    return correlation;
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix)

Example 2 with TetradMatrix

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

the class BooleanGlassGeneIm method asTimeSeriesData.

private TimeSeriesData asTimeSeriesData(double[][][] cube, int cell, List<String> factors) {
    int numTimeSteps = cube[0].length;
    int numFactors = cube.length;
    double[][] square = new double[numTimeSteps][numFactors];
    for (int timeStep = 0; timeStep < numTimeSteps; timeStep++) {
        for (int factor = 0; factor < numFactors; factor++) {
            square[timeStep][factor] = cube[factor][timeStep][cell];
        }
    }
    List<String> varNames = new ArrayList<>();
    for (int i = 0; i < numFactors; i++) {
        varNames.add(factors.get(i));
    }
    return new TimeSeriesData(new TetradMatrix(square), varNames);
}
Also used : ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix)

Example 3 with TetradMatrix

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

the class ExploreAutisticsNeurotypicals method printDataTranspose.

private static void printDataTranspose(String path, String prefix, DataSet dataSet) {
    List<Node> nodes = dataSet.getVariables();
    Node group = dataSet.getVariable("Group");
    List<Node> _nodes = new ArrayList<>();
    for (int i = 0; i < nodes.size(); i++) {
        if (nodes.get(i) == group) {
            _nodes.add(group);
        } else {
            _nodes.add(new ContinuousVariable("X" + (i + 1)));
        }
    }
    TetradMatrix m = dataSet.getDoubleData();
    TetradMatrix mt = m.transpose();
    List<Node> tvars = new ArrayList<>();
    for (int i = 0; i < mt.columns(); i++) tvars.add(new ContinuousVariable("S" + (i + 1)));
    dataSet = new BoxDataSet(new DoubleDataBox(mt.toArray()), tvars);
    // dataSet = new BoxDataSet(new DoubleDataBox(dataSet.getDoubleData().toArray()), _nodes);
    dataSet.setNumberFormat(new DecimalFormat("0"));
    File file1 = new File(path, prefix + ".data.txt");
    File file2 = new File(path, prefix + ".dict.txt");
    try {
        PrintStream out1 = new PrintStream(new FileOutputStream(file1));
        PrintStream out2 = new PrintStream(new FileOutputStream(file2));
        out1.println(dataSet);
        out1.close();
        for (int i = 0; i < nodes.size(); i++) {
            out2.println(_nodes.get(i) + "\t" + nodes.get(i));
        }
        out2.println("Group");
        out2.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new RuntimeException();
    }
}
Also used : Node(edu.cmu.tetrad.graph.Node) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix)

Example 4 with TetradMatrix

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

the class TestIndTestFisherZ method test2.

@Test
public void test2() {
    for (int p = 0; p < 50; p++) {
        Graph graph = new EdgeListGraph();
        Node x = new ContinuousVariable("X");
        Node y = new ContinuousVariable("Y");
        Node w1 = new ContinuousVariable("W1");
        Node w2 = new ContinuousVariable("W2");
        Node w3 = new ContinuousVariable("W3");
        Node r = new ContinuousVariable("R");
        graph.addNode(x);
        graph.addNode(y);
        graph.addNode(w1);
        graph.addNode(w2);
        graph.addNode(w3);
        graph.addNode(r);
        graph.addDirectedEdge(x, w1);
        graph.addDirectedEdge(w1, w2);
        graph.addDirectedEdge(w2, y);
        graph.addDirectedEdge(w3, y);
        // graph.addDirectedEdge(x, r);
        // graph.addDirectedEdge(r, y);
        graph.addDirectedEdge(y, r);
        // 
        SemPm pm = new SemPm(graph);
        Parameters parameters = new Parameters();
        parameters.set("coefLow", .3);
        parameters.set("coefHigh", .8);
        parameters.set("coefSymmetric", false);
        SemIm im = new SemIm(pm, parameters);
        final int N = 1000;
        DataSet data = im.simulateData(N, false);
        ICovarianceMatrix _cov = new CovarianceMatrix(data);
        TetradMatrix cov = _cov.getMatrix();
        List<Node> nodes = _cov.getVariables();
        final int xi = nodes.indexOf(x);
        final int yi = nodes.indexOf(y);
        final int ri = nodes.indexOf(r);
        double xy = StatUtils.partialCorrelation(cov, xi, yi);
        double xyr = StatUtils.partialCorrelation(cov, xi, yi, ri);
        double f1 = 0.5 * sqrt(N - 3) * log(1. + xy) - log(1. - xy);
        double f2 = 0.5 * sqrt(N - 3 - 1) * log(1. + xyr) - log(1. - xyr);
        System.out.println(abs(f1) > abs(f2));
    }
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test) IndependenceTest(edu.cmu.tetrad.search.IndependenceTest)

Example 5 with TetradMatrix

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

the class TestDeltaTetradTest method getBollenSimulationExampleData.

private CovarianceMatrix getBollenSimulationExampleData() {
    double[][] d = new double[][] { { 2.034 }, { 0.113, 1.281 }, { 0.510, 0.093, 1.572 }, { 0.105, 0.857, 0.447, 1.708 }, { 0.998, 0.228, 0.170, 0.345, 1.651 } };
    Node y1 = new ContinuousVariable("y1");
    Node y2 = new ContinuousVariable("y2");
    Node y3 = new ContinuousVariable("y3");
    Node y4 = new ContinuousVariable("y4");
    Node y5 = new ContinuousVariable("y5");
    List<Node> nodes = new ArrayList<>();
    nodes.add(y1);
    nodes.add(y2);
    nodes.add(y3);
    nodes.add(y4);
    nodes.add(y5);
    TetradMatrix matrix = new TetradMatrix(5, 5);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j <= i; j++) {
            matrix.set(i, j, d[i][j]);
            matrix.set(j, i, d[i][j]);
        }
    }
    return new CovarianceMatrix(nodes, matrix, 1000);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ArrayList(java.util.ArrayList) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Aggregations

TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)161 TetradVector (edu.cmu.tetrad.util.TetradVector)46 ArrayList (java.util.ArrayList)43 Node (edu.cmu.tetrad.graph.Node)41 List (java.util.List)12 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)10 DepthChoiceGenerator (edu.cmu.tetrad.util.DepthChoiceGenerator)9 SingularMatrixException (org.apache.commons.math3.linear.SingularMatrixException)9 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)8 RegressionResult (edu.cmu.tetrad.regression.RegressionResult)8 Test (org.junit.Test)8 Regression (edu.cmu.tetrad.regression.Regression)7 RegressionDataset (edu.cmu.tetrad.regression.RegressionDataset)7 SemIm (edu.cmu.tetrad.sem.SemIm)7 Graph (edu.cmu.tetrad.graph.Graph)6 SemPm (edu.cmu.tetrad.sem.SemPm)6 Vector (java.util.Vector)6 DoubleArrayList (cern.colt.list.DoubleArrayList)5 DataSet (edu.cmu.tetrad.data.DataSet)5 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)5