checkin of 0.3.0
[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 /* Returns the fourth power of its argument. */
37 extern inline double
38 hypercube (double x)
39 {
40   x *= x;
41   return x * x;
42 }
43
44 /* Returns the cube of its argument. */
45 extern inline double
46 cube (double x)
47 {
48   return x * x * x;
49 }
50
51 /* Returns the square of its argument. */
52 extern inline double
53 sqr (double x)
54 {
55   return x * x;
56 }
57
58 /* Mean, standard error of mean. */
59 #define calc_mean(D, N)                                         \
60         ((D)[0] / (N))
61 #define calc_semean(STDDEV, N)                  \
62         ((STDDEV) / sqrt (N))
63
64 /* Variance, standard deviation, coefficient of variance. */
65 #define calc_variance(D, N)                             \
66         ( ((D)[1] - sqr ((D)[0])/(N)) / ((N)-1) )
67 #define calc_stddev(VARIANCE)                   \
68         (sqrt (VARIANCE))
69 #define calc_cfvar(D, N)                                        \
70         ( calc_stddev (calc_variance (D, N)) / calc_mean (D, N) )
71
72 /* Kurtosis, standard error of kurtosis. */
73 double calc_kurt (const double d[4], double n, double variance);
74 double calc_sekurt (double n);
75
76 /* Skewness, standard error of skewness. */
77 double calc_skew (const double d[3], double n, double stddev);
78 double calc_seskew (double n);
79
80 /* Significance. */
81 double normal_sig (double x);
82 double chisq_sig (double chisq, int df);
83
84 #endif /* !statistics_h */