1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU 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, see <http://www.gnu.org/licenses/>. */
17 #ifndef HEADER_MOMENTS
18 #define HEADER_MOMENTS
21 #include "data/value.h"
23 /* Moments of the mean.
24 Higher-order moments have higher values. */
27 MOMENT_NONE, /* No moments. */
28 MOMENT_MEAN, /* First-order moment. */
29 MOMENT_VARIANCE, /* Second-order moment. */
30 MOMENT_SKEWNESS, /* Third-order moment. */
31 MOMENT_KURTOSIS /* Fourth-order moment. */
36 /* Two-pass moments. */
37 struct moments *moments_create (enum moment max_moment);
38 void moments_clear (struct moments *);
39 void moments_pass_one (struct moments *, double value, double weight);
40 void moments_pass_two (struct moments *, double value, double weight);
41 void moments_calculate (const struct moments *,
43 double *mean, double *variance,
44 double *skewness, double *kurtosis);
45 void moments_destroy (struct moments *);
47 /* Convenience functions for two-pass moments. */
48 void moments_of_doubles (const double *array, size_t n,
50 double *mean, double *variance,
51 double *skewness, double *kurtosis);
52 void moments_of_values (const union value *array, size_t n,
54 double *mean, double *variance,
55 double *skewness, double *kurtosis);
57 /* One-pass moments. Use only if two passes are impractical. */
58 struct moments1 *moments1_create (enum moment max_moment);
59 void moments1_clear (struct moments1 *);
60 void moments1_add (struct moments1 *, double value, double weight);
61 void moments1_calculate (const struct moments1 *,
63 double *mean, double *variance,
64 double *skewness, double *kurtosis);
65 void moments1_destroy (struct moments1 *);
67 /* Standard errors. */
68 double calc_semean (double variance, double weight);
69 double calc_seskew (double weight);
70 double calc_sekurt (double weight);
72 #endif /* moments.h */