Search in sources :

Example 11 with SemEstimator

use of edu.cmu.tetrad.sem.SemEstimator in project tetrad by cmu-phil.

the class PcGesSearchEditor method reportIfCovMatrix.

private String reportIfCovMatrix(Graph dag, ICovarianceMatrix dataSet) {
    SemPm semPm = new SemPm(dag);
    SemEstimator estimator = new SemEstimator(dataSet, semPm);
    estimator.estimate();
    SemIm semIm = estimator.getEstimatedSem();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    buf.append("\nDegrees of Freedom = ").append(semPm.getDof()).append(" Chi-Square = ").append(nf.format(semIm.getChiSquare())).append("\nP Value = ").append(nf.format(semIm.getPValue())).append("\nBIC Score = ").append(nf.format(semIm.getBicScore()));
    buf.append("\n\nThe above chi square test assumes that the maximum " + "likelihood function over the measured variables has been " + "maximized. Under that assumption, the null hypothesis for " + "the test is that the population covariance matrix over all " + "of the measured variables is equal to the estimated covariance " + "matrix over all of the measured variables written as a function " + "of the free model parameters--that is, the unfixed parameters " + "for each directed edge (the linear coefficient for that edge), " + "each exogenous variable (the variance for the error term for " + "that variable), and each bidirected edge (the covariance for " + "the exogenous variables it connects).  The model is explained " + "in Bollen, Structural Equations with Latent Variable, 110. ");
    return buf.toString();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 12 with SemEstimator

use of edu.cmu.tetrad.sem.SemEstimator in project tetrad by cmu-phil.

the class PcGesSearchEditor method reportIfContinuous.

private String reportIfContinuous(Graph dag, DataSet dataSet) {
    SemPm semPm = new SemPm(dag);
    SemEstimator estimator = new SemEstimator(dataSet, semPm);
    estimator.estimate();
    SemIm semIm = estimator.getEstimatedSem();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    buf.append("\nDegrees of Freedom = ").append(semPm.getDof()).append(" Chi-Square = ").append(nf.format(semIm.getChiSquare())).append("\nP Value = ").append(nf.format(semIm.getPValue())).append("\nBIC Score = ").append(nf.format(semIm.getBicScore()));
    buf.append("\n\nThe above chi square test assumes that the maximum " + "likelihood function over the measured variables has been " + "maximized. Under that assumption, the null hypothesis for " + "the test is that the population covariance matrix over all " + "of the measured variables is equal to the estimated covariance " + "matrix over all of the measured variables written as a function " + "of the free model parameters--that is, the unfixed parameters " + "for each directed edge (the linear coefficient for that edge), " + "each exogenous variable (the variance for the error term for " + "that variable), and each bidirected edge (the covariance for " + "the exogenous variables it connects).  The model is explained " + "in Bollen, Structural Equations with Latent Variable, 110. ");
    return buf.toString();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 13 with SemEstimator

use of edu.cmu.tetrad.sem.SemEstimator in project tetrad by cmu-phil.

the class SemEstimatorEditor method resetSemImEditor.

private void resetSemImEditor() {
    java.util.List<SemEstimator> semEstimators = wrapper.getMultipleResultList();
    if (semEstimators.size() == 1) {
        SemEstimator estimatedSem = semEstimators.get(0);
        SemImEditor editor = new SemImEditor(new SemImWrapper(estimatedSem.getEstimatedSem()));
        panel.removeAll();
        panel.add(editor, BorderLayout.CENTER);
        panel.revalidate();
        panel.repaint();
    } else {
        JTabbedPane tabs = new JTabbedPane();
        for (int i = 0; i < semEstimators.size(); i++) {
            SemEstimator estimatedSem = semEstimators.get(i);
            SemImEditor editor = new SemImEditor(new SemImWrapper(estimatedSem.getEstimatedSem()));
            JPanel _panel = new JPanel();
            _panel.setLayout(new BorderLayout());
            _panel.add(editor, BorderLayout.CENTER);
            tabs.addTab(estimatedSem.getDataSet().getName(), _panel);
        }
        panel.removeAll();
        panel.add(tabs);
        panel.validate();
    }
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JTabbedPane(javax.swing.JTabbedPane) SemImWrapper(edu.cmu.tetradapp.model.SemImWrapper) SemEstimator(edu.cmu.tetrad.sem.SemEstimator)

Example 14 with SemEstimator

use of edu.cmu.tetrad.sem.SemEstimator in project tetrad by cmu-phil.

the class SemEstimatorEditor method compileReport.

private String compileReport() {
    StringBuilder builder = new StringBuilder();
    builder.append("Datset\tFrom\tTo\tType\tValue\tSE\tT\tP");
    java.util.List<SemEstimator> estimators = wrapper.getMultipleResultList();
    for (int i = 0; i < estimators.size(); i++) {
        SemEstimator estimator = estimators.get(i);
        SemIm estSem = estimator.getEstimatedSem();
        String dataName = estimator.getDataSet().getName();
        estSem.getFreeParameters().forEach(parameter -> {
            builder.append("\n");
            builder.append(dataName).append("\t");
            builder.append(parameter.getNodeA()).append("\t");
            builder.append(parameter.getNodeB()).append("\t");
            builder.append(typeString(parameter)).append("\t");
            builder.append(asString(paramValue(estSem, parameter))).append("\t");
            /**
             * Maximum number of free parameters for which statistics will
             * be calculated. (Calculating standard errors is high
             * complexity.) Set this to zero to turn off statistics
             * calculations (which can be problematic sometimes).
             */
            int maxFreeParamsForStatistics = 200;
            builder.append(asString(estSem.getStandardError(parameter, maxFreeParamsForStatistics))).append("\t");
            builder.append(asString(estSem.getTValue(parameter, maxFreeParamsForStatistics))).append("\t");
            builder.append(asString(estSem.getPValue(parameter, maxFreeParamsForStatistics))).append("\t");
        });
        List<Node> nodes = estSem.getVariableNodes();
        for (int j = 0; j < nodes.size(); j++) {
            Node node = nodes.get(j);
            int n = estSem.getSampleSize();
            int df = n - 1;
            double mean = estSem.getMean(node);
            double stdDev = estSem.getMeanStdDev(node);
            double stdErr = stdDev / Math.sqrt(n);
            double tValue = mean / stdErr;
            double p = 2.0 * (1.0 - ProbUtils.tCdf(Math.abs(tValue), df));
            builder.append("\n");
            builder.append(dataName).append("\t");
            builder.append(nodes.get(j)).append("\t");
            builder.append(nodes.get(j)).append("\t");
            builder.append("Mean").append("\t");
            builder.append(asString(mean)).append("\t");
            builder.append(asString(stdErr)).append("\t");
            builder.append(asString(tValue)).append("\t");
            builder.append(asString(p)).append("\t");
        }
    }
    return builder.toString();
}
Also used : Node(edu.cmu.tetrad.graph.Node) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 15 with SemEstimator

use of edu.cmu.tetrad.sem.SemEstimator in project tetrad by cmu-phil.

the class Washdown method gof.

/**
 * @return the p value of the given model.
 */
private double gof(List<List<Node>> clusters) {
    clusters = removeEmpty(clusters);
    Graph graph = pureMeasurementModel(clusters);
    SemPm pm = new SemPm(graph);
    SemEstimator estimator;
    if (cov != null) {
        estimator = new SemEstimator(cov, pm);
    } else {
        estimator = new SemEstimator(dataSet, pm);
    }
    SemIm est = estimator.estimate();
    return est.getBicScore();
}
Also used : SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator) SemIm(edu.cmu.tetrad.sem.SemIm)

Aggregations

SemEstimator (edu.cmu.tetrad.sem.SemEstimator)18 SemPm (edu.cmu.tetrad.sem.SemPm)16 SemIm (edu.cmu.tetrad.sem.SemIm)15 DataSet (edu.cmu.tetrad.data.DataSet)6 Test (org.junit.Test)6 Graph (edu.cmu.tetrad.graph.Graph)4 Node (edu.cmu.tetrad.graph.Node)4 StandardizedSemIm (edu.cmu.tetrad.sem.StandardizedSemIm)4 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)3 GraphNode (edu.cmu.tetrad.graph.GraphNode)3 Parameter (edu.cmu.tetrad.sem.Parameter)3 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)3 NumberFormat (java.text.NumberFormat)3 ArrayList (java.util.ArrayList)2 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)1 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1 DataModel (edu.cmu.tetrad.data.DataModel)1 Dag (edu.cmu.tetrad.graph.Dag)1