Sat Dec 27 16:16:49 2003 Ben Pfaff <blp@gnu.org>
[pspp-builds.git] / src / stats.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 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 #if !statistics_h
21 #define statistics_h 1
22
23 /* These are all sample statistics except for mean since uses
24    population statistics for whatever reason. */
25
26 /* Define pi to the maximum precision available. */
27 #include <math.h>               /* defines M_PI on many systems */
28 #ifndef PI
29 #ifdef M_PI
30 #define PI M_PI
31 #else /* !PI && !M_PI */
32 #define PI 3.14159265358979323846264338327
33 #endif /* !PI && !M_PI */
34 #endif /* !PI */
35
36 extern double pow4 (double);
37 extern double cube (double);
38 extern double sqr (double);
39
40 /* Returns the fourth power of its argument. */
41 extern inline double
42 pow4 (double x)
43 {
44   x *= x;
45   return x * x;
46 }
47
48 /* Returns the cube of its argument. */
49 extern inline double
50 cube (double x)
51 {
52   return x * x * x;
53 }
54
55 /* Returns the square of its argument. */
56 extern inline double
57 sqr (double x)
58 {
59   return x * x;
60 }
61
62 /* Mean, standard error of mean. */
63 #define calc_mean(D, N)                                         \
64         ((D)[0] / (N))
65 #define calc_semean(STDDEV, N)                  \
66         ((STDDEV) / sqrt (N))
67
68 /* Variance, standard deviation, coefficient of variance. */
69 #define calc_variance(D, N)                             \
70         ( ((D)[1] - sqr ((D)[0])/(N)) / ((N)-1) )
71 #define calc_stddev(VARIANCE)                   \
72         (sqrt (VARIANCE))
73 #define calc_cfvar(D, N)                                        \
74         ( calc_stddev (calc_variance (D, N)) / calc_mean (D, N) )
75
76 /* Kurtosis, standard error of kurtosis. */
77 double calc_kurt (const double d[4], double n, double variance);
78 double calc_sekurt (double n);
79
80 /* Skewness, standard error of skewness. */
81 double calc_skew (const double d[3], double n, double stddev);
82 double calc_seskew (double n);
83
84 /* Significance. */
85 double normal_sig (double x);
86 double chisq_sig (double chisq, int df);
87
88 #endif /* !statistics_h */