1 /* lib/linreg/predict.c
3 Copyright (C) 2005 Free Software Foundation, Inc.
4 Written by Jason H. Stover.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <math/linreg/linreg.h>
23 #include <math/linreg/coefficient.h>
26 Predict the value of the dependent variable with the
27 new set of predictors. PREDICTORS must point to a list
28 of variables, each of whose values are stored in VALS,
32 pspp_linreg_predict (const struct variable **predictors,
33 const union value **vals,
34 const pspp_linreg_cache *c,
41 if (predictors == NULL || vals == NULL || c == NULL)
47 /* The stupid model: just guess the mean. */
48 return c->depvar_mean;
50 result = c->coeff->estimate; /* Intercept. */
53 Stop at the minimum of c->n_coeffs and n_vals in case
54 the caller passed us inadequate information, such as too
55 few or too many values.
58 for (i = 1; i < c->n_coeffs && i < n_vals; i++)
60 tmp = pspp_linreg_coeff_get_est (pspp_linreg_get_coeff (c, predictors[i], vals[i]));
61 if (predictors[i]->type == NUMERIC)
71 pspp_linreg_residual (const struct variable *predictors,
72 const union value **vals,
73 const union value *obs,
74 const pspp_linreg_cache *c,
80 if (predictors == NULL || vals == NULL || c == NULL || obs == NULL)
85 pred = pspp_linreg_predict (predictors, vals, c, n_vals);
87 result = gsl_isnan (pred) ? GSL_NAN : (obs->f - pred);