Add multipass procedures. Add two-pass moments calculation. Rewrite
[pspp-builds.git] / src / moments.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #ifndef HEADER_MOMENTS
21 #define HEADER_MOMENTS
22
23 #include <stddef.h>
24 #include "val.h"
25
26 /* Moments of the mean.
27    Higher-order moments have higher values. */
28 enum moment 
29   {
30     MOMENT_NONE,                /* No moments. */
31     MOMENT_MEAN,                /* First-order moment. */
32     MOMENT_VARIANCE,            /* Second-order moment. */
33     MOMENT_SKEWNESS,            /* Third-order moment. */
34     MOMENT_KURTOSIS             /* Fourth-order moment. */
35   };
36
37 struct moments;
38
39 struct moments *moments_create (enum moment max_moment);
40 void moments_clear (struct moments *);
41 void moments_pass_one (struct moments *, double value, double weight);
42 void moments_pass_two (struct moments *, double value, double weight);
43 void moments_calculate (const struct moments *,
44                         double *weight,
45                         double *mean, double *variance,
46                         double *skewness, double *kurtosis);
47 void moments_destroy (struct moments *);
48
49 void moments_of_doubles (const double *array, size_t cnt,
50                          double *weight,
51                          double *mean, double *variance,
52                          double *skewness, double *kurtosis);
53 void moments_of_values (const union value *array, size_t cnt,
54                         double *weight,
55                         double *mean, double *variance,
56                         double *skewness, double *kurtosis);
57
58 double calc_seskew (double weight);
59 double calc_sekurt (double weight);
60
61 #endif /* moments.h */