use of edu.cmu.tetrad.search.IndTestFisherZGeneralizedInverse in project tetrad by cmu-phil.
the class TestIndTestFisherGeneralizedInverse method testDirections.
@Test
public void testDirections() {
RandomUtil.getInstance().setSeed(48285934L);
Graph graph1 = new EdgeListGraph();
Graph graph2 = new EdgeListGraph();
Node x = new GraphNode("X");
Node y = new GraphNode("Y");
Node z = new GraphNode("Z");
graph1.addNode(x);
graph1.addNode(y);
graph1.addNode(z);
graph2.addNode(x);
graph2.addNode(y);
graph2.addNode(z);
graph1.addEdge(Edges.directedEdge(x, y));
graph1.addEdge(Edges.directedEdge(y, z));
graph2.addEdge(Edges.directedEdge(x, y));
graph2.addEdge(Edges.directedEdge(z, y));
SemPm pm1 = new SemPm(graph1);
SemPm pm2 = new SemPm(graph2);
SemIm im1 = new SemIm(pm1);
SemIm im2 = new SemIm(pm2);
im2.setEdgeCoef(x, y, im1.getEdgeCoef(x, y));
im2.setEdgeCoef(z, y, im1.getEdgeCoef(y, z));
DataSet data1 = im1.simulateData(500, false);
DataSet data2 = im2.simulateData(500, false);
IndependenceTest test1 = new IndTestFisherZGeneralizedInverse(data1, 0.05);
IndependenceTest test2 = new IndTestFisherZGeneralizedInverse(data2, 0.05);
test1.isIndependent(data1.getVariable(x.getName()), data1.getVariable(y.getName()));
double p1 = test1.getPValue();
test2.isIndependent(data2.getVariable(x.getName()), data2.getVariable(z.getName()), data2.getVariable(y.getName()));
double p2 = test2.getPValue();
test2.isIndependent(data2.getVariable(x.getName()), data2.getVariable(z.getName()));
double p3 = test2.getPValue();
assertEquals(0, p1, 0.01);
assertEquals(0, p2, 0.01);
assertEquals(0.38, p3, 0.01);
}
Aggregations