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();
}
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();
}
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();
}
}
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();
}
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();
}
Aggregations