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