fixed counting of valid cases in fill_covariance
[pspp-builds.git] / src / language / stats / regression.q
index 6e97fd10be3f0b6e64c9f8f2ef8aef0e560385b1..2b31158d5418c8009f2fbab38fad2c75dd216af3 100644 (file)
@@ -659,8 +659,6 @@ subcommand_save (struct dataset *ds, int save, linreg ** models)
   int n_trns = 0;
   int i;
 
-  assert (models != NULL);
-
   if (save)
     {
       /* Count the number of transformations we will need. */
@@ -823,22 +821,17 @@ fill_covariance (gsl_matrix *cov, struct covariance *all_cov,
   
   for (i = 0; i < n_all_vars; i++)
     {
-      for (j = k; j < n_vars; j++)
+      for (j = 0; j < n_vars; j++)
        {
          if (vars[j] == all_vars[i])
            {
-             if (vars[j] != dep_var)
-               {
-                 rows[j] = i;
-               }
-             else
-               {
-                 dep_subscript = i;
-               }
-             k++;
-             break;
+             rows[j] = i;
            }
        }
+      if (all_vars[i] == dep_var)
+       {
+         dep_subscript = i;
+       }
     }
   for (i = 0; i < cov->size1 - 1; i++)
     {
@@ -862,6 +855,7 @@ fill_covariance (gsl_matrix *cov, struct covariance *all_cov,
        }
     }
   free (rows);
+  return result;
 }
 
 static bool
@@ -953,6 +947,8 @@ run_regression (struct casereader *input, struct cmd_regression *cmd,
        {
          msg (SE,
               gettext ("No valid data found. This command was skipped."));
+         linreg_free (models[k]);
+         models[k] = NULL;
        }
     }