Remove "Written by Ben Pfaff <blp@gnu.org>" lines everywhere.
[pspp-builds.git] / src / math / moments.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #ifndef HEADER_MOMENTS
20 #define HEADER_MOMENTS
21
22 #include <stddef.h>
23 #include <data/value.h>
24
25 /* Moments of the mean.
26    Higher-order moments have higher values. */
27 enum moment 
28   {
29     MOMENT_NONE,                /* No moments. */
30     MOMENT_MEAN,                /* First-order moment. */
31     MOMENT_VARIANCE,            /* Second-order moment. */
32     MOMENT_SKEWNESS,            /* Third-order moment. */
33     MOMENT_KURTOSIS             /* Fourth-order moment. */
34   };
35
36 struct moments;
37
38 /* Two-pass moments. */
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 /* Convenience functions for two-pass moments. */
50 void moments_of_doubles (const double *array, size_t cnt,
51                          double *weight,
52                          double *mean, double *variance,
53                          double *skewness, double *kurtosis);
54 void moments_of_values (const union value *array, size_t cnt,
55                         double *weight,
56                         double *mean, double *variance,
57                         double *skewness, double *kurtosis);
58
59 /* One-pass moments.  Use only if two passes are impractical. */
60 struct moments1 *moments1_create (enum moment max_moment);
61 void moments1_clear (struct moments1 *);
62 void moments1_add (struct moments1 *, double value, double weight);
63 void moments1_calculate (const struct moments1 *,
64                          double *weight,
65                          double *mean, double *variance,
66                          double *skewness, double *kurtosis);
67 void moments1_destroy (struct moments1 *);
68
69 /* Standard errors. */
70 double calc_semean (double stddev, double weight);
71 double calc_seskew (double weight);
72 double calc_sekurt (double weight);
73
74 #endif /* moments.h */