use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class DescriptiveStats method generateDescriptiveStats.
/**
* Constructs a readable table of normality test results
*/
public static String generateDescriptiveStats(DataSet dataSet, Node variable) {
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
int col = dataSet.getColumn(variable);
double[] data = new double[dataSet.getNumRows()];
boolean continuous = false;
if (variable instanceof ContinuousVariable) {
continuous = true;
for (int i = 0; i < dataSet.getNumRows(); i++) {
data[i] = dataSet.getDouble(i, col);
}
} else {
try {
for (int i = 0; i < dataSet.getNumRows(); i++) {
DiscreteVariable var = (DiscreteVariable) variable;
String category = var.getCategory(dataSet.getInt(i, col));
int value = Integer.parseInt(category);
data[i] = value;
}
} catch (NumberFormatException e) {
return "Not a numerical discrete column.";
}
}
String result = "Descriptive Statistics for: " + variable.getName() + "\n";
result += "------------------------------------\n\n";
double[] normalValues = normalParams(data);
result += "Sample Size:\t\t" + dataSet.getNumRows() + "\n";
result += "Mean:\t\t\t" + nf.format(normalValues[0]) + "\nStandard Deviation:\t" + nf.format(normalValues[1]) + "\nVariance:\t\t" + nf.format(normalValues[2]) + "\n";
result += "Skewness:\t\t" + nf.format(StatUtils.skewness(data)) + "\n";
result += "Excess Kurtosis:\t" + nf.format(StatUtils.kurtosis(data)) + "\n";
if (continuous) {
result += "SE Mean:\t\t" + nf.format(standardErrorMean(normalValues[1], dataSet.getNumRows())) + "\n";
}
double[] median = median(data);
result += "Median:\t\t\t" + nf.format(median[0]) + "\n";
if (continuous) {
result += "Minimum Value:\t\t" + nf.format(median[1]) + "\nMaximum Value:\t\t" + nf.format(median[2]);
}
return result;
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class LogisticRegressionRunner method serializableInstance.
/**
* Generates a simple exemplar of this class to test serialization.
*
* @see TetradSerializableUtils
*/
public static LogisticRegressionRunner serializableInstance() {
List<Node> variables = new LinkedList<>();
ContinuousVariable var1 = new ContinuousVariable("X");
ContinuousVariable var2 = new ContinuousVariable("Y");
variables.add(var1);
variables.add(var2);
DataSet dataSet = new ColtDataSet(3, variables);
double[] col1data = new double[] { 0.0, 1.0, 2.0 };
double[] col2data = new double[] { 2.3, 4.3, 2.5 };
for (int i = 0; i < 3; i++) {
dataSet.setDouble(i, 0, col1data[i]);
dataSet.setDouble(i, 1, col2data[i]);
}
DataWrapper dataWrapper = new DataWrapper(dataSet);
return new LogisticRegressionRunner(dataWrapper, new Parameters());
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class DataConvertUtils method toNodes.
public static List<Node> toNodes(List<String> variables) {
List<Node> nodes = new LinkedList<>();
variables.forEach(variable -> {
nodes.add(new ContinuousVariable(variable));
});
return nodes;
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class TestEdgeListGraphSingleConnections method testSequence3.
@Test
public void testSequence3() {
List<Node> nodes = new ArrayList<>();
for (int i1 = 0; i1 < 50; i1++) {
nodes.add(new ContinuousVariable("X" + (i1 + 1)));
}
Graph graph = new Dag(GraphUtils.randomGraph(nodes, 0, 50, 30, 15, 15, false));
Node node1 = graph.getNodes().get(0);
Node node2 = graph.getNodes().get(1);
List<Node> cond = new ArrayList<>();
for (int i = 2; i < 5; i++) {
cond.add(graph.getNodes().get(i));
}
boolean dsep = graph.isDSeparatedFrom(node1, node2, cond);
}
use of edu.cmu.tetrad.data.ContinuousVariable in project tetrad by cmu-phil.
the class TestFas method test1.
@Test
public void test1() {
int numVars = 10;
double edgesPerNode = 1.0;
List<Node> vars = new ArrayList<>();
for (int i = 0; i < numVars; i++) {
vars.add(new ContinuousVariable("X" + i));
}
Graph graph = GraphUtils.randomGraphRandomForwardEdges(vars, 0, (int) (numVars * edgesPerNode), 30, 15, 15, false, true);
IndependenceTest test = new IndTestDSep(graph);
Graph fasGraph = new FasStableConcurrent(test).search();
Graph pcGraph = new Pc(test).search();
assertEquals(fasGraph, GraphUtils.undirectedGraph(pcGraph));
}
Aggregations