X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Flinreg.c;h=147ff272cd54a4fee2e8bcb7aa83da3bea2baf05;hb=5f9212b9af772575bd3026ca9643684ce6493b3c;hp=63d1a0f976ee420ca52b476e67aa85cd94ff4a5e;hpb=a258e53c63a08b0ec48aea8f03808eb651729424;p=pspp diff --git a/src/math/linreg.c b/src/math/linreg.c index 63d1a0f976..147ff272cd 100644 --- a/src/math/linreg.c +++ b/src/math/linreg.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2005, 2010 Free Software Foundation, Inc. + Copyright (C) 2005, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,17 +15,21 @@ along with this program. If not, see . */ #include + +#include "math/linreg.h" + #include #include #include #include #include #include -#include -#include -#include -#include -#include + +#include "data/value.h" +#include "data/variable.h" +#include "linreg/sweep.h" + +#include "gl/xalloc.h" /* Find the least-squares estimate of b for the linear model: @@ -82,9 +86,6 @@ linreg_alloc (const struct variable *depvar, const struct variable **indep_vars, c->indep_means = gsl_vector_alloc (p); c->indep_std = gsl_vector_alloc (p); - c->ss_indeps = gsl_vector_alloc (p); /* Sums of squares for the - model parameters. - */ c->n_obs = n; c->n_indeps = p; c->n_coeffs = p; @@ -95,22 +96,27 @@ linreg_alloc (const struct variable *depvar, const struct variable **indep_vars, c->dfe = c->dft - c->dfm; c->intercept = 0.0; c->depvar_mean = 0.0; - c->depvar_std = 0.0; /* Default settings. */ c->method = LINREG_SWEEP; - c->pred = NULL; - c->resid = NULL; + + c->refcnt = 1; return c; } -bool -linreg_free (void *m) + +void +linreg_ref (linreg *c) { - linreg *c = m; - if (c != NULL) + c->refcnt++; +} + +void +linreg_unref (linreg *c) +{ + if (--c->refcnt == 0) { gsl_vector_free (c->indep_means); gsl_vector_free (c->indep_std); @@ -119,7 +125,6 @@ linreg_free (void *m) free (c->coeff); free (c); } - return true; } static void @@ -239,22 +244,10 @@ linreg_residual (const linreg *c, double obs, const double *vals, size_t n_vals) return (obs - linreg_predict (c, vals, n_vals)); } -double linreg_get_indep_variable_sd (linreg *c, size_t j) -{ - assert (c != NULL); - return gsl_vector_get (c->indep_std, j); -} - -void linreg_set_indep_variable_sd (linreg *c, size_t j, double s) -{ - assert (c != NULL); - gsl_vector_set (c->indep_std, j, s); -} - /* Mean of the independent variable. */ -double linreg_get_indep_variable_mean (linreg *c, size_t j) +double linreg_get_indep_variable_mean (const linreg *c, size_t j) { assert (c != NULL); return gsl_vector_get (c->indep_means, j); @@ -397,7 +390,7 @@ double linreg_intercept (const linreg *c) return c->intercept; } -gsl_matrix * +const gsl_matrix * linreg_cov (const linreg *c) { return c->cov; @@ -457,7 +450,7 @@ linreg_set_depvar_mean (linreg *c, double x) } double -linreg_get_depvar_mean (linreg *c) +linreg_get_depvar_mean (const linreg *c) { return c->depvar_mean; }