dm = xmalloc (sizeof *dm);
dm->vars = xnmalloc (n_variables, sizeof *dm->vars);
+ dm->n_cases = xnmalloc (n_variables, sizeof (*dm->n_cases));
dm->n_vars = n_variables;
for (i = 0; i < n_variables; i++)
{
+ dm->n_cases[i] = 0;
v = v_variables[i];
assert ((dm->vars + i) != NULL);
(dm->vars + i)->v = v; /* Allows us to look up the variable from
dm->m = gsl_matrix_calloc (n_data, n_cols);
col = 0;
+
return dm;
}
{
free (dm->vars);
gsl_matrix_free (dm->m);
+ free (dm->n_cases);
free (dm);
}
{
struct design_matrix *result;
size_t i;
- size_t j;
assert (dm != NULL);
result = xmalloc (sizeof *result);
return result;
}
+/*
+ Increment the number of cases for V.
+ */
+void
+design_matrix_increment_case_count (struct design_matrix *dm, const struct variable *v)
+{
+ size_t i;
+ assert (dm != NULL);
+ assert (dm->n_cases != NULL);
+ assert (v != NULL);
+ i = design_matrix_var_to_column (dm, v);
+ dm->n_cases[i]++;
+}
+
+/*
+ Set the number of cases for V.
+ */
+void
+design_matrix_set_case_count (struct design_matrix *dm, const struct variable *v, size_t n)
+{
+ size_t i;
+ assert (dm != NULL);
+ assert (dm->n_cases != NULL);
+ assert (v != NULL);
+ i = design_matrix_var_to_column (dm, v);
+ dm->n_cases[i] = n;
+}
+
+/*
+ Get the number of cases for V.
+ */
+size_t
+design_matrix_get_case_count (const struct design_matrix *dm, const struct variable *v)
+{
+ size_t i;
+ assert (dm != NULL);
+ assert (dm->n_cases != NULL);
+ assert (v != NULL);
+ i = design_matrix_var_to_column (dm, v);
+ return dm->n_cases[i];
+}
+
+size_t
+design_matrix_get_n_cols (const struct design_matrix *d)
+{
+ return d->m->size2;
+}
+
+size_t
+design_matrix_get_n_rows (const struct design_matrix *d)
+{
+ return d->m->size1;
+}
+
+double
+design_matrix_get_element (const struct design_matrix *d, size_t row, size_t col)
+{
+ return (gsl_matrix_get (d->m, row, col));
+}
+
+void
+design_matrix_set_element (const struct design_matrix *d, size_t row, size_t col, double x)
+{
+ gsl_matrix_set (d->m, row, col, x);
+}
+
+/*
+ Return the subscript of the column of the design matrix
+ corresponding to VAL. If VAR is categorical with d categories, its
+ first category should correspond to the origin in d-dimensional
+ Euclidean space, so there is no subscript for this value.
+ */
+size_t
+dm_get_exact_subscript (const struct design_matrix *dm, const struct variable *var,
+ const union value *val)
+{
+ size_t result;
+
+ result = design_matrix_var_to_column (dm, var);
+ if (var_is_alpha (var))
+ {
+ if (cat_is_origin (var, val))
+ {
+ return -1u;
+ }
+ result += cat_value_find (var, val) - 1;
+ }
+ return result;
+}