projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pspp-mode.el: Make indentation closer to what lisp people like.
[pspp]
/
src
/
math
/
percentiles.c
diff --git
a/src/math/percentiles.c
b/src/math/percentiles.c
index bf99de163ffbaafe2af8711685e9a640a0256784..a55cfaf2bf2fdd4b165907451ab569a059a737e4 100644
(file)
--- a/
src/math/percentiles.c
+++ b/
src/math/percentiles.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008
, 2009, 2011
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-15,21
+15,22
@@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
-#include "percentiles.h"
-#include <math/order-stats.h>
+#include "math/percentiles.h"
+
+#include "data/casereader.h"
+#include "data/val-type.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+#include "libpspp/cast.h"
+#include "math/order-stats.h"
+
+#include "gl/xalloc.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) msgid
-#include <libpspp/assertion.h>
-#include <data/val-type.h>
-#include <gl/xalloc.h>
-#include <data/variable.h>
-#include <data/casereader.h>
-
-
const char *const ptile_alg_desc[] = {
"",
N_("HAverage"),
const char *const ptile_alg_desc[] = {
"",
N_("HAverage"),
@@
-44,32
+45,30
@@
const char *const ptile_alg_desc[] = {
double
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
{
double
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
{
- struct percentile *mutable =
(struct percentile *) ptl
;
+ struct percentile *mutable =
CONST_CAST (struct percentile *, ptl)
;
const struct order_stats *os = &ptl->parent;
const struct order_stats *os = &ptl->parent;
- assert (os->cc == ptl->w);
-
- if ( ptl->g1 == SYSMIS)
+ if (ptl->g1 == SYSMIS)
mutable->g1 = (os->k[0].tc - os->k[0].cc) / os->k[0].c_p1;
mutable->g1 = (os->k[0].tc - os->k[0].cc) / os->k[0].c_p1;
- if (
ptl->g1_star == SYSMIS)
+ if (ptl->g1_star == SYSMIS)
mutable->g1_star = os->k[0].tc - os->k[0].cc;
mutable->g1_star = os->k[0].tc - os->k[0].cc;
- if (
ptl->g2 == SYSMIS)
+ if (ptl->g2 == SYSMIS)
{
{
- if (
os->k[1].c == 0
)
+ if (
os->k[1].c == 0
)
mutable->g2 = os->k[1].tc / os->k[1].c_p1;
mutable->g2 = os->k[1].tc / os->k[1].c_p1;
- else if (
os->k[1].c_p1 == 0
)
+ else if (
os->k[1].c_p1 == 0
)
mutable->g2 = 0;
else
mutable->g2 = (os->k[1].tc - os->k[1].cc) / os->k[1].c_p1;
}
mutable->g2 = 0;
else
mutable->g2 = (os->k[1].tc - os->k[1].cc) / os->k[1].c_p1;
}
- if (
ptl->g2_star == SYSMIS)
+ if (ptl->g2_star == SYSMIS)
{
{
- if (
os->k[1].c == 0
)
+ if (
os->k[1].c == 0
)
mutable->g2_star = os->k[1].tc;
mutable->g2_star = os->k[1].tc;
- else if (
os->k[1].c_p1 == 0
)
+ else if (
os->k[1].c_p1 == 0
)
mutable->g2_star = 0;
else
mutable->g2_star = os->k[1].tc - os->k[1].cc;
mutable->g2_star = 0;
else
mutable->g2_star = os->k[1].tc - os->k[1].cc;
@@
-78,11
+77,11
@@
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
switch (alg)
{
case PC_WAVERAGE:
switch (alg)
{
case PC_WAVERAGE:
- if (
ptl->g1_star >= 1.0)
+ if (ptl->g1_star >= 1.0)
return os->k[0].y_p1;
else
{
return os->k[0].y_p1;
else
{
- double a = (
os->k[0].y == SYSMIS
) ? 0 : os->k[0].y;
+ double a = (
os->k[0].y == SYSMIS
) ? 0 : os->k[0].y;
if (os->k[0].c_p1 >= 1.0)
return (1 - ptl->g1_star) * a + ptl->g1_star * os->k[0].y_p1;
if (os->k[0].c_p1 >= 1.0)
return (1 - ptl->g1_star) * a + ptl->g1_star * os->k[0].y_p1;
@@
-93,7
+92,7
@@
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
case PC_ROUND:
{
case PC_ROUND:
{
- double a = (
os->k[0].y == SYSMIS
) ? 0 : os->k[0].y;
+ double a = (
os->k[0].y == SYSMIS
) ? 0 : os->k[0].y;
if (os->k[0].c_p1 >= 1.0)
return (ptl->g1_star < 0.5) ? a : os->k[0].y_p1;
if (os->k[0].c_p1 >= 1.0)
return (ptl->g1_star < 0.5) ? a : os->k[0].y_p1;
@@
-103,24
+102,24
@@
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
break;
case PC_EMPIRICAL:
break;
case PC_EMPIRICAL:
- if (
ptl->g1_star == 0
)
+ if (
ptl->g1_star == 0
)
return os->k[0].y;
else
return os->k[0].y_p1;
break;
case PC_HAVERAGE:
return os->k[0].y;
else
return os->k[0].y_p1;
break;
case PC_HAVERAGE:
- if (
ptl->g2_star >= 1.0)
+ if (ptl->g2_star >= 1.0)
{
return os->k[1].y_p1;
}
else
{
{
return os->k[1].y_p1;
}
else
{
- double a = (
os->k[1].y == SYSMIS
) ? 0 : os->k[1].y;
+ double a = (
os->k[1].y == SYSMIS
) ? 0 : os->k[1].y;
- if (
os->k[1].c_p1 >= 1.0)
+ if (os->k[1].c_p1 >= 1.0)
{
{
- if (
ptl->g2_star == 0)
+ if (ptl->g2_star == 0)
return os->k[1].y;
return (1 - ptl->g2_star) * a + ptl->g2_star * os->k[1].y_p1;
return os->k[1].y;
return (1 - ptl->g2_star) * a + ptl->g2_star * os->k[1].y_p1;
@@
-134,7
+133,7
@@
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
break;
case PC_AEMPIRICAL:
break;
case PC_AEMPIRICAL:
- if (
ptl->g1_star == 0
)
+ if (
ptl->g1_star == 0
)
return (os->k[0].y + os->k[0].y_p1)/ 2.0;
else
return os->k[0].y_p1;
return (os->k[0].y + os->k[0].y_p1)/ 2.0;
else
return os->k[0].y_p1;
@@
-154,18
+153,19
@@
percentile_calculate (const struct percentile *ptl, enum pc_alg alg)
static void
destroy (struct statistic *stat)
{
static void
destroy (struct statistic *stat)
{
- struct order_stats *os = (struct order_stats *) stat;
+ struct percentile *ptl = UP_CAST (stat, struct percentile, parent.parent);
+ struct order_stats *os = &ptl->parent;
free (os->k);
free (os->k);
- free (
os
);
+ free (
ptl
);
}
}
-struct
order_stats
*
+struct
percentile
*
percentile_create (double p, double W)
{
struct percentile *ptl = xzalloc (sizeof (*ptl));
percentile_create (double p, double W)
{
struct percentile *ptl = xzalloc (sizeof (*ptl));
- struct order_stats *os =
(struct order_stats *) ptl
;
- struct statistic *stat =
(struct statistic *) ptl
;
+ struct order_stats *os =
&ptl->parent
;
+ struct statistic *stat =
&os->parent
;
assert (p >= 0);
assert (p <= 1.0);
assert (p >= 0);
assert (p <= 1.0);
@@
-174,7
+174,7
@@
percentile_create (double p, double W)
ptl->w = W;
os->n_k = 2;
ptl->w = W;
os->n_k = 2;
- os->k = xcalloc (
sizeof (*os->k), 2
);
+ os->k = xcalloc (
2, sizeof (*os->k)
);
os->k[0].tc = W * p;
os->k[1].tc = (W + 1.0) * p;
os->k[0].tc = W * p;
os->k[1].tc = (W + 1.0) * p;
@@
-186,6
+186,6
@@
percentile_create (double p, double W)
stat->destroy = destroy;
stat->destroy = destroy;
- return
os
;
+ return
ptl
;
}
}