From a3dd22c0ed3bcf0d3cf5cf3e009c215eeb35b567 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 11 Jul 2011 16:47:18 +0200 Subject: [PATCH] Fix ssq for interactions --- src/language/stats/glm.c | 8 +++----- src/math/covariance.c | 32 -------------------------------- src/math/covariance.h | 5 +---- 3 files changed, 4 insertions(+), 41 deletions(-) diff --git a/src/language/stats/glm.c b/src/language/stats/glm.c index 54e60c05f9..3194fd8178 100644 --- a/src/language/stats/glm.c +++ b/src/language/stats/glm.c @@ -329,9 +329,7 @@ get_ssq (struct covariance *cov, gsl_vector * ssq, const struct glm_spec *cmd) size_t j; size_t k; size_t *dropped = xcalloc (covariance_dim (cov), sizeof (*dropped)); - const struct variable **vars = xcalloc (covariance_dim (cov), sizeof (*vars)); - - covariance_get_var_indices (cov, vars); + const struct categoricals *cats = covariance_get_categoricals (cov); for (k = 0; k < cmd->n_interactions; k++) { @@ -341,7 +339,8 @@ get_ssq (struct covariance *cov, gsl_vector * ssq, const struct glm_spec *cmd) size_t n_dropped = 0; for (i = cmd->n_dep_vars; i < covariance_dim (cov); i++) { - if (vars[i] == cmd->interactions[k]->vars[0]) + if (categoricals_get_interaction_by_subscript (cats, i - cmd->n_dep_vars) + == cmd->interactions[k]) { assert (n_dropped < covariance_dim (cov)); dropped[n_dropped++] = i; @@ -375,7 +374,6 @@ get_ssq (struct covariance *cov, gsl_vector * ssq, const struct glm_spec *cmd) } free (dropped); - free (vars); gsl_matrix_free (cm); } diff --git a/src/math/covariance.c b/src/math/covariance.c index aed42436ba..5dc1782638 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -738,36 +738,4 @@ covariance_dim (const struct covariance * cov) return (cov->dim); } -/* - Returns an array of variables corresponding to rows of the covariance matrix. - In other words, element i of the array is the variable corresponding to - row (and column) i of the covariance matrix. - */ -void -covariance_get_var_indices (const struct covariance *cov, const struct variable **vars) -{ - int i; - for (i = 0; i < cov->n_vars; i++) - { - vars[i] = cov->vars[i]; - } - for (i = cov->n_vars; i < cov->dim; i++) - { - vars[i] = categoricals_get_variable_by_subscript (cov->categoricals, i - cov->n_vars); - } -} - -void -covariance_get_interaction_indices (const struct covariance *cov, const struct interaction **iacts) -{ - int i; - for (i = 0; i < cov->n_vars; i++) - { - iacts[i] = cov->vars[i]; - } - for (i = cov->n_vars; i < cov->dim; i++) - { - iacts[i] = categoricals_get_interaction_by_subscript (cov->categoricals, i - cov->n_vars); - } -} diff --git a/src/math/covariance.h b/src/math/covariance.h index 87afd8b282..ed5b3ee734 100644 --- a/src/math/covariance.h +++ b/src/math/covariance.h @@ -47,9 +47,6 @@ void covariance_destroy (struct covariance *cov); const gsl_matrix *covariance_moments (const struct covariance *cov, int m); const struct categoricals * covariance_get_categoricals (const struct covariance *cov); -struct interaction; -void covariance_get_interaction_indices (const struct covariance *cov, const struct interaction **iacts); - -void covariance_get_var_indices (const struct covariance *cov, const struct variable **vars); size_t covariance_dim (const struct covariance * cov); + #endif -- 2.30.2