/[pspp]/pspp/lib/linreg/linreg.c
ViewVC logotype

Diff of /pspp/lib/linreg/linreg.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by blp, Sun Oct 23 20:48:06 2005 UTC revision 1.4 by jstover, Fri Oct 28 20:52:37 2005 UTC
# Line 87  linreg_mean_std (gsl_vector_const_view v Line 87  linreg_mean_std (gsl_vector_const_view v
87  pspp_linreg_cache *  pspp_linreg_cache *
88  pspp_linreg_cache_alloc (size_t n, size_t p)  pspp_linreg_cache_alloc (size_t n, size_t p)
89  {  {
90    pspp_linreg_cache *cache;    pspp_linreg_cache *c;
91    
92    cache = (pspp_linreg_cache *) malloc (sizeof (pspp_linreg_cache));    c = (pspp_linreg_cache *) malloc (sizeof (pspp_linreg_cache));
93    cache->param_estimates = gsl_vector_alloc (p + 1);    c->param_estimates = gsl_vector_alloc (p + 1);
94    cache->indep_means = gsl_vector_alloc (p);    c->indep_means = gsl_vector_alloc (p);
95    cache->indep_std = gsl_vector_alloc (p);    c->indep_std = gsl_vector_alloc (p);
96    cache->ssx = gsl_vector_alloc (p);    /* Sums of squares for the independent    c->ssx = gsl_vector_alloc (p);        /* Sums of squares for the independent
97                                             variables.                                             variables.
98                                           */                                           */
99    cache->ss_indeps = gsl_vector_alloc (p);      /* Sums of squares for the model    c->ss_indeps = gsl_vector_alloc (p);  /* Sums of squares for the model
100                                                     parameters.                                             parameters.
101                                                   */                                           */
102    cache->cov = gsl_matrix_alloc (p + 1, p + 1); /* Covariance matrix. */    c->cov = gsl_matrix_alloc (p + 1, p + 1);     /* Covariance matrix. */
103    cache->n_obs = n;    c->n_obs = n;
104    cache->n_indeps = p;    c->n_indeps = p;
105    /*    /*
106       Default settings.       Default settings.
107     */     */
108    cache->method = PSPP_LINREG_SWEEP;    c->method = PSPP_LINREG_SWEEP;
109    
110    return cache;    return c;
111  }  }
112    
113  void  void
114  pspp_linreg_cache_free (pspp_linreg_cache * cache)  pspp_linreg_cache_free (pspp_linreg_cache * c)
115  {  {
116    gsl_vector_free (cache->param_estimates);    gsl_vector_free (c->param_estimates);
117    gsl_vector_free (cache->indep_means);    gsl_vector_free (c->indep_means);
118    gsl_vector_free (cache->indep_std);    gsl_vector_free (c->indep_std);
119    gsl_vector_free (cache->ss_indeps);    gsl_vector_free (c->ss_indeps);
120    gsl_matrix_free (cache->cov);    gsl_matrix_free (c->cov);
121    free (cache);    free (c->coeff);
122      free (c);
123  }  }
124    
125  /*  /*
# Line 180  pspp_linreg (const gsl_vector * Y, const Line 181  pspp_linreg (const gsl_vector * Y, const
181           standard deviations of the independent variables here since doing           standard deviations of the independent variables here since doing
182           so would cause a miscalculation of the residual sums of           so would cause a miscalculation of the residual sums of
183           squares. Dividing by the standard deviation is done GSL's linear           squares. Dividing by the standard deviation is done GSL's linear
184           regression functions, so if the design matrix has a very poor           regression functions, so if the design matrix has a poor
185           condition, use QR decomposition.           condition, use QR decomposition.
186           *  
187           The design matrix here does not include a column for the intercept           The design matrix here does not include a column for the intercept
188           (i.e., a column of 1's). If using PSPP_LINREG_QR, we need that column,           (i.e., a column of 1's). If using PSPP_LINREG_QR, we need that column,
189           so design is allocated here when sweeping, or below if using QR.           so design is allocated here when sweeping, or below if using QR.
# Line 244  pspp_linreg (const gsl_vector * Y, const Line 245  pspp_linreg (const gsl_vector * Y, const
245        for (i = 0; i < cache->n_indeps; i++)        for (i = 0; i < cache->n_indeps; i++)
246          {          {
247            tmp = gsl_matrix_get (sw, i, cache->n_indeps);            tmp = gsl_matrix_get (sw, i, cache->n_indeps);
248              cache->coeff[i + 1].estimate = tmp;
249            gsl_vector_set (cache->param_estimates, i + 1, tmp);            gsl_vector_set (cache->param_estimates, i + 1, tmp);
250            m -= tmp * gsl_vector_get (cache->indep_means, i);            m -= tmp * gsl_vector_get (cache->indep_means, i);
251          }          }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26