From: Jason Stover Date: Sun, 16 Jul 2006 12:49:13 +0000 (+0000) Subject: center the data before computing the coefficients; remove variance member of innovati... X-Git-Tag: v0.6.0~755 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=755ecfd2e8d86bc134fe7202c46fee354ec166d0;p=pspp-builds.git center the data before computing the coefficients; remove variance member of innovations estimate --- diff --git a/src/math/ts/ChangeLog b/src/math/ts/ChangeLog index 18948856..a353ffce 100644 --- a/src/math/ts/ChangeLog +++ b/src/math/ts/ChangeLog @@ -2,6 +2,8 @@ * innovations.c (get_coef): Fixed diagonal elements and call to innovations_convolve(). + (subtract_mean): New function. Subtract the mean before computing + the coefficients. 2006-07-15 Jason Stover diff --git a/src/math/ts/innovations.c b/src/math/ts/innovations.c index 00d366ce..107d8ba4 100644 --- a/src/math/ts/innovations.c +++ b/src/math/ts/innovations.c @@ -239,9 +239,6 @@ get_coef (const gsl_matrix *data, + est->coeff[m-1] * (X[m-2] - X_hat[m-2]) ... + est->coeff[m-max_lag] * (X[m - max_lag] - X_hat[m - max_lag]) - - (That is what X_hat[m] SHOULD be, anyway. These routines need - to be tested.) */ pspp_coeff_set_estimate (est[n]->coeff[i], theta[max_lag - 1][i]); } @@ -281,7 +278,28 @@ innovations_struct_init (struct innovations_estimate *est, } est->max_lag = (double) lag; } - +/* + The mean is subtracted from the original data before computing the + coefficients. The mean is NOT added back, so if you want to predict + a new value, you must add the mean to X_hat[m] to get the correct + value. + */ +static void +subtract_mean (gsl_matrix *m, struct innovations_estimate **est) +{ + size_t i; + size_t j; + double tmp; + + for (i = 0; i < m->size1; i++) + { + for (j = 0; j < m->size2; j++) + { + tmp = gsl_matrix_get (m, i, j) - est[j]->mean; + gsl_matrix_set (m, i, j, tmp); + } + } +} struct innovations_estimate ** pspp_innovations (const struct design_matrix *dm, size_t lag) { @@ -297,6 +315,7 @@ pspp_innovations (const struct design_matrix *dm, size_t lag) } get_mean (dm->m, est); + subtract_mean (dm->m, est); get_covariance (dm->m, est, lag); get_coef (dm->m, est, lag); diff --git a/src/math/ts/innovations.h b/src/math/ts/innovations.h index d6ec1ce4..3432a3be 100644 --- a/src/math/ts/innovations.h +++ b/src/math/ts/innovations.h @@ -36,7 +36,6 @@ struct innovations_estimate { const struct variable *variable; double mean; - double variance; double *cov; double *scale; double n_obs;