math: Improve comments.
[pspp] / src / math / percentiles.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #ifndef __PERCENTILES_H__
18 #define __PERCENTILES_H__
19
20 #include <stddef.h>
21
22 #include "order-stats.h"
23
24 /* To calculate a percentile:
25
26    - Create a "struct percentile" with percentile_create().
27    - Feed in the data with order_stats_accumulate() or
28      order_stats_accumulate_idx().  The data must be in sorted order: if
29      necessary, use one of the sorting functions from sort.h to sort them.
30    - Obtain the percentile with percentile_calculate().
31    - Destroy the data structure with statistic_destroy().
32 */
33
34 /* The algorithm used to calculate percentiles */
35 enum pc_alg {
36   PC_NONE=0,
37   PC_HAVERAGE,
38   PC_WAVERAGE,
39   PC_ROUND,
40   PC_EMPIRICAL,
41   PC_AEMPIRICAL
42 } ;
43
44 struct percentile
45 {
46   struct order_stats parent;
47
48   double ptile;
49   double w;
50
51   /* Mutable */
52   double g1;
53   double g1_star;
54
55   double g2;
56   double g2_star;
57
58   struct k k[2];
59 };
60
61 struct percentile *percentile_create (double p, double W);
62 double percentile_calculate (const struct percentile *, enum pc_alg);
63
64 #endif  /* percentiles.h */