#include "libpspp/assertion.h"
#include "libpspp/misc.h"
#include "math/categoricals.h"
+#include "math/interaction.h"
#include "math/moments.h"
#include "gl/xalloc.h"
cov->n_cm = (n_vars * (n_vars - 1) ) / 2;
- if (cov->n_cm > 0)
- cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
+
+ cov->cm = xcalloc (cov->n_cm, sizeof *cov->cm);
cov->categoricals = NULL;
return cov;
{
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);
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);
+ cov->cm = xcalloc (cov->n_cm, sizeof *cov->cm);
/* Grow the moment matrices so that they're large enough to accommodate the
categorical elements */
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)
{
static gsl_matrix *
covariance_calculate_double_pass_unnormalized (struct covariance *cov)
{
- size_t i, j;
- for (i = 0 ; i < cov->dim; ++i)
- {
- for (j = 0 ; j < cov->dim; ++j)
- {
- int idx;
- double *x = gsl_matrix_ptr (cov->moments[MOMENT_VARIANCE], i, j);
-
- idx = cm_idx (cov, i, j);
- if ( idx >= 0)
- {
- x = &cov->cm [idx];
- }
- }
- }
-
return cm_to_gsl (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);
- }
-}
+