use of edu.cmu.tetrad.util.TetradMatrix in project tetrad by cmu-phil.
the class ScatterPlot method getCorrelationCoeff.
public double getCorrelationCoeff() {
DataSet dataSet = getDataSet();
TetradMatrix data = dataSet.getDoubleData();
int _x = dataSet.getColumn(dataSet.getVariable(x));
int _y = dataSet.getColumn(dataSet.getVariable(y));
double[] xdata = data.getColumn(_x).toArray();
double[] ydata = data.getColumn(_y).toArray();
double correlation = StatUtils.correlation(xdata, ydata);
if (correlation > 1)
correlation = 1;
else if (correlation < -1)
correlation = -1;
return correlation;
}
use of edu.cmu.tetrad.util.TetradMatrix in project tetrad by cmu-phil.
the class BooleanGlassGeneIm method asTimeSeriesData.
private TimeSeriesData asTimeSeriesData(double[][][] cube, int cell, List<String> factors) {
int numTimeSteps = cube[0].length;
int numFactors = cube.length;
double[][] square = new double[numTimeSteps][numFactors];
for (int timeStep = 0; timeStep < numTimeSteps; timeStep++) {
for (int factor = 0; factor < numFactors; factor++) {
square[timeStep][factor] = cube[factor][timeStep][cell];
}
}
List<String> varNames = new ArrayList<>();
for (int i = 0; i < numFactors; i++) {
varNames.add(factors.get(i));
}
return new TimeSeriesData(new TetradMatrix(square), varNames);
}
use of edu.cmu.tetrad.util.TetradMatrix in project tetrad by cmu-phil.
the class ExploreAutisticsNeurotypicals method printDataTranspose.
private static void printDataTranspose(String path, String prefix, DataSet dataSet) {
List<Node> nodes = dataSet.getVariables();
Node group = dataSet.getVariable("Group");
List<Node> _nodes = new ArrayList<>();
for (int i = 0; i < nodes.size(); i++) {
if (nodes.get(i) == group) {
_nodes.add(group);
} else {
_nodes.add(new ContinuousVariable("X" + (i + 1)));
}
}
TetradMatrix m = dataSet.getDoubleData();
TetradMatrix mt = m.transpose();
List<Node> tvars = new ArrayList<>();
for (int i = 0; i < mt.columns(); i++) tvars.add(new ContinuousVariable("S" + (i + 1)));
dataSet = new BoxDataSet(new DoubleDataBox(mt.toArray()), tvars);
// dataSet = new BoxDataSet(new DoubleDataBox(dataSet.getDoubleData().toArray()), _nodes);
dataSet.setNumberFormat(new DecimalFormat("0"));
File file1 = new File(path, prefix + ".data.txt");
File file2 = new File(path, prefix + ".dict.txt");
try {
PrintStream out1 = new PrintStream(new FileOutputStream(file1));
PrintStream out2 = new PrintStream(new FileOutputStream(file2));
out1.println(dataSet);
out1.close();
for (int i = 0; i < nodes.size(); i++) {
out2.println(_nodes.get(i) + "\t" + nodes.get(i));
}
out2.println("Group");
out2.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
use of edu.cmu.tetrad.util.TetradMatrix in project tetrad by cmu-phil.
the class TestIndTestFisherZ method test2.
@Test
public void test2() {
for (int p = 0; p < 50; p++) {
Graph graph = new EdgeListGraph();
Node x = new ContinuousVariable("X");
Node y = new ContinuousVariable("Y");
Node w1 = new ContinuousVariable("W1");
Node w2 = new ContinuousVariable("W2");
Node w3 = new ContinuousVariable("W3");
Node r = new ContinuousVariable("R");
graph.addNode(x);
graph.addNode(y);
graph.addNode(w1);
graph.addNode(w2);
graph.addNode(w3);
graph.addNode(r);
graph.addDirectedEdge(x, w1);
graph.addDirectedEdge(w1, w2);
graph.addDirectedEdge(w2, y);
graph.addDirectedEdge(w3, y);
// graph.addDirectedEdge(x, r);
// graph.addDirectedEdge(r, y);
graph.addDirectedEdge(y, r);
//
SemPm pm = new SemPm(graph);
Parameters parameters = new Parameters();
parameters.set("coefLow", .3);
parameters.set("coefHigh", .8);
parameters.set("coefSymmetric", false);
SemIm im = new SemIm(pm, parameters);
final int N = 1000;
DataSet data = im.simulateData(N, false);
ICovarianceMatrix _cov = new CovarianceMatrix(data);
TetradMatrix cov = _cov.getMatrix();
List<Node> nodes = _cov.getVariables();
final int xi = nodes.indexOf(x);
final int yi = nodes.indexOf(y);
final int ri = nodes.indexOf(r);
double xy = StatUtils.partialCorrelation(cov, xi, yi);
double xyr = StatUtils.partialCorrelation(cov, xi, yi, ri);
double f1 = 0.5 * sqrt(N - 3) * log(1. + xy) - log(1. - xy);
double f2 = 0.5 * sqrt(N - 3 - 1) * log(1. + xyr) - log(1. - xyr);
System.out.println(abs(f1) > abs(f2));
}
}
use of edu.cmu.tetrad.util.TetradMatrix in project tetrad by cmu-phil.
the class TestDeltaTetradTest method getBollenSimulationExampleData.
private CovarianceMatrix getBollenSimulationExampleData() {
double[][] d = new double[][] { { 2.034 }, { 0.113, 1.281 }, { 0.510, 0.093, 1.572 }, { 0.105, 0.857, 0.447, 1.708 }, { 0.998, 0.228, 0.170, 0.345, 1.651 } };
Node y1 = new ContinuousVariable("y1");
Node y2 = new ContinuousVariable("y2");
Node y3 = new ContinuousVariable("y3");
Node y4 = new ContinuousVariable("y4");
Node y5 = new ContinuousVariable("y5");
List<Node> nodes = new ArrayList<>();
nodes.add(y1);
nodes.add(y2);
nodes.add(y3);
nodes.add(y4);
nodes.add(y5);
TetradMatrix matrix = new TetradMatrix(5, 5);
for (int i = 0; i < 5; i++) {
for (int j = 0; j <= i; j++) {
matrix.set(i, j, d[i][j]);
matrix.set(j, i, d[i][j]);
}
}
return new CovarianceMatrix(nodes, matrix, 1000);
}
Aggregations