2ea47d516a770bb7115df2ddca987f0e14abc99d
[pspp-builds.git] / src / math / categoricals.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2010, 2011 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 _CATEGORICALS__
19 #define _CATEGORICALS__
20
21 #include <stddef.h>
22 #include "data/missing-values.h"
23
24 struct categoricals;
25 struct variable;
26 struct ccase;
27 struct interaction;
28
29 union value ;
30
31 typedef void update_func (void *user_data,
32                           enum mv_class exclude,
33                           const struct variable *wv, 
34                           const struct variable *catvar,
35                           const struct ccase *c,
36                           void *aux1, void *aux2);
37
38 typedef void *user_data_create_func (void *aux1, void *aux2);
39
40 struct categoricals *categoricals_create (struct interaction *const *, size_t n_int,
41                                           const struct variable *wv, enum mv_class exclude,
42                                           user_data_create_func *udf,
43                                           update_func *update, void *aux1, void *aux2);
44
45 void categoricals_destroy (struct categoricals *);
46
47 void categoricals_update (struct categoricals *cat, const struct ccase *c);
48
49
50 /* Return the number of categories (distinct values) for variable N */
51 size_t categoricals_n_count (const struct categoricals *cat, size_t n);
52
53 size_t categoricals_df (const struct categoricals *cat, size_t n);
54
55 /* Return the total number of categories */
56 size_t categoricals_n_total (const struct categoricals *cat);
57
58 /* Return the total degrees of freedom */
59 size_t categoricals_df_total (const struct categoricals *cat);
60
61
62 /*
63   Return the total number of variables which participated in these categoricals.
64   Due to the possibility of missing values, this is NOT necessarily
65   equal to the number of variables passed in when the object was
66   created.
67 */
68 size_t categoricals_get_n_variables (const struct categoricals *cat);
69
70
71 bool categoricals_is_complete (const struct categoricals *cat);
72
73
74 /*
75   Must be called (once) before any call to the *_by_subscript or *_by_category
76   functions, but AFTER any calls to categoricals_update.
77   If this function returns false, then no calls to _by_subscript or *_by_category
78   are allowed.
79 */
80 bool categoricals_done (const struct categoricals *cat);
81
82
83 /*
84   The *_by_subscript functions use the short map.
85   Their intended use is by covariance matrix routines, where normally 1 less than 
86   the total number of distinct values of each categorical variable should
87   be considered.
88  */
89 double categoricals_get_weight_by_subscript (const struct categoricals *cat, int subscript);
90 const struct interaction *categoricals_get_interaction_by_subscript (const struct categoricals *cat, int subscript);
91
92 double categoricals_get_sum_by_subscript (const struct categoricals *cat, int subscript);
93
94 double categoricals_get_code_for_case (const struct categoricals *cat, int subscript, const struct ccase *c);
95
96
97 /* These use the long map.  Useful for descriptive statistics. */
98
99 /* Return the value corresponding to the N'th category */
100 const union value * categoricals_get_value_by_category (const struct categoricals *cat, int n);
101
102 void * categoricals_get_user_data_by_category (const struct categoricals *cat, int category);
103
104 const struct ccase * categoricals_get_case_by_category (const struct categoricals *cat, int subscript);
105
106
107 #endif