1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
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.
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.
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
19 #ifndef HEADER_MOMENTS
20 #define HEADER_MOMENTS
23 #include <data/value.h>
25 /* Moments of the mean.
26 Higher-order moments have higher values. */
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. */
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 *,
45 double *mean, double *variance,
46 double *skewness, double *kurtosis);
47 void moments_destroy (struct moments *);
49 /* Convenience functions for two-pass moments. */
50 void moments_of_doubles (const double *array, size_t cnt,
52 double *mean, double *variance,
53 double *skewness, double *kurtosis);
54 void moments_of_values (const union value *array, size_t cnt,
56 double *mean, double *variance,
57 double *skewness, double *kurtosis);
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 *,
65 double *mean, double *variance,
66 double *skewness, double *kurtosis);
67 void moments1_destroy (struct moments1 *);
69 /* Standard errors. */
70 double calc_semean (double stddev, double weight);
71 double calc_seskew (double weight);
72 double calc_sekurt (double weight);
74 #endif /* moments.h */