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