From: Jason Stover Date: Fri, 17 Jul 2009 20:02:02 +0000 (-0400) Subject: pspp_linreg(): Use cache->n_coeffs to set the dimensions of sw, instead of X-Git-Tag: sav-api~248^2~63^2~8 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=324b25ac025d75a164ba4506175be6d265681108;p=pspp pspp_linreg(): Use cache->n_coeffs to set the dimensions of sw, instead of cache->n_indeps, which may give incorrect dimension in the case of categorical variables. Fixes bug referenced in bug report 26861. --- diff --git a/src/math/linreg.c b/src/math/linreg.c index 2b4f7c9069..a01158b50b 100644 --- a/src/math/linreg.c +++ b/src/math/linreg.c @@ -368,8 +368,8 @@ pspp_linreg (const gsl_vector * Y, const struct design_matrix *dm, gsl_matrix_set (design, j, i, tmp); } } - sw = gsl_matrix_calloc (cache->n_indeps + 1, cache->n_indeps + 1); - xtx = gsl_matrix_submatrix (sw, 0, 0, cache->n_indeps, cache->n_indeps); + sw = gsl_matrix_calloc (cache->n_coeffs + 1, cache->n_coeffs + 1); + xtx = gsl_matrix_submatrix (sw, 0, 0, cache->n_coeffs, cache->n_coeffs); for (i = 0; i < xtx.matrix.size1; i++) { @@ -384,8 +384,8 @@ pspp_linreg (const gsl_vector * Y, const struct design_matrix *dm, } } - gsl_matrix_set (sw, cache->n_indeps, cache->n_indeps, cache->sst); - xty = gsl_matrix_column (sw, cache->n_indeps); + gsl_matrix_set (sw, cache->n_coeffs, cache->n_coeffs, cache->sst); + xty = gsl_matrix_column (sw, cache->n_coeffs); /* This loop starts at 1, with i=0 outside the loop, so we can get the model sum of squares due to the first independent variable. @@ -395,7 +395,7 @@ pspp_linreg (const gsl_vector * Y, const struct design_matrix *dm, gsl_vector_set (&(xty.vector), 0, tmp); tmp *= tmp / gsl_vector_get (cache->ssx, 0); gsl_vector_set (cache->ss_indeps, 0, tmp); - for (i = 1; i < cache->n_indeps; i++) + for (i = 1; i < cache->n_coeffs; i++) { xi = gsl_matrix_column (design, i); gsl_blas_ddot (&(xi.vector), Y, &tmp);