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