public double mcdonaldOmega() {
   double omega = 0.0;
   double sumLambda = 0.0, sumLambda2 = 0.0;
   double sumErrorVar = 0.0;
   double[] fl = model.getFactorLoading();
   double[] er = model.getErrorVariance();
   for (int i = 0; i < nItems; i++) {
     sumLambda += fl[i];
     sumErrorVar += er[i];
   }
   sumLambda2 = Math.pow(sumLambda, 2);
   omega = sumLambda2 / (sumLambda2 + sumErrorVar);
   return omega;
 }
 public AbstractConfirmatoryFactorAnalysisEstimator(
     ConfirmatoryFactorAnalysisModel model, RealMatrix varcov, double numberOfExaminees) {
   this.model = model;
   this.varcov = varcov;
   this.numberOfExaminees = numberOfExaminees;
   this.nItems = model.getNumberOfItems();
   LUDecomposition CVLUD = new LUDecomposition(varcov);
   VCinv = CVLUD.getSolver().getInverse();
 }
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    double[] fl = model.getFactorLoading();
    double[] er = model.getErrorVariance();

    for (int i = 0; i < nItems; i++) {
      f.format("% .4f", fl[i]);
      f.format("%5s", "");
      f.format("% .4f", er[i]);
      f.format("%n");
    }

    f.format("%10s", "McDonald's Omega = ");
    f.format("%8.4f", mcdonaldOmega());
    f.format("%n");
    f.format("%10s", "GFI = ");
    f.format("%8.4f", gfi());
    f.format("%n");
    f.format("%10s", "AGFI = ");
    f.format("%8.4f", agfi());
    f.format("%n");
    f.format("%10s", "RMSEA = ");
    f.format("%8.4f", rmsea());
    f.format("%n");
    f.format("%10s", "RMSR = ");
    f.format("%8.4f", Math.sqrt(meanSquaredResidual()));
    f.format("%n");
    f.format("%10s", "BIC = ");
    f.format("%8.4f", Math.sqrt(bic()));
    f.format("%n");
    f.format("%10s", "X^2 = ");
    f.format("%8.4f", chisquare());
    f.format("%n");
    f.format("%10s", "df = ");
    f.format("%8.4f", degreesOfFreedom());
    f.format("%n");
    f.format("%10s", "p = ");
    f.format("%8.4f", pvalue());
    f.format("%n");
    return f.toString();
  }
  public String printEstimates(ArrayList<VariableInfo> items) {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb);
    double[] fl = model.getFactorLoading();
    double[] er = model.getErrorVariance();
    //        f.format("%50s", "       CONFIRMATORY FACTOR ANALYSIS RESULTS       ");
    f.format("%n");
    f.format("%-50s", model.getName());
    f.format("%n");
    f.format("%50s", "==================================================");
    f.format("%n");
    f.format("%10s", "     ");
    f.format("%5s", "");
    f.format("%10s", "Factor ");
    f.format("%5s", "");
    f.format("%10s", " Error");
    f.format("%n");
    f.format("%10s", " Item");
    f.format("%5s", "");
    f.format("%10s", "Loading");
    f.format("%5s", "");
    f.format("%10s", "Variance");
    f.format("%n");
    f.format("%50s", "--------------------------------------------------");
    f.format("%n");

    for (int i = 0; i < items.size(); i++) {
      f.format("%10s", items.get(i));
      f.format("%5s", "");
      f.format("% 10.4f", fl[i]);
      f.format("%5s", "");
      f.format("% 10.4f", er[i]);
      f.format("%n");
    }
    f.format("%50s", "--------------------------------------------------");
    f.format("%n");
    return f.toString();
  }
 public double degreesOfFreedom() {
   double ni = Double.valueOf(nItems).doubleValue();
   double m = (ni * (ni + 1.0)) / 2.0;
   double df = m - model.getNumberOfParameters();
   return df;
 }
 public double bic() {
   double b = chisquare() + model.getNumberOfParameters() * Math.log(numberOfExaminees) * nItems;
   return b;
 }