From: Jason Stover Date: Fri, 28 Oct 2005 20:54:06 +0000 (+0000) Subject: Added variable/parameter matching and error reporting X-Git-Tag: v0.6.0~1157 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b80235141f331530de337cceeab87de873c5cc2;p=pspp-builds.git Added variable/parameter matching and error reporting --- diff --git a/src/regression.q b/src/regression.q index ca0b65f5..56420c53 100644 --- a/src/regression.q +++ b/src/regression.q @@ -24,16 +24,19 @@ #include #include "alloc.h" #include "case.h" +#include "casefile.h" +#include "cat.h" +#include "command.h" #include "dictionary.h" +#include "error.h" #include "file-handle.h" -#include "command.h" +#include "gettext.h" #include "lexer.h" +#include #include "tab.h" #include "var.h" #include "vfm.h" -#include "casefile.h" -#include -#include "cat.h" + /* (headers) */ @@ -69,6 +72,11 @@ static struct cmd_regression cmd; */ size_t *indep_vars; +/* + Return value for the procedure. + */ +int pspp_reg_rc = CMD_SUCCESS; + static void run_regression (const struct casefile *, void *); /* STATISTICS subcommand output functions. @@ -143,7 +151,8 @@ reg_stats_coeff (pspp_linreg_cache * c) struct tab_table *t; assert (c != NULL); - n_rows = 2 + c->param_estimates->size; + n_rows = 2; + t = tab_create (n_cols, n_rows, 0); tab_headers (t, 2, 0, 1, 0); tab_dim (t, tab_natural_dimensions); @@ -462,7 +471,7 @@ cmd_regression (void) } multipass_procedure_with_splits (run_regression, &cmd); - return CMD_SUCCESS; + return pspp_reg_rc; } /* @@ -492,6 +501,7 @@ run_regression (const struct casefile *cf, void *cmd_ UNUSED) size_t n_data = 0; size_t row; int n_indep; + int j = 0; const union value *val; struct casereader *r; struct casereader *r2; @@ -560,7 +570,13 @@ run_regression (const struct casefile *cf, void *cmd_ UNUSED) */ if (is_depvar (i)) { - assert (v->type == NUMERIC); + if (v->type != NUMERIC) + { + msg (SE, gettext ("Dependent variable must be numeric.")); + pspp_reg_rc = CMD_FAILURE; + return; + } + lcache->depvar = (const struct var *) v; gsl_vector_set (Y, row, val->f); } else @@ -581,6 +597,18 @@ run_regression (const struct casefile *cf, void *cmd_ UNUSED) } } } + /* + Now that we know the number of coefficients, allocate space + and store pointers to the variables that correspond to the + coefficients. + */ + lcache->coeff = xnmalloc (X->m->size2 + 1, sizeof (*lcache->coeff)); + for (i = 0; i < X->m->size2; i++) + { + j = i + 1; /* The first coeff is the intercept. */ + lcache->coeff[j].v = + (const struct variable *) design_matrix_col_to_var (X, i); + } /* Find the least-squares estimates and other statistics. */ @@ -592,6 +620,7 @@ run_regression (const struct casefile *cf, void *cmd_ UNUSED) free (lopts.get_indep_mean_std); free (indep_vars); casereader_destroy (r); + return; } /*