Search in sources :

Example 16 with CovarianceMatrix

use of edu.cmu.tetrad.data.CovarianceMatrix in project tetrad by cmu-phil.

the class TestDeltaTetradTest method testBollenExample2.

// Bollen and Ting p. 167 (Confirmatory Tetrad Analysis). Union Sentiment.
@Test
public void testBollenExample2() {
    CovarianceMatrix cov = getBollenExample2Data();
    List<Node> variables = cov.getVariables();
    Node y1 = variables.get(0);
    Node y2 = variables.get(1);
    Node y3 = variables.get(2);
    Node x1 = variables.get(3);
    Node x2 = variables.get(4);
    Tetrad t1 = new Tetrad(y1, x1, x2, y2);
    DeltaTetradTest test = new DeltaTetradTest(cov);
    double chiSq = test.calcChiSquare(t1);
    double pValue = test.getPValue();
    assertEquals(.68, chiSq, 0.01);
    assertEquals(0.40, pValue, 0.01);
// They get chi square = .73  p = .39  df = 1
}
Also used : DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) Tetrad(edu.cmu.tetrad.search.Tetrad) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) Test(org.junit.Test)

Example 17 with CovarianceMatrix

use of edu.cmu.tetrad.data.CovarianceMatrix in project tetrad by cmu-phil.

the class TestSem method constructCovMatrix2.

private ICovarianceMatrix constructCovMatrix2() {
    String[] vars = new String[] { "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8" };
    int sampleSize = 173;
    double[][] arr = { { 1.0 }, { .215, 1.0 }, { -.164, -.472, 1.0 }, { .112, .079, -.157, 1.0 }, { .034, .121, -.184, .407, 1.0 }, { .101, .197, -.190, .176, .120, 1.0 }, { .071, -.172, .206, -.049, -.084, -.291, 1.0 }, { .043, -.038, -.037, -.062, .028, .166, -.149, 1.0 } };
    double[][] m = MatrixUtils.convertLowerTriangleToSymmetric(arr);
    TetradMatrix m2 = new TetradMatrix(m);
    return new CovarianceMatrix(DataUtils.createContinuousVariables(vars), m2, sampleSize);
}
Also used : TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Example 18 with CovarianceMatrix

use of edu.cmu.tetrad.data.CovarianceMatrix in project tetrad by cmu-phil.

the class TestSem method constructCovMatrix1.

private ICovarianceMatrix constructCovMatrix1() {
    String[] vars = new String[] { "X1", "X2", "X3", "X4", "X5" };
    double[][] arr = { { 1.04408 }, { 0.80915, 1.55607 }, { 0.89296, 1.67375, 2.87584 }, { 2.23792, 2.68536, 3.94996, 7.78259 }, { 1.17516, 1.36337, 1.99039, 4.04533, 3.14922 } };
    double[][] m = MatrixUtils.convertLowerTriangleToSymmetric(arr);
    TetradMatrix m2 = new TetradMatrix(m);
    return new CovarianceMatrix(DataUtils.createContinuousVariables(vars), m2, 1000);
}
Also used : TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Example 19 with CovarianceMatrix

use of edu.cmu.tetrad.data.CovarianceMatrix in project tetrad by cmu-phil.

the class TestSemIm method test3.

@Test
public void test3() {
    Graph graph = constructGraph1();
    SemPm semPm = new SemPm(graph);
    SemIm semIm = new SemIm(semPm);
    DataSet dataSetContColumnContinuous = semIm.simulateData(500, false);
    ICovarianceMatrix covMatrix = new CovarianceMatrix(dataSetContColumnContinuous);
    SemEstimator estimator2 = new SemEstimator(covMatrix, semPm);
    estimator2.estimate();
    estimator2.getEstimatedSem();
    SemEstimator estimator3 = new SemEstimator(covMatrix, semPm);
    estimator3.estimate();
    estimator3.getEstimatedSem();
    SemPm semPm4 = new SemPm(graph);
    SemEstimator estimator4 = new SemEstimator(covMatrix, semPm4);
    estimator4.estimate();
    estimator4.getEstimatedSem();
    SemPm semPm5 = new SemPm(graph);
    SemEstimator estimator5 = new SemEstimator(covMatrix, semPm5);
    estimator5.estimate();
    estimator5.getEstimatedSem();
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) Test(org.junit.Test)

Example 20 with CovarianceMatrix

use of edu.cmu.tetrad.data.CovarianceMatrix in project tetrad by cmu-phil.

the class InverseCorrelation method search.

public Graph search() {
    CovarianceMatrix cov = new CovarianceMatrix(data);
    TetradMatrix _data = cov.getMatrix();
    TetradMatrix inverse = _data.inverse();
    System.out.println(inverse);
    Graph graph = new EdgeListGraph(data.getVariables());
    for (int i = 0; i < inverse.rows(); i++) {
        for (int j = i + 1; j < inverse.columns(); j++) {
            double a = inverse.get(i, j);
            double b = inverse.get(i, i);
            double c = inverse.get(j, j);
            double r = -a / Math.sqrt(b * c);
            int sampleSize = data.getNumRows();
            int z = data.getNumColumns();
            double fisherZ = Math.sqrt(sampleSize - z - 3.0) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r));
            double p = getPValue(fisherZ);
            if (p < threshold) {
                Node x = graph.getNodes().get(i);
                Node y = graph.getNodes().get(j);
                graph.addUndirectedEdge(x, y);
            }
        // if (abs(fisherZ) > threshold) {
        // System.out.println(fisherZ + " &&& " + p);
        // Node x = graph.getNodes().get(i);
        // Node y = graph.getNodes().get(j);
        // graph.addUndirectedEdge(x, y);
        // }
        // if (Math.abs(inverse.get(i, j)) > threshold) {
        // Node x = graph.getNodes().get(i);
        // Node y = graph.getNodes().get(j);
        // graph.addUndirectedEdge(x, y);
        // }
        }
    }
    return graph;
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) TetradMatrix(edu.cmu.tetrad.util.TetradMatrix) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix)

Aggregations

CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)20 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)11 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)7 DataSet (edu.cmu.tetrad.data.DataSet)6 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)5 DeltaTetradTest (edu.cmu.tetrad.search.DeltaTetradTest)4 Tetrad (edu.cmu.tetrad.search.Tetrad)4 SemPm (edu.cmu.tetrad.sem.SemPm)4 SemIm (edu.cmu.tetrad.sem.SemIm)3 DataModel (edu.cmu.tetrad.data.DataModel)2 Node (edu.cmu.tetrad.graph.Node)2 List (java.util.List)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)1 Graph (edu.cmu.tetrad.graph.Graph)1 SemGraph (edu.cmu.tetrad.graph.SemGraph)1 Regression (edu.cmu.tetrad.regression.Regression)1