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