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
);
71 tukey_hinges_create (double W
, double c_min
)
74 struct tukey_hinges
*th
= XZALLOC (struct tukey_hinges
);
75 struct order_stats
*os
= &th
->parent
;
76 struct statistic
*stat
= &os
->parent
;
85 d
= floor ((W
+ 3) / 2.0) / 2.0;
88 os
->k
[1].tc
= W
/2.0 + 0.5;
89 os
->k
[2].tc
= W
+ 1 - d
;
93 d
= floor ((W
/c_min
+ 3.0)/ 2.0) / 2.0 ;
94 os
->k
[0].tc
= d
* c_min
;
95 os
->k
[1].tc
= (W
+ c_min
) / 2.0;
96 os
->k
[2].tc
= W
+ c_min
* (1 - d
);
100 stat
->destroy
= destroy
;