1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #ifndef _CATEGORICALS__
19 #define _CATEGORICALS__
22 #include "data/missing-values.h"
31 struct categoricals *categoricals_create (struct interaction *const*, size_t n_int,
32 const struct variable *wv, enum mv_class dep_excl,
33 enum mv_class fctr_excl);
35 void categoricals_destroy (struct categoricals *);
37 void categoricals_update (struct categoricals *cat, const struct ccase *c);
40 /* Return the number of categories (distinct values) for variable N */
41 size_t categoricals_n_count (const struct categoricals *cat, size_t n);
43 size_t categoricals_df (const struct categoricals *cat, size_t n);
45 /* Return the total number of categories */
46 size_t categoricals_n_total (const struct categoricals *cat);
48 /* Return the total degrees of freedom */
49 size_t categoricals_df_total (const struct categoricals *cat);
53 Return the total number of variables which participated in these categoricals.
54 Due to the possibility of missing values, this is NOT necessarily
55 equal to the number of variables passed in when the object was
58 size_t categoricals_get_n_variables (const struct categoricals *cat);
60 bool categoricals_is_complete (const struct categoricals *cat);
64 Must be called (once) before any call to the *_by_subscript or *_by_category
65 functions, but AFTER any calls to categoricals_update.
66 If this function returns false, then no calls to _by_subscript or *_by_category
69 void categoricals_done (const struct categoricals *cat);
71 bool categoricals_sane (const struct categoricals *cat);
75 The *_by_subscript functions use the short map.
76 Their intended use is by covariance matrix routines, where normally 1 less than
77 the total number of distinct values of each categorical variable should
80 double categoricals_get_weight_by_subscript (const struct categoricals *cat, int subscript);
81 const struct interaction *categoricals_get_interaction_by_subscript (const struct categoricals *cat, int subscript);
83 double categoricals_get_sum_by_subscript (const struct categoricals *cat, int subscript);
85 /* Returns unity if the value in case C at SUBSCRIPT is equal to the category
88 categoricals_get_dummy_code_for_case (const struct categoricals *cat, int subscript,
89 const struct ccase *c);
91 /* Returns unity if the value in case C at SUBSCRIPT is equal to the category
93 Else if it is the last category, return -1.
97 categoricals_get_effects_code_for_case (const struct categoricals *cat, int subscript,
98 const struct ccase *c);
101 /* These use the long map. Useful for descriptive statistics. */
105 categoricals_get_case_by_category_real (const struct categoricals *cat, int iact, int n);
108 categoricals_get_user_data_by_category_real (const struct categoricals *cat, int iact, int n);
111 void * categoricals_get_user_data_by_category (const struct categoricals *cat, int category);
113 const struct ccase * categoricals_get_case_by_category (const struct categoricals *cat, int subscript);
118 void* (*create) (const void *aux1, void *aux2);
119 void (*update) (const void *aux1, void *aux2, void *user_data, const struct ccase *, double weight);
120 void (*calculate) (const void *aux1, void *aux2, void *user_data);
121 void (*destroy) (const void *aux1, void *aux2, void *user_data);
125 void categoricals_set_payload (struct categoricals *cats, const struct payload *p, const void *aux1, void *aux2);