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
}
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);
}
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);
}
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();
}
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;
}
Aggregations