const gsl_matrix *cov_matrix;
gsl_matrix *corr_matrix;
struct covariance *cov = covariance_2pass_create (corr->n_vars_total, corr->vars,
- 0, NULL,
+ NULL,
opts->wv, opts->exclude);
struct casereader *rc = casereader_clone (r);
#include <libpspp/compiler.h>
#include <libpspp/message.h>
#include <math/covariance.h>
+#include <math/categoricals.h>
#include <math/linreg.h>
#include <math/moments.h>
#include <output/tab.h>
k++;
}
- cov = covariance_2pass_create (n_numerics, numerics, n_categoricals, categoricals, NULL, MV_NEVER);
+ struct categoricals *cats = categoricals_create (categoricals,
+ n_categoricals,
+ NULL, MV_NEVER);
+
+ cov = covariance_2pass_create (n_numerics, numerics,
+ cats,
+ NULL, MV_NEVER);
reader = casereader_clone (input);
reader = casereader_create_filter_missing (reader, numerics, n_numerics,
ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws));
+
for (v = 0; v < cmd->n_vars; ++v)
{
+ struct categoricals *cats = categoricals_create (&cmd->indep_var, 1,
+ cmd->wv, cmd->exclude);
+
ws.vws[v].cov = covariance_2pass_create (1, &cmd->vars[v],
- 1, &cmd->indep_var,
+ cats,
cmd->wv, cmd->exclude);
ws.vws[v].cc = 0;
}
*/
struct covariance *
covariance_2pass_create (size_t n_vars, const struct variable *const *vars,
- size_t n_catvars, const struct variable *const *catvars,
+ struct categoricals *cats,
const struct variable *wv, enum mv_class exclude)
{
size_t i;
cov->n_cm = -1;
cov->cm = NULL;
- cov->categoricals = categoricals_create (catvars, n_catvars, wv, exclude);
+ cov->categoricals = cats;
return cov;
}
cov->state = 1;
}
- categoricals_update (cov->categoricals, c);
+ if (cov->categoricals)
+ categoricals_update (cov->categoricals, c);
for (i = 0 ; i < cov->dim; ++i)
{
assert (cov->state == 1);
cov->state = 2;
- cov->dim = cov->n_vars +
- categoricals_total (cov->categoricals) - categoricals_get_n_variables (cov->categoricals);
+ cov->dim = cov->n_vars;
+
+ if (cov->categoricals)
+ cov->dim += categoricals_total (cov->categoricals)
+ - categoricals_get_n_variables (cov->categoricals);
cov->n_cm = (cov->dim * (cov->dim - 1) ) / 2;
cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
cov->moments[i] = resize_matrix (cov->moments[i], cov->dim);
}
- categoricals_done (cov->categoricals);
+ 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)
struct covariance;
struct variable;
struct ccase ;
+struct categoricals;
struct covariance * covariance_1pass_create (size_t n_vars, const struct variable *const *vars,
const struct variable *wv, enum mv_class excl);
struct covariance *
covariance_2pass_create (size_t n_vars, const struct variable *const *vars,
- size_t n_catvars, const struct variable *const *catvars,
+ struct categoricals *cats,
const struct variable *wv, enum mv_class excl);
void covariance_accumulate (struct covariance *, const struct ccase *);