8a82f46be98ebec69eaa17ab115c8add71dc4052
[pspp-builds.git] / src / math / coefficient.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17
18 #ifndef COEFFICIENT_H
19 #define COEFFICIENT_H
20
21 #include <assert.h>
22 #include <math/linreg/linreg.h>
23 #include <src/data/variable.h>
24 #include <src/data/value.h>
25
26 /*
27   This file contains definitions of data structures for storing
28   coefficients of a statistical model. The coefficients are the point
29   in the model where the theoretical aspects of the model meet the
30   data. As such, the coefficients are the interface where users need
31   to match variable names and values with any information about the
32   model itself. This file and coefficient.c provide this interface
33   between data and model structures.
34  */
35
36 struct design_matrix;
37
38 /*
39   Cache for the relevant data from the model. There are several
40   members which the caller might not use, and which could use a lot of
41   storage. Therefore non-essential members of the struct will be
42   allocated only when requested.
43  */
44 struct pspp_coeff
45 {
46   double estimate;              /* Estimated coefficient. */
47   double std_err;               /* Standard error of the estimate. */
48   struct varinfo *v_info;       /* Information pertaining to the variable(s)
49                                    associated with this coefficient.  The
50                                    calling function should initialize this
51                                    value with the functions in coefficient.c.
52                                    The estimation procedure ignores this
53                                    member. It is here so the caller can match
54                                    parameters with relevant variables and
55                                    values. If the coefficient is associated
56                                    with an interaction, then v_info contains
57                                    information for multiple variables. */
58   int n_vars;                   /* Number of variables associated with this
59                                    coefficient. Coefficients corresponding to
60                                    interaction terms will have more than one
61                                    variable. */
62 };
63 typedef struct pspp_coeff coefficient;
64
65 void pspp_coeff_free (struct pspp_coeff *);
66
67 /*
68   Initialize the variable and value pointers inside the
69   coefficient structures for the linear model.
70  */
71 void pspp_coeff_init (struct pspp_coeff **, const struct design_matrix *);
72
73
74 void
75 pspp_coeff_set_estimate (struct pspp_coeff *, double estimate);
76
77 void
78 pspp_coeff_set_std_err (struct pspp_coeff *, double std_err);
79
80 /*
81   Accessor functions for matching coefficients and variables.
82  */
83
84 /*
85   Return the estimated value of the coefficient.
86  */
87 double pspp_coeff_get_est (const struct pspp_coeff *);
88
89 /*
90   Return the standard error of the estimated coefficient.
91 */
92 double pspp_coeff_get_std_err (const struct pspp_coeff *);
93
94 /*
95   How many variables are associated with this coefficient?
96  */
97 int pspp_coeff_get_n_vars (struct pspp_coeff *);
98
99 /*
100   Which variable does this coefficient match? The int argument is usually
101   0, unless the coefficient refers to an interaction.
102  */
103 const struct variable *pspp_coeff_get_var (struct pspp_coeff *,
104                                                   int);
105 /*
106   Which value is associated with this coefficient/variable comination?
107  */
108 const union value *pspp_coeff_get_value (struct pspp_coeff *,
109                                                 const struct variable *);
110
111 const struct pspp_coeff *pspp_linreg_get_coeff (const pspp_linreg_cache
112                                                        *,
113                                                        const struct variable
114                                                        *,
115                                                        const union value *);
116 #endif