+static union value *pspp_reg_coefficient_to_value (const pspp_linreg_cache *,
+ const struct
+ pspp_linreg_coeff *,
+ size_t);
+
+/*
+ Which value of a categorical variable corresponds to the
+ coefficient? This routine provides the answer IF the
+ categorical variable is encoded in the usual way: The
+ first value maps to the zero vector, the second value to
+ the vector (0, 1, 0, ...), the third value (0, 0, 1, 0, ...),
+ etc.
+ */
+static union value *
+pspp_reg_coefficient_to_value (const pspp_linreg_cache * cache,
+ const struct pspp_linreg_coeff *coeff,
+ size_t j)
+{
+ size_t which = 0;
+ int k = 1; /* First coefficient is the intercept. */
+ int found = 0;
+ const union value *result;
+ struct pspp_linreg_coeff c;
+
+ assert (cache != NULL);
+ assert (coeff != NULL);
+ assert (coeff->v->type == ALPHA);
+ while (!found && k < cache->n_coeffs)
+ {
+ c = cache->coeff[k];
+ /*
+ compare_var_names returns 0 if the variable
+ names match.
+ */
+ if (!compare_var_names (coeff->v, c.v, NULL))
+ {
+ if (j == k)
+ {
+ found = 1;
+ }
+ else
+ {
+ which++;
+ }
+ }
+ k++;
+ }
+ result = cat_subscript_to_value ((const size_t) which, coeff->v);
+ return result;
+}
+