Search in sources :

Example 56 with ContinuousVariable

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;
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) NumberFormat(java.text.NumberFormat)

Example 57 with ContinuousVariable

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());
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) Parameters(edu.cmu.tetrad.util.Parameters) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Example 58 with ContinuousVariable

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;
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList)

Example 59 with ContinuousVariable

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);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 60 with ContinuousVariable

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));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Graph(edu.cmu.tetrad.graph.Graph) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)91 DataSet (edu.cmu.tetrad.data.DataSet)48 Node (edu.cmu.tetrad.graph.Node)46 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)22 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)19 SemPm (edu.cmu.tetrad.sem.SemPm)18 SemIm (edu.cmu.tetrad.sem.SemIm)16 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)15 LinkedList (java.util.LinkedList)13 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)12 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)8 DMSearch (edu.cmu.tetrad.search.DMSearch)7 Dag (edu.cmu.tetrad.graph.Dag)6 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)5 RandomUtil (edu.cmu.tetrad.util.RandomUtil)5 ParseException (java.text.ParseException)4 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)3 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3