X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcovariance.c;h=f64e89d1eb2ffbee673c2179e6d2e48b78d066f3;hb=dc29c57e7908b0bdc6ab84f8aa4b7cb8a780026c;hp=b0b0b466676a58eb67311067dbba8f4aab2de413;hpb=3c5fcaa67efcee56981c16b543fb9f679787a486;p=pspp-builds.git diff --git a/src/math/covariance.c b/src/math/covariance.c index b0b0b466..f64e89d1 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,15 +16,19 @@ #include -#include -#include "covariance.h" -#include -#include "moments.h" +#include "math/covariance.h" + #include -#include -#include -#include -#include "categoricals.h" + +#include "data/case.h" +#include "data/variable.h" +#include "libpspp/assertion.h" +#include "libpspp/misc.h" +#include "math/categoricals.h" +#include "math/interaction.h" +#include "math/moments.h" + +#include "gl/xalloc.h" #define n_MOMENTS (MOMENT_VARIANCE + 1) @@ -244,7 +248,7 @@ is_missing (const struct covariance *cov, int i, const struct ccase *c) { const struct variable *var = i < cov->n_vars ? cov->vars[i] : - categoricals_get_variable_by_subscript (cov->categoricals, i - cov->n_vars); + categoricals_get_interaction_by_subscript (cov->categoricals, i - cov->n_vars)->vars[0]; const union value *val = case_data (c, var); @@ -343,11 +347,13 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c) assert (cov->state == 1); cov->state = 2; + if (cov->categoricals) + categoricals_done (cov->categoricals); + cov->dim = cov->n_vars; if (cov->categoricals) - cov->dim += categoricals_total (cov->categoricals) - - categoricals_get_n_variables (cov->categoricals); + cov->dim += categoricals_df_total (cov->categoricals); cov->n_cm = (cov->dim * (cov->dim - 1) ) / 2; cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm); @@ -359,9 +365,6 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c) cov->moments[i] = resize_matrix (cov->moments[i], cov->dim); } - if (cov->categoricals) - categoricals_done (cov->categoricals); - /* Populate the moments matrices with the categorical value elements */ for (i = cov->n_vars; i < cov->dim; ++i) { @@ -728,3 +731,11 @@ covariance_destroy (struct covariance *cov) free (cov->cm); free (cov); } + +size_t +covariance_dim (const struct covariance * cov) +{ + return (cov->dim); +} + +