Search in sources :

Example 11 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class RegressionResult method getResultsTable.

public TextTable getResultsTable() {
    NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
    TextTable table = new TextTable(getNumRegressors() + 3, 6);
    table.setToken(0, 0, "VAR");
    table.setToken(0, 1, "COEF");
    table.setToken(0, 2, "SE");
    table.setToken(0, 3, "T");
    table.setToken(0, 4, "P");
    table.setToken(0, 5, "");
    for (int i = 0; i < getNumRegressors() + 1; i++) {
        // Note: the first column contains the regression constants.
        String variableName = (i > 0) ? regressorNames[i - 1] : "const";
        table.setToken(i + 2, 0, variableName);
        table.setToken(i + 2, 1, nf.format(b[i]));
        if (se.length != 0) {
            table.setToken(i + 2, 2, nf.format(se[i]));
        } else {
            table.setToken(i + 2, 2, "-1");
        }
        if (t.length != 0) {
            table.setToken(i + 2, 3, nf.format(t[i]));
        } else {
            table.setToken(i + 2, 3, "-1");
        }
        if (p.length != 0) {
            table.setToken(i + 2, 4, nf.format(p[i]));
        } else {
            table.setToken(i + 2, 4, "-1");
        }
        if (p.length != 0) {
            table.setToken(i + 2, 5, (p[i] < alpha) ? "significant " : "");
        } else {
            table.setToken(i + 2, 5, "(p not defined)");
        }
    }
    return table;
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable) NumberFormat(java.text.NumberFormat)

Example 12 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class RegressionResult method toString.

public String toString() {
    StringBuilder summary = new StringBuilder(getPreamble());
    TextTable table = getResultsTable();
    summary.append("\n").append(table.toString());
    return summary.toString();
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable)

Example 13 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class GraphUtils method edgeMisclassifications.

public static String edgeMisclassifications(double[][] counts, NumberFormat nf) {
    StringBuilder builder = new StringBuilder();
    TextTable table2 = new TextTable(9, 7);
    table2.setToken(1, 0, "---");
    table2.setToken(2, 0, "o-o");
    table2.setToken(3, 0, "o->");
    table2.setToken(4, 0, "<-o");
    table2.setToken(5, 0, "-->");
    table2.setToken(6, 0, "<--");
    table2.setToken(7, 0, "<->");
    table2.setToken(8, 0, "No Edge");
    table2.setToken(0, 1, "---");
    table2.setToken(0, 2, "o-o");
    table2.setToken(0, 3, "o->");
    table2.setToken(0, 4, "-->");
    table2.setToken(0, 5, "<->");
    table2.setToken(0, 6, "No Edge");
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 6; j++) {
            if (i == 7 && j == 5) {
                table2.setToken(i + 1, j + 1, "*");
            } else {
                table2.setToken(i + 1, j + 1, "" + nf.format(counts[i][j]));
            }
        }
    }
    builder.append(table2.toString());
    double correctEdges = 0;
    double estimatedEdges = 0;
    for (int i = 0; i < counts.length; i++) {
        for (int j = 0; j < counts[0].length - 1; j++) {
            if ((i == 0 && j == 0) || (i == 1 && j == 1) || (i == 2 && j == 2) || (i == 4 && j == 3) || (i == 6 && j == 4)) {
                correctEdges += counts[i][j];
            }
            estimatedEdges += counts[i][j];
        }
    }
    NumberFormat nf2 = new DecimalFormat("0.00");
    builder.append("\nRatio correct edges to estimated edges = ").append(nf2.format((correctEdges / (double) estimatedEdges)));
    return builder.toString();
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 14 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class GraphUtils method loadGraphRMatrix.

public static String loadGraphRMatrix(Graph graph) throws IllegalArgumentException {
    int[][] m = incidenceMatrix(graph);
    TextTable table = new TextTable(m[0].length + 1, m.length + 1);
    for (int i = 0; i < m.length; i++) {
        for (int j = 0; j < m[0].length; j++) {
            table.setToken(i + 1, j + 1, m[i][j] + "");
        }
    }
    for (int i = 0; i < m.length; i++) {
        table.setToken(i + 1, 0, (i + 1) + "");
    }
    List<Node> nodes = graph.getNodes();
    for (int j = 0; j < m[0].length; j++) {
        table.setToken(0, j + 1, nodes.get(j).getName());
    }
    return table.toString();
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable)

Example 15 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class GraphUtils method graphRMatrixTxt.

public static String graphRMatrixTxt(Graph graph) throws IllegalArgumentException {
    int[][] m = incidenceMatrix(graph);
    TextTable table = new TextTable(m[0].length + 1, m.length + 1);
    for (int i = 0; i < m.length; i++) {
        for (int j = 0; j < m[0].length; j++) {
            table.setToken(i + 1, j + 1, m[i][j] + "");
        }
    }
    for (int i = 0; i < m.length; i++) {
        table.setToken(i + 1, 0, (i + 1) + "");
    }
    List<Node> nodes = graph.getNodes();
    for (int j = 0; j < m[0].length; j++) {
        table.setToken(0, j + 1, nodes.get(j).getName());
    }
    return table.toString();
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable)

Aggregations

TextTable (edu.cmu.tetrad.util.TextTable)19 DecimalFormat (java.text.DecimalFormat)8 NumberFormat (java.text.NumberFormat)8 ArrayList (java.util.ArrayList)2 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)1 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)1 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)1 Statistic (edu.cmu.tetrad.algcomparison.statistic.Statistic)1 HasParameterValues (edu.cmu.tetrad.algcomparison.utils.HasParameterValues)1 DataSet (edu.cmu.tetrad.data.DataSet)1 SemIm (edu.cmu.tetrad.sem.SemIm)1 SemPm (edu.cmu.tetrad.sem.SemPm)1