1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2008, 2009, 2011 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/>. */
19 #include "math/tukey-hinges.h"
23 #include "libpspp/assertion.h"
24 #include "libpspp/cast.h"
25 #include "math/order-stats.h"
27 #include "gl/xalloc.h"
30 tukey_hinges_calculate (const struct tukey_hinges *th, double hinge[3])
35 const struct order_stats *os = &th->parent;
37 for (i = 0 ; i < 3 ; ++i)
39 a_star[i] = os->k[i].tc - os->k[i].cc;
40 a[i] = a_star[i] / os->k[i].c_p1;
44 if (os->k[i].c_p1 >= 1 )
46 hinge[i] = (1 - a_star[i]) * os->k[i].y
47 + a_star[i] * os->k[i].y_p1;
51 hinge[i] = (1 - a[i]) * os->k[i].y
52 + a[i] * os->k[i].y_p1;
57 hinge[i] = os->k[i].y_p1;
64 destroy (struct statistic *s)
66 struct tukey_hinges *th = UP_CAST (s, struct tukey_hinges, parent.parent);
67 struct order_stats *os = &th->parent;
74 tukey_hinges_create (double W, double c_min)
77 struct tukey_hinges *th = xzalloc (sizeof (*th));
78 struct order_stats *os = &th->parent;
79 struct statistic *stat = &os->parent;
84 os->k = xcalloc (3, sizeof (*os->k));
88 d = floor ((W + 3) / 2.0) / 2.0;
91 os->k[1].tc = W/2.0 + 0.5;
92 os->k[2].tc = W + 1 - d;
96 d = floor ((W/c_min + 3.0)/ 2.0) / 2.0 ;
97 os->k[0].tc = d * c_min;
98 os->k[1].tc = (W + c_min) / 2.0;
99 os->k[2].tc = W + c_min * (1 - d);
103 stat->destroy = destroy;