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/trimmed-mean.h"
23 #include "data/val-type.h"
24 #include "libpspp/assertion.h"
25 #include "libpspp/cast.h"
26 #include "math/order-stats.h"
28 #include "gl/xalloc.h"
31 acc (struct statistic
*s
, const struct ccase
*cx UNUSED
, double c
, double cc
, double y
)
33 struct trimmed_mean
*tm
= UP_CAST (s
, struct trimmed_mean
, parent
.parent
);
34 struct order_stats
*os
= &tm
->parent
;
36 if ( cc
> os
->k
[0].tc
&& cc
<= os
->k
[1].tc
)
39 if ( tm
->cyk1p1
== SYSMIS
&& cc
> os
->k
[0].tc
)
44 destroy (struct statistic
*s
)
46 struct trimmed_mean
*tm
= UP_CAST (s
, struct trimmed_mean
, parent
.parent
);
47 struct order_stats
*os
= &tm
->parent
;
53 trimmed_mean_create (double W
, double tail
)
55 struct trimmed_mean
*tm
= xzalloc (sizeof (*tm
));
56 struct order_stats
*os
= &tm
->parent
;
57 struct statistic
*stat
= &os
->parent
;
60 os
->k
= xcalloc (2, sizeof (*os
->k
));
65 os
->k
[0].tc
= tail
* W
;
66 os
->k
[1].tc
= W
* (1 - tail
);
68 stat
->accumulate
= acc
;
69 stat
->destroy
= destroy
;
80 trimmed_mean_calculate (const struct trimmed_mean
*tm
)
82 const struct order_stats
*os
= (const struct order_stats
*) tm
;
86 (os
->k
[0].cc
- os
->k
[0].tc
) * os
->k
[0].y_p1
88 (tm
->w
- os
->k
[1].cc
- os
->k
[0].tc
) * os
->k
[1].y_p1
92 / ((1.0 - tm
->tail
* 2) * tm
->w
);