Search in sources :

Example 1 with DeltaTetradTest

use of edu.cmu.tetrad.search.DeltaTetradTest in project tetrad by cmu-phil.

the class TestDeltaTetradTest method testBollenExample1.

// Bollen and Ting, Confirmatory Tetrad Analysis, p. 164 Sympathy and Anger.
@Test
public void testBollenExample1() {
    CovarianceMatrix cov = getBollenExample1Data();
    List<Node> variables = cov.getVariables();
    Node v1 = variables.get(0);
    Node v2 = variables.get(1);
    Node v3 = variables.get(2);
    Node v4 = variables.get(3);
    Node v5 = variables.get(4);
    Node v6 = variables.get(5);
    Tetrad t1 = new Tetrad(v1, v2, v3, v4);
    Tetrad t2 = new Tetrad(v1, v2, v3, v5);
    Tetrad t3 = new Tetrad(v1, v2, v3, v6);
    Tetrad t4 = new Tetrad(v1, v4, v5, v6);
    Tetrad t5 = new Tetrad(v1, v4, v2, v3);
    Tetrad t6 = new Tetrad(v1, v5, v2, v3);
    Tetrad t7 = new Tetrad(v1, v6, v2, v3);
    Tetrad t8 = new Tetrad(v1, v6, v4, v5);
    DeltaTetradTest test = new DeltaTetradTest(cov);
    // DeltaTetradTest test = new DeltaTetradTest(new CorrelationMatrix(cov));
    double chiSq = test.calcChiSquare(t1, t2, t3, t4, t5, t6, t7, t8);
    double pValue = test.getPValue();
    // They get chi square = 6.71 p = .57 8 df but using the raw data which they don't provide here.
    // Just using the covariance matrix provided, I get chi square = 8.46, p = 0.39, df = 8.
    assertEquals(11.42, chiSq, 0.01);
    assertEquals(0.18, pValue, 0.01);
}
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 2 with DeltaTetradTest

use of edu.cmu.tetrad.search.DeltaTetradTest in project tetrad by cmu-phil.

the class TestDeltaTetradTest method test3.

@Test
public void test3() {
    SemPm pm = makePm();
    DataSet data = new SemIm(pm).simulateData(1000, false);
    CovarianceMatrix cov = new CovarianceMatrix(data);
    List<Node> variables = data.getVariables();
    Node x1 = variables.get(0);
    Node x2 = variables.get(1);
    Node x3 = variables.get(2);
    Node x4 = variables.get(3);
    Node x5 = variables.get(4);
    Tetrad t1234 = new Tetrad(x1, x2, x3, x4);
    Tetrad t1342 = new Tetrad(x1, x3, x4, x2);
    Tetrad t1423 = new Tetrad(x1, x4, x2, x3);
    DeltaTetradTest test1 = new DeltaTetradTest(data);
    // DeltaTetradTest test = new DeltaTetradTest(new CorrelationMatrix(cov));
    double chiSq1 = test1.calcChiSquare(t1234, t1342);
    DeltaTetradTest test2 = new DeltaTetradTest(cov);
    // DeltaTetradTest test = new DeltaTetradTest(new CorrelationMatrix(cov));
    double chiSq2 = test2.calcChiSquare(t1234, t1342);
}
Also used : DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) DataSet(edu.cmu.tetrad.data.DataSet) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) Tetrad(edu.cmu.tetrad.search.Tetrad) CovarianceMatrix(edu.cmu.tetrad.data.CovarianceMatrix) DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) Test(org.junit.Test)

Example 3 with DeltaTetradTest

use of edu.cmu.tetrad.search.DeltaTetradTest in project tetrad by cmu-phil.

the class TestDeltaTetradTest method test4aIteratedPositives.

@Test
public void test4aIteratedPositives() {
    RandomUtil.getInstance().setSeed(482834823L);
    int numTrials = 10;
    double alpha = 0.2;
    SemIm sem = getFigure4aSem();
    int[] sampleSizes = new int[] { 100, 500, 1000, 5000 };
    double[][] answers = { { .1, .5, .2, .1, .1, .1 }, { 0.1, 0.6, 0.0, 0.0, 0.0, 0.0 }, { 0.1, 0.7, 0.2, 0.2, 0.2, 0.2 }, { 0.3, 0.7, 0.2, 0.1, 0.1, 0.1 } };
    for (int i = 0; i < 4; i++) {
        System.out.println("i = " + i);
        int sampleSize = sampleSizes[i];
        int[] count = new int[6];
        for (int k = 0; k < numTrials; k++) {
            DataSet data = sem.simulateData(sampleSize, false);
            Node x1 = data.getVariable("x1");
            Node x2 = data.getVariable("x2");
            Node x3 = data.getVariable("x3");
            Node x4 = data.getVariable("x4");
            Tetrad t1234 = new Tetrad(x1, x2, x3, x4);
            Tetrad t1342 = new Tetrad(x1, x3, x4, x2);
            Tetrad t1423 = new Tetrad(x1, x4, x2, x3);
            DeltaTetradTest test = new DeltaTetradTest(new CorrelationMatrix(data));
            double p1 = test.getPValue(t1234);
            double p2 = test.getPValue(t1342);
            double p3 = test.getPValue(t1423);
            double p4 = test.getPValue(t1234, t1342);
            double p5 = test.getPValue(t1234, t1423);
            double p6 = test.getPValue(t1342, t1423);
            if (p1 < alpha)
                count[0]++;
            if (p2 < alpha)
                count[1]++;
            if (p3 < alpha)
                count[2]++;
            if (p4 < alpha)
                count[3]++;
            if (p5 < alpha)
                count[4]++;
            if (p6 < alpha)
                count[5]++;
        }
        double[] _answer = new double[6];
        for (int j = 0; j < 6; j++) {
            double v = count[j] / (double) numTrials;
            _answer[j] = v;
        }
    // System.out.println(MatrixUtils.toString(_answer));
    // System.out.println(MatrixUtils.toString(answers[i]));
    // assertTrue(Arrays.equals(_answer, answers[i]));
    }
}
Also used : DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) CorrelationMatrix(edu.cmu.tetrad.data.CorrelationMatrix) DataSet(edu.cmu.tetrad.data.DataSet) SemIm(edu.cmu.tetrad.sem.SemIm) Tetrad(edu.cmu.tetrad.search.Tetrad) DeltaTetradTest(edu.cmu.tetrad.search.DeltaTetradTest) Test(org.junit.Test)

Example 4 with DeltaTetradTest

use of edu.cmu.tetrad.search.DeltaTetradTest in project tetrad by cmu-phil.

the class TestDeltaTetradTest method testBollenSimulationExample.

// Bollen 2000 A Tetrad Test for Causal Indicators, p. 13.
@Test
public void testBollenSimulationExample() {
    CovarianceMatrix cov = getBollenSimulationExampleData();
    List<Node> variables = cov.getVariables();
    Node y1 = variables.get(0);
    Node y2 = variables.get(1);
    Node y3 = variables.get(2);
    Node y4 = variables.get(3);
    Node y5 = variables.get(4);
    Tetrad t1 = new Tetrad(y1, y2, y3, y4);
    Tetrad t2 = new Tetrad(y1, y2, y4, y3);
    Tetrad t3 = new Tetrad(y1, y3, y4, y2);
    Tetrad t4 = new Tetrad(y1, y2, y3, y5);
    Tetrad t5 = new Tetrad(y1, y2, y5, y3);
    Tetrad t6 = new Tetrad(y1, y3, y5, y2);
    Tetrad t7 = new Tetrad(y1, y2, y4, y5);
    Tetrad t8 = new Tetrad(y1, y2, y5, y4);
    Tetrad t9 = new Tetrad(y1, y4, y5, y2);
    Tetrad t10 = new Tetrad(y1, y3, y4, y5);
    Tetrad t11 = new Tetrad(y1, y3, y5, y4);
    Tetrad t12 = new Tetrad(y1, y4, y5, y3);
    Tetrad t13 = new Tetrad(y2, y3, y4, y5);
    Tetrad t14 = new Tetrad(y2, y3, y5, y4);
    Tetrad t15 = new Tetrad(y2, y4, y5, y3);
    Tetrad[] tetrads = new Tetrad[] { t1, t2, t3, t4 };
    DeltaTetradTest test = new DeltaTetradTest(cov);
    double chiSq = test.calcChiSquare(tetrads[0]);
    double pValue = test.getPValue();
    assertEquals(58.1, chiSq, 0.1);
    assertEquals(2.46E-14, pValue, .1E-14);
    Tetrad[] independentTetrads = new Tetrad[] { t1, t2, t4, t6, t10 };
    chiSq = test.calcChiSquare(independentTetrads[0]);
    pValue = test.getPValue();
    assertEquals(58.1, chiSq, 0.1);
    assertEquals(2.46E-14, pValue, 0.1E-14);
    {
        chiSq = test.calcChiSquare(independentTetrads);
        pValue = test.getPValue();
        assertEquals(89.34, chiSq, 0.01);
        assertEquals(0.0, pValue, 0.01);
    }
// They get chsq = 64.13 and so do I.
}
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 5 with DeltaTetradTest

use of edu.cmu.tetrad.search.DeltaTetradTest 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)

Aggregations

DeltaTetradTest (edu.cmu.tetrad.search.DeltaTetradTest)5 Tetrad (edu.cmu.tetrad.search.Tetrad)5 Test (org.junit.Test)5 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)4 DataSet (edu.cmu.tetrad.data.DataSet)2 SemIm (edu.cmu.tetrad.sem.SemIm)2 CorrelationMatrix (edu.cmu.tetrad.data.CorrelationMatrix)1 SemPm (edu.cmu.tetrad.sem.SemPm)1