Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / math / factor-stats.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004 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 #ifndef FACTOR_STATS
18 #define FACTOR_STATS
19
20
21 /* FIXME: These things should probably be amalgamated with the
22    group_statistics struct */
23
24 #include <libpspp/hash.h>
25 #include <data/value.h>
26 #include <string.h>
27 #include <gsl/gsl_histogram.h>
28 #include "percentiles.h"
29
30
31 struct moments1;
32
33 struct metrics
34 {
35   double n;
36
37   double n_missing;
38
39   double min;
40
41   double max;
42
43   double mean;
44
45   double se_mean;
46
47   double var;
48
49   double stddev;
50
51   struct moments1 *moments;
52
53   gsl_histogram *histogram;
54
55   double skewness;
56   double kurtosis;
57
58   double trimmed_mean;
59
60   /* A hash of data for this factor. */
61   struct hsh_table *ordered_data;
62
63   /* A Pointer to this hash table AFTER it has been SORTED and crunched */
64   struct weighted_value **wvp;
65
66   /* The number of values in the above array
67      (if all the weights are 1, then this will
68      be the same as n) */
69   int n_data;
70
71   /* Percentile stuff */
72
73   /* A hash of struct percentiles */
74   struct hsh_table *ptile_hash;
75
76   /* Algorithm to be used for calculating percentiles */
77   enum pc_alg ptile_alg;
78
79   /* Tukey's Hinges */
80   double hinge[3];
81
82 };
83
84
85 struct metrics * metrics_create(void);
86
87 void metrics_precalc(struct metrics *m);
88
89 void metrics_calc(struct metrics *m, const union value *f, double weight,
90                   int case_no);
91
92 void metrics_postcalc(struct metrics *m);
93
94 void  metrics_destroy(struct metrics *m);
95
96
97
98 /* Linked list of case nos */
99 struct case_node
100 {
101   int num;
102   struct case_node *next;
103 };
104
105 struct weighted_value
106 {
107   union value v;
108
109   /* The weight */
110   double w;
111
112   /* The cumulative weight */
113   double cc;
114
115   /* The rank */
116   double rank;
117
118   /* Linked list of cases nos which have this value */
119   struct case_node *case_nos;
120
121 };
122
123
124 struct weighted_value *weighted_value_create(void);
125
126 void weighted_value_free(struct weighted_value *wv);
127
128
129
130 struct factor_statistics {
131
132   /* The values of the independent variables */
133   union value *id[2];
134
135   /* The an array stats for this factor, one for each dependent var */
136   struct metrics *m;
137
138   /* The number of dependent variables */
139   int n_var;
140 };
141
142
143 /* Create a factor statistics object with for N dependent vars
144    and ID as the value of the independent variable */
145 struct factor_statistics * create_factor_statistics (int n,
146                           union value *id0,
147                           union value *id1);
148
149
150 void factor_statistics_free(struct factor_statistics *f);
151
152
153 /* Compare f0 and f1.
154    width is the width of the independent variable */
155 int
156 factor_statistics_compare(const struct factor_statistics *f0,
157                           const struct factor_statistics *f1, int width);
158
159 unsigned int
160 factor_statistics_hash(const struct factor_statistics *f, int width);
161
162 #endif