public double[] getCumulativeInertia() { double tot = 0.0; for (double val : ca.getRates()) { tot += val; } double[] p = new double[ca.getRates().length]; for (int i = 0; i < p.length; i++) { p[i] = ca.getRates()[i] / tot; if (i > 0) p[i] += p[i - 1]; } return p; }
public ResultCA(CorrespondenceAnalysis ca, Word[] rowlabs, ConciseDocument[] collabs) { this.rowlabs = rowlabs; this.collabs = collabs; principal = ca.getPrincipalMatrix(); n = principal.getRowDimension(); m = principal.getColumnDimension(); double[][] data = principal.getArray(); double[] rowmass = principal.getRowMass(); double[] colmass = principal.getColumnMass(); double trace = ca.getTrace(); this.ca = ca; int nfactor = Math.min(n, m) - 1; // First determine inertias of observations (rows) and // variables (columns), and qualities of representation // in the new factor space. rinertia = new double[n]; // relative inertia cinertia = new double[m]; rquality = new double[n]; // quality cquality = new double[m]; for (int i = 0; i < n; i++) { rinertia[i] = 0.0; rquality[i] = 0.0; for (int j = 0; j < m; j++) { rinertia[i] += Math.pow((data[i][j] / rowmass[i] - colmass[j]), 2.0) / colmass[j]; } rinertia[i] = rowmass[i] * rinertia[i] / trace; for (int k = 1; k <= nfactor; k++) { rquality[i] += ca.getRowCorrelations()[i][k]; } } for (int j = 0; j < m; j++) { cinertia[j] = 0.0; cquality[j] = 0.0; for (int i = 0; i < n; i++) { cinertia[j] += Math.pow((data[i][j] / colmass[j] - rowmass[i]), 2.0) / rowmass[i]; } cinertia[j] = colmass[j] * cinertia[j] / trace; for (int k = 1; k <= nfactor; k++) { cquality[j] += ca.getColumnCorrelations()[j][k]; } } }
public double[][] getRowContributions() { return ca.getRowContributions(); }
public double[][] getRowCorrelations() { return ca.getRowCorrelations(); }
public double[][] getRowProjections() { return ca.getRowProjections(); }
public double getTrace() { return ca.getTrace(); }
public double[] getLambda() { return ca.getEigenvalues(); }
public double[] getRatesOfInertia() { return ca.getRates(); }
public double[][] getColumnContributions() { return ca.getColumnContributions(); }
public double[][] getColumnCorrelations() { return ca.getColumnCorrelations(); }
public double[][] getColumnProjections() { return ca.getColumnProjections(); }