1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2008 Free Software Foundation, Inc.
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.
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.
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/>. */
18 #include "tukey-hinges.h"
19 #include <math/order-stats.h>
21 #include <gl/xalloc.h>
22 #include <libpspp/assertion.h>
26 tukey_hinges_calculate (const struct tukey_hinges *th, double hinge[3])
31 const struct order_stats *os = &th->parent;
33 for (i = 0 ; i < 3 ; ++i)
35 a_star[i] = os->k[i].tc - os->k[i].cc;
36 a[i] = a_star[i] / os->k[i].c_p1;
40 if (os->k[i].c_p1 >= 1 )
42 hinge[i] = (1 - a_star[i]) * os->k[i].y
43 + a_star[i] * os->k[i].y_p1;
47 hinge[i] = (1 - a[i]) * os->k[i].y
48 + a[i] * os->k[i].y_p1;
53 hinge[i] = os->k[i].y_p1;
60 destroy (struct statistic *s)
62 struct order_stats *os = (struct order_stats *) s;
69 tukey_hinges_create (double W, double c_min)
72 struct tukey_hinges *th = xzalloc (sizeof (*th));
73 struct order_stats *os = (struct order_stats *) th;
74 struct statistic *stat = (struct statistic *) th;
79 os->k = xcalloc (sizeof (*os->k), 3);
83 d = floor ((W + 3) / 2.0) / 2.0;
86 os->k[1].tc = W/2.0 + 0.5;
87 os->k[2].tc = W + 1 - d;
91 d = floor ((W/c_min + 3.0)/ 2.0) / 2.0 ;
92 os->k[0].tc = d * c_min;
93 os->k[1].tc = (W + c_min) / 2.0;
94 os->k[2].tc = W + c_min * (1 - d);
98 stat->destroy = destroy;