mode: New order statistic.
[pspp] / src / math / mode.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2008, 2009, 2022 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 MATH_MODE_H
18 #define MATH_MODE_H 1
19
20 #include <stddef.h>
21
22 #include "order-stats.h"
23
24 /* To calculate the mode:
25
26    - Create a "struct mode" with mode_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    - The members of "struct mode" then designate the mode.
31    - Destroy the data structure with statistic_destroy().
32 */
33
34 struct mode
35 {
36   struct order_stats parent;
37
38   /* These are initialized by order_stats_accumulate{_idx}(). */
39   double mode;          /* The value of the smallest mode, if 'n_modes' > 0. */
40   double mode_weight;   /* The weight of each mode, if 'n_modes' > 0. */
41   size_t n_modes;       /* The number of modes. */
42 };
43
44 struct mode *mode_create (void);
45
46 #endif /* mode.h */