Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / math / design-matrix.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   Create design matrices for procedures that need them.
19  */
20
21 #ifndef DESIGN_MATRIX_H
22 #define DESIGN_MATRIX_H
23
24 #include <gsl/gsl_matrix.h>
25 #include <stdbool.h>
26 #include <data/category.h>
27
28 struct design_matrix_var
29 {
30   size_t first_column;          /* First column for this variable in
31                                    the design_matix. If this variable
32                                    is categorical, its values are
33                                    stored in multiple, contiguous
34                                    columns, as dictated by its vector
35                                    encoding in the variable's struct
36                                    cat_vals.
37                                  */
38   size_t last_column;
39   const struct variable *v;
40 };
41
42 struct design_matrix
43 {
44   gsl_matrix *m;
45   struct design_matrix_var *vars;       /* Element i corresponds to
46                                            the variable whose values
47                                            are stored in at least one
48                                            column of m. If that
49                                            variable is categorical
50                                            with more than two
51                                            categories, its values are
52                                            stored in multiple,
53                                            contiguous columns. The
54                                            variable's values are then
55                                            stored in the columns
56                                            first_column through
57                                            last_column of the
58                                            design_matrix_var
59                                            structure.
60                                          */
61   size_t n_vars;
62 };
63
64
65 struct design_matrix *design_matrix_create (int, const struct variable *[],
66                                             const size_t);
67
68 void design_matrix_destroy (struct design_matrix *);
69
70 void design_matrix_set_categorical (struct design_matrix *, size_t,
71                                     const struct variable *,
72                                     const union value *);
73
74 void design_matrix_set_numeric (struct design_matrix *, size_t,
75                                     const struct variable *,
76                                     const union value *);
77
78 size_t design_matrix_var_to_column (const struct design_matrix *,
79                                     const struct variable *);
80
81 const struct variable *design_matrix_col_to_var (const struct design_matrix *,
82                                            size_t);
83
84 #endif