1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 Accessor functions for matching coefficients and variables.
21 #include <math/coefficient.h>
22 #include "src/math/design-matrix.h"
24 #include <gl/xalloc.h>
29 const struct variable *v; /* Variable associated with this
30 coefficient. Note this variable
31 may not be unique. In other words,
32 a coefficient structure may have
33 other v_info's, each with its own
35 const union value *val; /* Value of the variable v which this varinfo
36 refers to. This member is relevant only to
37 categorical variables. */
41 pspp_coeff_free (struct pspp_coeff *c)
48 Initialize the variable and value pointers inside the
49 coefficient structures for the model.
52 pspp_coeff_init (struct pspp_coeff ** c, const struct design_matrix *X)
58 for (i = 0; i < X->m->size2; i++)
60 c[i] = xmalloc (sizeof (*c[i]));
61 c[i]->n_vars = n_vals; /* Currently, no procedures allow
62 interactions. This line will have to
63 change when procedures that allow
64 interaction terms are written.
66 c[i]->v_info = xnmalloc (c[i]->n_vars, sizeof (*c[i]->v_info));
67 assert (c[i]->v_info != NULL);
68 c[i]->v_info->v = design_matrix_col_to_var (X, i);
70 if (var_is_alpha (c[i]->v_info->v))
73 k = design_matrix_var_to_column (X, c[i]->v_info->v);
77 cat_subscript_to_value (k, c[i]->v_info->v);
82 pspp_coeff_set_estimate (struct pspp_coeff *c, double estimate)
84 c->estimate = estimate;
88 pspp_coeff_set_std_err (struct pspp_coeff *c, double std_err)
94 Return the estimated value of the coefficient.
97 pspp_coeff_get_est (const struct pspp_coeff *c)
107 Return the standard error of the estimated coefficient.
110 pspp_coeff_get_std_err (const struct pspp_coeff *c)
120 How many variables are associated with this coefficient?
123 pspp_coeff_get_n_vars (struct pspp_coeff *c)
133 Which variable does this coefficient match? I should be
134 0 unless the coefficient refers to an interaction term.
136 const struct variable *
137 pspp_coeff_get_var (struct pspp_coeff *c, int i)
143 assert (i < c->n_vars);
144 return (c->v_info + i)->v;
148 Which value is associated with this coefficient/variable combination?
151 pspp_coeff_get_value (struct pspp_coeff *c,
152 const struct variable *v)
155 const struct variable *candidate;
157 if (c == NULL || v == NULL)
161 if (var_is_numeric (v))
165 while (i < c->n_vars)
167 candidate = pspp_coeff_get_var (c, i);
170 return (c->v_info + i)->val;