Search in sources :

Example 1 with DeltaSextadTest

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

the class TestDeltaSextadTest method testBollenExampleb.

@Test
public void testBollenExampleb() {
    DataSet data = null;
    try {
        String name = "src/test/resources/dataLG.txt";
        DataReader reader = new DataReader();
        data = reader.parseTabular(new File(name));
    } catch (IOException e) {
        e.printStackTrace();
    }
    int m1 = 0;
    int m2 = 1;
    int m3 = 2;
    int m4 = 3;
    int m5 = 4;
    int m6 = 5;
    IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6);
    IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6);
    IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6);
    IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5);
    IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6);
    IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6);
    IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5);
    IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6);
    IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5);
    IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4);
    DeltaSextadTest test = new DeltaSextadTest(data);
    IntSextad[] _sextads = { t2, t5, t10, t3, t6 };
    double p = test.getPValue(_sextads);
    assertEquals(0.21, p, 0.01);
    _sextads = new IntSextad[] { t10 };
    p = test.getPValue(_sextads);
    assertEquals(0.30, p, 0.01);
// This should throw an exception but doesn't.
// MySextad[] _sextads = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10};
}
Also used : IntSextad(edu.cmu.tetrad.search.IntSextad) DataReader(edu.cmu.tetrad.data.DataReader) DataSet(edu.cmu.tetrad.data.DataSet) IOException(java.io.IOException) File(java.io.File) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest) Test(org.junit.Test) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest)

Example 2 with DeltaSextadTest

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

the class TestDeltaSextadTest method test2.

@Test
public void test2() {
    int c = 2;
    int m = 2;
    int p = 6;
    Graph g = new EdgeListGraph();
    List<List<Node>> varClusters = new ArrayList<>();
    List<List<Node>> latents = new ArrayList<>();
    List<Node> vars = new ArrayList<>();
    for (int y = 0; y < c; y++) {
        varClusters.add(new ArrayList<Node>());
        latents.add(new ArrayList<Node>());
    }
    int e = 0;
    for (int y = 0; y < c; y++) {
        for (int i = 0; i < p; i++) {
            GraphNode n = new GraphNode("V" + ++e);
            vars.add(n);
            varClusters.get(y).add(n);
            g.addNode(n);
        }
    }
    List<Node> l = new ArrayList<>();
    int f = 0;
    for (int y = 0; y < c; y++) {
        for (int j = 0; j < m; j++) {
            Node _l = new GraphNode("L" + ++f);
            _l.setNodeType(NodeType.LATENT);
            l.add(_l);
            latents.get(y).add(_l);
            g.addNode(_l);
        }
    }
    for (int y = 0; y < c; y++) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < p; j++) {
                g.addDirectedEdge(latents.get(y).get(i), varClusters.get(y).get(j));
            }
        }
    }
    for (int y = 1; y < c; y++) {
        for (int j = 0; j < m; j++) {
            g.addDirectedEdge(latents.get(y - 1).get(j), latents.get(y).get(j));
        }
    }
    SemPm pm = new SemPm(g);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(1000, false);
    List<Integer> indices = new ArrayList<>();
    indices.add(0);
    indices.add(1);
    indices.add(2);
    indices.add(4);
    indices.add(5);
    indices.add(7);
    Collections.shuffle(indices);
    // Node x1 = data.getVariable(indices.get(0));
    // Node x2 = data.getVariable(indices.get(1));
    // Node x3 = data.getVariable(indices.get(2));
    // Node x4 = data.getVariable(indices.get(3));
    // Node x5 = data.getVariable(indices.get(4));
    // Node x6 = data.getVariable(indices.get(5));
    int x1 = indices.get(0);
    int x2 = indices.get(1);
    int x3 = indices.get(2);
    int x4 = indices.get(3);
    int x5 = indices.get(4);
    int x6 = indices.get(5);
    DeltaSextadTest test = new DeltaSextadTest(data);
    // Should be invariant to changes or order of the first three or of the last three variables.
    double a = test.getPValue(new IntSextad(x1, x2, x3, x4, x5, x6));
    double b = test.getPValue(new IntSextad(x2, x3, x1, x5, x4, x6));
    assertEquals(a, b, 1e-7);
}
Also used : IntSextad(edu.cmu.tetrad.search.IntSextad) DataSet(edu.cmu.tetrad.data.DataSet) ArrayList(java.util.ArrayList) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest) SemPm(edu.cmu.tetrad.sem.SemPm) ArrayList(java.util.ArrayList) List(java.util.List) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest)

Example 3 with DeltaSextadTest

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

the class TestDeltaSextadTest method testBollenExample1.

// Bollen and Ting, Confirmatory Tetrad Analysis, p. 164 Sympathy and Anger.
@Test
public void testBollenExample1() {
    SemIm sem = getSem1();
    DataSet data = sem.simulateData(3000, false);
    List<Node> variables = data.getVariables();
    int m1 = 0;
    int m2 = 1;
    int m3 = 2;
    int m4 = 3;
    int m5 = 4;
    int m6 = 5;
    IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6);
    IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6);
    IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6);
    IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5);
    IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6);
    IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6);
    IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5);
    IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6);
    IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5);
    IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4);
    List<IntSextad> sextads = new ArrayList<>();
    sextads.add(t1);
    sextads.add(t2);
    sextads.add(t3);
    sextads.add(t4);
    sextads.add(t5);
    sextads.add(t6);
    sextads.add(t7);
    sextads.add(t8);
    sextads.add(t9);
    sextads.add(t10);
    DeltaSextadTest test = new DeltaSextadTest(data);
    int numSextads = 3;
    double alpha = 0.001;
    ChoiceGenerator gen = new ChoiceGenerator(sextads.size(), numSextads);
    int[] choice;
    while ((choice = gen.next()) != null) {
        IntSextad[] _sextads = new IntSextad[numSextads];
        for (int i = 0; i < numSextads; i++) {
            _sextads[i] = sextads.get(choice[i]);
        }
        double p = test.getPValue(_sextads);
    }
}
Also used : IntSextad(edu.cmu.tetrad.search.IntSextad) DataSet(edu.cmu.tetrad.data.DataSet) ArrayList(java.util.ArrayList) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest) ChoiceGenerator(edu.cmu.tetrad.util.ChoiceGenerator) SemIm(edu.cmu.tetrad.sem.SemIm) Test(org.junit.Test) DeltaSextadTest(edu.cmu.tetrad.search.DeltaSextadTest)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)3 DeltaSextadTest (edu.cmu.tetrad.search.DeltaSextadTest)3 IntSextad (edu.cmu.tetrad.search.IntSextad)3 Test (org.junit.Test)3 SemIm (edu.cmu.tetrad.sem.SemIm)2 ArrayList (java.util.ArrayList)2 DataReader (edu.cmu.tetrad.data.DataReader)1 SemPm (edu.cmu.tetrad.sem.SemPm)1 ChoiceGenerator (edu.cmu.tetrad.util.ChoiceGenerator)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1