-/*
- Which coefficient is associated with V? The VAL argument is relevant
- only to categorical variables.
- */
-const struct pspp_coeff *
-pspp_linreg_get_coeff (const pspp_linreg_cache * c,
- const struct variable *v, const union value *val)
-{
- int i;
- struct pspp_coeff *result = NULL;
- const struct variable *tmp = NULL;
-
- if (c == NULL)
- {
- return NULL;
- }
- if (c->coeff == NULL || c->n_indeps == 0 || v == NULL)
- {
- return NULL;
- }
- /*
- C->N_COEFFS == 1 means regression through the origin.
- */
- i = (c->n_coeffs > 1) ? 1 : 0;
- result = c->coeff[i];
- tmp = pspp_coeff_get_var (result, 0);
- while (tmp != v && i < c->n_coeffs)
- {
- result = c->coeff[i];
- tmp = pspp_coeff_get_var (result, 0);
- i++;
- }
- if (i >= c->n_coeffs)
- {
- return NULL;
- }
- if (var_is_numeric (v))
- {
- return result;
- }
- else if (val != NULL)
- {
- /*
- If v is categorical, we need to ensure the coefficient
- matches the VAL.
- */
- while (tmp != v && i < c->n_coeffs
- && compare_values (pspp_coeff_get_value (result, tmp),
- val, var_get_width (v)))
- { /* FIX THIS */
- i++;
- result = c->coeff[i];
- tmp = pspp_coeff_get_var (result, 0);
- }
- if (i == c->n_coeffs)
- {
- return NULL;
- }
- return result;
- }
- return NULL;
-}