Ejemplo n.º 1
0
  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();
  }
Ejemplo n.º 2
0
  private String reportIfDiscrete(Graph dag, DataSet dataSet) {
    List vars = dataSet.getVariables();
    Map<String, DiscreteVariable> nodesToVars = new HashMap<String, DiscreteVariable>();
    for (int i = 0; i < dataSet.getNumColumns(); i++) {
      DiscreteVariable var = (DiscreteVariable) vars.get(i);
      String name = var.getName();
      Node node = new GraphNode(name);
      nodesToVars.put(node.getName(), var);
    }

    BayesPm bayesPm = new BayesPm(new Dag(dag));
    List<Node> nodes = bayesPm.getDag().getNodes();

    for (Node node : nodes) {
      Node var = nodesToVars.get(node.getName());

      if (var instanceof DiscreteVariable) {
        DiscreteVariable var2 = nodesToVars.get(node.getName());
        int numCategories = var2.getNumCategories();
        List<String> categories = new ArrayList<String>();
        for (int j = 0; j < numCategories; j++) {
          categories.add(var2.getCategory(j));
        }
        bayesPm.setCategories(node, categories);
      }
    }

    BayesProperties properties = new BayesProperties(dataSet, dag);
    properties.setGraph(dag);

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);

    StringBuilder buf = new StringBuilder();
    buf.append("\nP-value = ").append(properties.getLikelihoodRatioP());
    buf.append("\nDf = ").append(properties.getPValueDf());
    buf.append("\nChi square = ").append(nf.format(properties.getPValueChisq()));
    buf.append("\nBIC score = ").append(nf.format(properties.getBic()));
    buf.append("\n\nH0: Completely disconnected graph.");

    return buf.toString();
  }