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)
+static int
+regression_trns_proc (void *m, struct ccase *c, int case_idx UNUSED)
{
- int i;
- int case_num;
- double residual;
- const union value **vals;
- struct casereader *r;
- struct ccase c;
-
- assert (lc != NULL);
- assert (is_missing != NULL);
+ size_t i;
+ size_t n_vars;
+ pspp_linreg_cache *model = m;
+ union value *output;
+ const union value **vals = NULL;
+ const union value *obs = NULL;
+ struct variable **vars = NULL;
+
+ assert (model != NULL);
+ assert (model->depvar != NULL);
+ assert (model->resid != NULL);
+
+ dict_get_vars (default_dict, &vars, &n_vars, 1u << DC_ORDINARY);
+ vals = xnmalloc (n_vars, sizeof (*vals));
+ assert (vals != NULL);
+ output = case_data_rw (c, model->resid->fv);
+ assert (output != NULL);
- if (save)
+ for (i = 0; i < n_vars; i++)
{
- vals = xnmalloc (n_variables, sizeof (*vals));
- for (r = casefile_get_reader (cf); casereader_read (r, &c);
- case_destroy (&c))
+ /* Do not use the residual variable. */
+ if (vars[i]->index != model->resid->index)
{
- case_num = casereader_cnum (r) - 1;
- if (!is_missing[case_num])
+ /* Do not use the dependent variable as a predictor. */
+ if (vars[i]->index == model->depvar->index)
{
- for (i = 0; i < n_variables; ++i)
- {
- vals[i] = case_data (&c, v_variables[i]->fv);
- }
- residual = (*lc->predict) ((const struct variable **) v_variables,
- (const union value **) vals, lc, n_variables);
+ obs = case_data (c, i);
+ assert (obs != NULL);
+ }
+ else
+ {
+ vals[i] = case_data (c, i);
}
}
- free (vals);
+ }
+ output->f = (*model->residual) ((const struct variable **) vars,
+ vals, obs, model, i);
+ free (vals);
+ return TRNS_CONTINUE;
+}
+static void
+subcommand_save (int save, pspp_linreg_cache *lc)
+{
+ struct variable *residuals = NULL;
+
+ assert (lc != NULL);
+ assert (lc->depvar != NULL);
+
+ if (save)
+ {
+ residuals = dict_create_var (default_dict, "residuals", 0);
+ assert (residuals != NULL);
+ lc->resid = residuals;
+ add_transformation (regression_trns_proc, pspp_linreg_cache_free, lc);
+ }
+ else
+ {
+ pspp_linreg_cache_free (lc);
}
}
static int
{
assert (c != NULL);
assert (model_file != NULL);
- fp = fopen (fh_get_filename (model_file), "w");
+ fp = fopen (fh_get_file_name (model_file), "w");
assert (fp != NULL);
fprintf (fp, "%s", reg_preamble);
reg_print_getvar (fp, c);
*/
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);
+ subcommand_save (cmd.sbc_save, lcache);
gsl_vector_free (Y);
design_matrix_destroy (X);
free (indep_vars);
- pspp_linreg_cache_free (lcache);
free (lopts.get_indep_mean_std);
casereader_destroy (r);
}