Return 0.0 for mean of a categorical variable. Fixes bug mentioned in bug report...
[pspp-builds.git] / src / math / linreg.c
index f5ae33e5823f4f79cfaccd73637316baa2f96d0f..baf9cb737e8250b59a8814dac93dc5ca5b768390 100644 (file)
@@ -641,7 +641,7 @@ double pspp_linreg_get_indep_variable_mean (pspp_linreg_cache *c, const struct v
       coef = pspp_linreg_get_coeff (c, v, NULL);
       return pspp_coeff_get_mean (coef);
     }
-  return GSL_NAN;
+  return 0.0;
 }
 
 void pspp_linreg_set_indep_variable_mean (pspp_linreg_cache *c, const struct variable *v, 
@@ -669,6 +669,7 @@ rearrange_covariance_matrix (const struct covariance_matrix *cm, pspp_linreg_cac
   size_t i;
   size_t j;
   size_t k;
+  size_t n_coeffs = 0;
 
   assert (cm != NULL);
   cov = covariance_to_design (cm);
@@ -676,11 +677,11 @@ rearrange_covariance_matrix (const struct covariance_matrix *cm, pspp_linreg_cac
   assert (c != NULL);
   assert (cov->m->size1 > 0);
   assert (cov->m->size2 == cov->m->size1);
-  permutation = xnmalloc (1 + c->n_indeps, sizeof (*permutation));
   model_vars = xnmalloc (1 + c->n_indeps, sizeof (*model_vars));
 
   /*
     Put the model variables in the right order in MODEL_VARS.
+    Count the number of coefficients.
    */
   for (i = 0; i < c->n_indeps; i++)
     {
@@ -688,6 +689,8 @@ rearrange_covariance_matrix (const struct covariance_matrix *cm, pspp_linreg_cac
     }
   model_vars[i] = c->depvar;
   result = covariance_matrix_create (1 + c->n_indeps, model_vars);
+  permutation = xnmalloc (design_matrix_get_n_cols (result), sizeof (*permutation));
+
   for (j = 0; j < cov->m->size2; j++)
     {
       k = 0;
@@ -742,4 +745,3 @@ double pspp_linreg_mse (const pspp_linreg_cache *c)
   assert (c != NULL);
   return (c->sse / c->dfe);
 }
-