use of edu.cmu.tetrad.data.CorrelationMatrix 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]));
}
}
Aggregations