1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
20 #ifndef HEADER_MOMENTS
21 #define HEADER_MOMENTS
26 /* Moments of the mean.
27 Higher-order moments have higher values. */
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. */
39 /* Two-pass moments. */
40 struct moments *moments_create (enum moment max_moment);
41 void moments_clear (struct moments *);
42 void moments_pass_one (struct moments *, double value, double weight);
43 void moments_pass_two (struct moments *, double value, double weight);
44 void moments_calculate (const struct moments *,
46 double *mean, double *variance,
47 double *skewness, double *kurtosis);
48 void moments_destroy (struct moments *);
50 /* Convenience functions for two-pass moments. */
51 void moments_of_doubles (const double *array, size_t cnt,
53 double *mean, double *variance,
54 double *skewness, double *kurtosis);
55 void moments_of_values (const union value *array, size_t cnt,
57 double *mean, double *variance,
58 double *skewness, double *kurtosis);
60 /* One-pass moments. Use only if two passes are impractical. */
61 struct moments1 *moments1_create (enum moment max_moment);
62 void moments1_clear (struct moments1 *);
63 void moments1_add (struct moments1 *, double value, double weight);
64 void moments1_calculate (const struct moments1 *,
66 double *mean, double *variance,
67 double *skewness, double *kurtosis);
68 void moments1_destroy (struct moments1 *);
70 /* Standard errors. */
71 double calc_semean (double stddev, double weight);
72 double calc_seskew (double weight);
73 double calc_sekurt (double weight);
75 #endif /* moments.h */