Fix bug #11612, "q2c documentation does not agree with code".
[pspp-builds.git] / src / math / linreg / coefficient.h
1 /*
2   lib/linreg/coefficient.c
3   
4   Copyright (C) 2005 Free Software Foundation, Inc. Written by Jason H Stover.
5   
6   This program is free software; you can redistribute it and/or modify it under
7   the terms of the GNU General Public License as published by the Free
8   Software Foundation; either version 2 of the License, or (at your option)
9   any later version.
10   
11   This program is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14   more details.
15   
16   You should have received a copy of the GNU General Public License along with
17   this program; if not, write to the Free Software Foundation, Inc., 51
18   Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
19 */
20
21
22 #ifndef COEFFICIENT_H
23 #define COEFFICIENT_H
24
25 #include <assert.h>
26 #include <math/linreg/linreg.h>
27 #include <src/data/variable.h>
28 #include <src/data/value.h>
29
30 struct design_matrix;
31
32 /*
33   Cache for the relevant data from the model. There are several
34   members which the caller might not use, and which could use a lot of
35   storage. Therefore non-essential members of the struct will be
36   allocated only when requested.
37  */
38 struct pspp_linreg_coeff
39 {
40   double estimate;              /* Estimated coefficient. */
41   double std_err;               /* Standard error of the estimate. */
42   struct varinfo *v_info;       /* Information pertaining to the variable(s)
43                                    associated with this coefficient.  The
44                                    calling function should initialize this
45                                    value with the functions in coefficient.c.
46                                    The estimation procedure ignores this
47                                    member. It is here so the caller can match
48                                    parameters with relevant variables and
49                                    values. If the coefficient is associated
50                                    with an interaction, then v_info contains
51                                    information for multiple variables. */
52   int n_vars;                   /* Number of variables associated with this
53                                    coefficient. Coefficients corresponding to
54                                    interaction terms will have more than one
55                                    variable. */
56 };
57
58
59 void pspp_linreg_coeff_free (struct pspp_linreg_coeff *);
60
61 /*
62   Initialize the variable and value pointers inside the
63   coefficient structures for the linear model.
64  */
65 void pspp_linreg_coeff_init (pspp_linreg_cache *, struct design_matrix *);
66
67
68 void
69 pspp_linreg_coeff_set_estimate (struct pspp_linreg_coeff *, double estimate);
70
71 void
72 pspp_linreg_coeff_set_std_err (struct pspp_linreg_coeff *, double std_err);
73
74 /*
75   Accessor functions for matching coefficients and variables.
76  */
77
78 /*
79   Return the estimated value of the coefficient.
80  */
81 double pspp_linreg_coeff_get_est (const struct pspp_linreg_coeff *);
82
83 /*
84   Return the standard error of the estimated coefficient.
85 */
86 double pspp_linreg_coeff_get_std_err (const struct pspp_linreg_coeff *);
87
88 /*
89   How many variables are associated with this coefficient?
90  */
91 int pspp_linreg_coeff_get_n_vars (struct pspp_linreg_coeff *);
92
93 /*
94   Which variable does this coefficient match? The int argument is usually
95   0, unless the coefficient refers to an interaction.
96  */
97 const struct variable *pspp_linreg_coeff_get_var (struct pspp_linreg_coeff *,
98                                                   int);
99 /*
100   Which value is associated with this coefficient/variable comination?
101  */
102 const union value *pspp_linreg_coeff_get_value (struct pspp_linreg_coeff *,
103                                                 const struct variable *);
104
105 const struct pspp_linreg_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache
106                                                        *,
107                                                        const struct variable
108                                                        *,
109                                                        const union value *);
110 #endif