FACTOR: Improve calculation of Kaiser-Meyer-Olkin and add a test
[pspp] / src / language / stats / factor.c
index a1cd333389c7276bc5a6ed7c37b776f2daf583a1..095d98ff35c5c0c290bae9cc3c6ab45f1fdd9afb 100644 (file)
@@ -293,7 +293,7 @@ ssq_row_od_n (const gsl_matrix *m, int j)
   return ss;
 }
 
-/* Return the sum of all the elements excluding row N */
+/* Return the sum of squares of all the elements excluding row N */
 static double
 ssq_od_n (const gsl_matrix *m, int n)
 {
@@ -305,9 +305,9 @@ ssq_od_n (const gsl_matrix *m, int n)
 
   for (i = 0; i < m->size1; ++i)
     {
-      if (i == n ) continue;
       for (j = 0; j < m->size2; ++j)
        {
+         if (i == j) continue;
          ss += pow2 (gsl_matrix_get (m, i, j));
        }
     }
@@ -2384,8 +2384,8 @@ do_factor_by_matrix (const struct cmd_factor *factor, struct idata *idata)
   double sum_ssq_a = 0;
   for (i = 0; i < r_inv->size1; ++i)
     {
-      sum_ssq_r += ssq_od_n (r_inv, i);
-      sum_ssq_a += ssq_od_n (idata->ai_cov, i);
+      sum_ssq_r += ssq_od_n (idata->mm.corr, i);
+      sum_ssq_a += ssq_od_n (idata->ai_cor, i);
     }
 
   gsl_matrix_free (r_inv);