-#if 0
-/*
- Return the row of the matrix corresponding
- to the value v.
- */
-static gsl_vector_view
-cr_value_to_vector (const union value *v, struct recoded_categorical *cr)
-{
- size_t row;
- row = cr_value_to_subscript (v, cr);
- return gsl_matrix_row (cr->m, row);
-}
-#endif
-/*
- Which element of a vector is equal to the value x?
- */
-static size_t
-cat_which_element_eq (const gsl_vector * vec, double x)
-{
- size_t i;
-
- for (i = 0; i < vec->size; i++)
- {
- if (fabs (gsl_vector_get (vec, i) - x) < GSL_DBL_EPSILON)
- {
- return i;
- }
- }
- return CAT_VALUE_NOT_FOUND;
-}
-static int
-cat_is_zero_vector (const gsl_vector * vec)
-{
- size_t i;
-
- for (i = 0; i < vec->size; i++)
- {
- if (gsl_vector_get (vec, i) != 0.0)
- {
- return 0;
- }
- }
- return 1;
-}
-
-/*
- Return the value corresponding to the vector.
- To avoid searching the matrix, this routine takes
- advantage of the fact that element (i,i+1) is 1
- when i is between 1 and cr->n_categories - 1 and
- i is 0 otherwise.
- */
-union value *
-cr_vector_to_value (const gsl_vector * vec, struct variable *v)
-{
- size_t i;
-
- i = cat_which_element_eq (vec, 1.0);
- if (i != CAT_VALUE_NOT_FOUND)
- {
- return cat_subscript_to_value (i + 1, v);
- }
- if (cat_is_zero_vector (vec))
- {
- return cat_subscript_to_value (0, v);
- }
- return NULL;
-}
-
-#if 0
-/*
- Given a variable, return a pointer to its recoded
- structure. BUSTED IN HERE.
- */
-struct recoded_categorical *
-cr_var_to_recoded_categorical (const struct variable *v,
- struct recoded_categorical_array *ca)
-{
- struct recoded_categorical *rc;
- size_t i;
-
- for (i = 0; i < ca->n_vars; i++)
- {
- rc = *(ca->a + i);
- if (rc->v->index == v->index)
- {
- return rc;
- }
- }
- return NULL;
-}
-#endif
-struct design_matrix *
-design_matrix_create (int n_variables,
- const struct variable *v_variables[],
- const size_t n_data)
-{
- struct design_matrix *dm;
- const struct variable *v;
- size_t i;
- size_t n_cols = 0;
- size_t col;
-
- dm = xmalloc (sizeof *dm);
- dm->vars = xnmalloc (n_variables, sizeof *dm->vars);
- dm->n_vars = n_variables;
-
- for (i = 0; i < n_variables; i++)
- {
- v = v_variables[i];
- assert ((dm->vars + i) != NULL);
- (dm->vars + i)->v = v; /* Allows us to look up the variable from
- the design matrix. */
- (dm->vars + i)->first_column = n_cols;
- if (v->type == NUMERIC)
- {
- n_cols++;
- (dm->vars + i)->last_column = n_cols;
- }
- else if (v->type == ALPHA)
- {
- assert (v->obs_vals != NULL);
- (dm->vars + i)->last_column =
- (dm->vars + i)->first_column + v->obs_vals->n_categories - 2;
- n_cols += v->obs_vals->n_categories - 1;
- }
- }
- dm->m = gsl_matrix_calloc (n_data, n_cols);
- col = 0;
-
- return dm;
-}
-
-void
-design_matrix_destroy (struct design_matrix *dm)
-{
- free (dm->vars);
- gsl_matrix_free (dm->m);
- free (dm);
-}
-
-/*
- Return the index of the variable for the
- given column.
- */
-static size_t
-design_matrix_col_to_var_index (const struct design_matrix *dm, size_t col)
-{
- size_t i;
- struct design_matrix_var v;
-
- for (i = 0; i < dm->n_vars; i++)
- {
- v = dm->vars[i];
- if (v.first_column <= col && col <= v.last_column)
- return (v.v)->index;
- }
- return CAT_INDEX_NOT_FOUND;
-}
-
-/*
- Return a pointer to the variable whose values
- are stored in column col.
- */
-struct variable *
-design_matrix_col_to_var (const struct design_matrix *dm, size_t col)
-{
- size_t index;
- size_t i;
- struct design_matrix_var dmv;
-
- index = design_matrix_col_to_var_index (dm, col);
- for (i = 0; i < dm->n_vars; i++)
- {
- dmv = dm->vars[i];
- if ((dmv.v)->index == index)
- {
- return (struct variable *) dmv.v;
- }
- }
- return NULL;
-}
-
-static size_t
-cmp_dm_var_index (const struct design_matrix_var *dmv, size_t index)
-{
- if (dmv->v->index == index)
- return 1;
- return 0;
-}
-