From 96b31e17b2c336995db448531ab7f86f57319b5f Mon Sep 17 00:00:00 2001 From: Jason H Stover Date: Fri, 12 Sep 2008 17:47:43 -0400 Subject: [PATCH] Do not use const in pspp_linreg_get_vars. Use correct covariance matrix in pspp_linreg_with_cov. Initialize model cache in glm.q --- src/language/stats/glm.q | 14 +++++++++++++- src/math/linreg.c | 6 +++--- src/math/linreg.h | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/language/stats/glm.q b/src/language/stats/glm.q index 1b91ba81..ad8bf55e 100644 --- a/src/language/stats/glm.q +++ b/src/language/stats/glm.q @@ -47,7 +47,7 @@ #include "xalloc.h" #include "gettext.h" -#define GLM_LARGE_DATA 1000 +#define GLM_LARGE_DATA 10000 /* (headers) */ @@ -339,6 +339,17 @@ run_glm (struct casereader *input, } } } + model = pspp_linreg_cache_alloc (n_data, n_indep); + model->depvar = v_dependent; + /* + For large data sets, use QR decomposition. + */ + if (n_data > sqrt (n_indep) && n_data > GLM_LARGE_DATA) + { + model->method = PSPP_LINREG_QR; + } + coeff_init (model, X); + pspp_linreg_with_cov (X, model); casereader_destroy (reader); for (i = 0; i < n_all_vars; i++) { @@ -357,6 +368,7 @@ run_glm (struct casereader *input, } free (indep_vars); free (lopts.get_indep_mean_std); + pspp_linreg_cache_free (model); casereader_destroy (input); return true; diff --git a/src/math/linreg.c b/src/math/linreg.c index 2fb98cf7..355261b6 100644 --- a/src/math/linreg.c +++ b/src/math/linreg.c @@ -96,7 +96,7 @@ linreg_mean_std (gsl_vector_const_view v, double *mp, double *sp, double *ssp) The return value is the number of distinct variables found. */ int -pspp_linreg_get_vars (const void *c_, const struct variable **v) +pspp_linreg_get_vars (const void *c_, struct variable **v) { const pspp_linreg_cache *c = c_; const struct variable *tmp; @@ -666,7 +666,7 @@ rearrange_covariance_matrix (const struct design_matrix *cov, pspp_linreg_cache v = xnmalloc (c->n_coeffs, sizeof (*v)); model_vars = xnmalloc (c->n_coeffs, sizeof (*model_vars)); columns = xnmalloc (cov->m->size2, sizeof (*columns)); - n_vars = pspp_linreg_get_vars (c, (const struct variable **) v); + n_vars = pspp_linreg_get_vars (c, v); dep_col = 0; k = 0; for (i = 0; i < cov->m->size2; i++) @@ -731,7 +731,7 @@ pspp_linreg_with_cov (const struct design_matrix *full_cov, { struct design_matrix *cov; - assert (cov != NULL); + assert (full_cov != NULL); assert (cache != NULL); cov = rearrange_covariance_matrix (full_cov, cache); diff --git a/src/math/linreg.h b/src/math/linreg.h index 05c81596..18f962c0 100644 --- a/src/math/linreg.h +++ b/src/math/linreg.h @@ -197,7 +197,7 @@ pspp_linreg_residual (const struct variable **, const union value **, /* All variables used in the model. */ -int pspp_linreg_get_vars (const void *, const struct variable **); +int pspp_linreg_get_vars (const void *, struct variable **); struct pspp_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache *, -- 2.30.2