c7f1216221f5401fa8444f4c0888c9483012ac54
[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 weighted_value 
32 {
33   union value v;
34
35   /* The weight */
36   double w;
37
38   /* The cumulative weight */
39   double cc; 
40
41   /* The rank */
42   double rank;
43 };
44
45
46
47 struct metrics
48 {
49   double n;
50   
51   double ssq;
52   
53   double sum;
54
55   double min;
56
57   double max;
58
59   double mean;
60   
61   double stderr;
62
63   double var;
64
65   double stddev;
66
67   double trimmed_mean;
68
69   /* An ordered arary of data for this factor */
70   struct hsh_table *ordered_data;
71
72   /* An SORTED array of weighted values */
73   struct weighted_value *wv;
74 };
75
76
77
78 struct factor_statistics {
79
80   /* The value of the independent variable for this factor */
81   const union value *id;
82
83   /* An array of metrics indexed by dependent variable */
84   struct metrics *stats;
85
86 };
87
88
89
90 void metrics_precalc(struct metrics *fs);
91
92 void metrics_calc(struct metrics *fs, const union value *f, double weight);
93
94 void metrics_postcalc(struct metrics *fs);
95
96
97
98
99 /* These functions are necessary for creating hashes */
100
101 int compare_indep_values(const struct factor_statistics *f1, 
102                      const struct factor_statistics *f2, 
103                      int width);
104
105 unsigned hash_indep_value(const struct factor_statistics *f, int width) ;
106
107 void  free_factor_stats(struct factor_statistics *f, int width );
108
109
110 #endif