added SAVE subcommand
authorJason Stover <jhs@math.gcsu.edu>
Sat, 8 Apr 2006 02:44:49 +0000 (02:44 +0000)
committerJason Stover <jhs@math.gcsu.edu>
Sat, 8 Apr 2006 02:44:49 +0000 (02:44 +0000)
src/language/stats/ChangeLog
src/language/stats/regression.q

index a3d8eb2c6a9a9d1b90ae2ef19f65e29f4e507129..89829de204bbdc11eeda7cbed9f4e34edbc208bb 100644 (file)
@@ -1,3 +1,7 @@
+2006-04-07  Jason Stover  <jhs@math.gcsu.edu>
+
+       * regression.q (subcommand_save): New function.
+
 2006-04-04  Jason Stover  <jhs@math.gcsu.edu>
 
        * regression.q: New function reg_has_categorical () to tell
index ef0041e8b6fa0407afb2a8c354099eb6e2511edf..11a1f211c87c35889413634a652ab715825c5b8a 100644 (file)
@@ -71,6 +71,7 @@
    all;
    export=custom;
    ^dependent=varlist;
+   save=residuals;
    method=enter.
 */
 /* (declarations) */
@@ -500,6 +501,37 @@ subcommand_statistics (int *keywords, pspp_linreg_cache * c)
   statistics_keyword_output (reg_stats_tol, keywords[tol], c);
   statistics_keyword_output (reg_stats_selection, keywords[selection], c);
 }
+static void
+subcommand_save (int save, pspp_linreg_cache *lc, const struct casefile *cf, int *is_missing)
+{
+  int i;
+  int k;
+  int case_num;
+  double residual;
+  const union value **vals;
+  struct casereader *r;
+  struct ccase c;
+
+  assert (lc != NULL);
+  if (save)
+    {
+      vals = xnmalloc (n_variables, sizeof (*vals));
+      for (r = casefile_get_reader (cf); casereader_read (r, &c);
+          case_destroy (&c))
+       {
+         case_num = casereader_cnum (r) - 1;
+         if (!is_missing[case_num])
+           {
+             for (i = 0; i < n_variables; ++i)
+               {
+                 vals[i] = case_data (&c, v_variables[i]->fv);
+               }
+             residual = (*lc->predict) (v_variables, vals, lc, n_variables);
+           }
+       }
+      free (vals);
+    }
+}
 static int
 reg_inserted (const struct variable *v, struct variable **varlist, int n_vars)
 {
@@ -1002,6 +1034,7 @@ run_regression (const struct casefile *cf, void *cmd_ UNUSED)
        */
       pspp_linreg ((const gsl_vector *) Y, X->m, &lopts, lcache);
       subcommand_statistics (cmd.a_statistics, lcache);
+      subcommand_save (cmd.sbc_save, lcache, cf, is_missing_case);
       subcommand_export (cmd.sbc_export, lcache);
       gsl_vector_free (Y);
       design_matrix_destroy (X);