Added the skewness and kurtosis calculations to the EXAMINE command.
[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
31
32 struct moments1;
33
34 struct metrics
35 {
36   double n;
37
38   double n_missing;
39   
40   double min;
41
42   double max;
43
44   double mean;
45   
46   double stderr;
47
48   double var;
49
50   double stddev;
51
52   struct moments1 *moments;
53
54   double skewness;
55   double kurtosis;
56
57   double trimmed_mean;
58
59   /* A hash of data for this factor.
60    */
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
67   /* The number of values in the above array
68      (if all the weights are 1, then this will
69      be the same as n) */
70   int n_data;
71 };
72
73
74
75
76 void metrics_precalc(struct metrics *m);
77
78 void metrics_calc(struct metrics *m, const union value *f, double weight, 
79                   int case_no);
80
81 void metrics_postcalc(struct metrics *m);
82
83
84 /* Linked list of case nos */
85 struct case_node
86 {
87   int num;
88   struct case_node *next;
89 };
90
91 struct weighted_value 
92 {
93   union value v;
94
95   /* The weight */
96   double w;
97
98   /* The cumulative weight */
99   double cc; 
100
101   /* The rank */
102   double rank;
103
104   /* Linked list of cases nos which have this value */
105   struct case_node *case_nos;
106   
107 };
108
109
110 struct weighted_value *weighted_value_create(void);
111
112 void weighted_value_free(struct weighted_value *wv);
113
114
115
116 struct factor_statistics {
117
118   /* The values of the independent variables */
119   union value id[2];
120
121   /* The an array stats for this factor, one for each dependent var */
122   struct metrics *m;
123
124 };
125
126
127 /* Create a factor statistics object with for N dependent vars
128    and ID as the value of the independent variable */
129 struct factor_statistics * 
130 create_factor_statistics (int n, union value *id0, union value *id1);
131
132
133 void factor_statistics_free(struct factor_statistics *f);
134
135
136 /* Compare f0 and f1.
137    width is the width of the independent variable */
138 int 
139 factor_statistics_compare(const struct factor_statistics *f0,
140                           const struct factor_statistics *f1, int width);
141
142                               
143
144 unsigned int 
145 factor_statistics_hash(const struct factor_statistics *f, int width);
146
147 #endif