projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Continue work on bug 12859, plus some code cleanup.
[pspp]
/
src
/
percentiles.c
diff --git
a/src/percentiles.c
b/src/percentiles.c
index 9719676d5c424925d76b942d7623399d81873c1e..8782c36a9b7e77f3fa5c3a60b9f17b0e543dbbba 100644
(file)
--- a/
src/percentiles.c
+++ b/
src/percentiles.c
@@
-15,8
+15,8
@@
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, Inc., 5
9 Temple Place - Suite 330
, Boston, MA
-0211
1-1307
, USA. */
+Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+0211
0-1301
, USA. */
#include "factor_stats.h"
#include "percentiles.h"
#include "factor_stats.h"
#include "percentiles.h"
@@
-80,18
+80,22
@@
ptile_round(const struct weighted_value **wv,
const struct ptile_params *par)
{
double x;
const struct ptile_params *par)
{
double x;
+ double a=0;
+
+ if ( par->k1 >= 0 )
+ a = wv[par->k1]->v.f;
if ( wv[par->k1 + 1]->w >= 1 )
{
if ( par->g1_star < 0.5 )
if ( wv[par->k1 + 1]->w >= 1 )
{
if ( par->g1_star < 0.5 )
- x =
wv[par->k1]->v.f
;
+ x =
a
;
else
x = wv[par->k1 + 1]->v.f;
}
else
{
if ( par->g1 < 0.5 )
else
x = wv[par->k1 + 1]->v.f;
}
else
{
if ( par->g1 < 0.5 )
- x =
wv[par->k1]->v.f
;
+ x =
a
;
else
x = wv[par->k1 + 1]->v.f;
else
x = wv[par->k1 + 1]->v.f;
@@
-105,6
+109,9
@@
double
ptile_haverage(const struct weighted_value **wv,
const struct ptile_params *par)
{
ptile_haverage(const struct weighted_value **wv,
const struct ptile_params *par)
{
+
+ double a=0;
+
if ( par->g2_star >= 1.0 )
return wv[par->k2 + 1]->v.f ;
if ( par->g2_star >= 1.0 )
return wv[par->k2 + 1]->v.f ;
@@
-117,15
+124,17
@@
ptile_haverage(const struct weighted_value **wv,
return wv[par->k2]->v.f;
}
return wv[par->k2]->v.f;
}
- assert(par->k2 >= 0);
+ /* Ditto for k2 < 0 */
+ if ( par->k2 >= 0 )
+ {
+ a = wv[par->k2]->v.f;
+ }
if ( wv[par->k2 + 1]->w >= 1.0 )
if ( wv[par->k2 + 1]->w >= 1.0 )
- return ( (1 - par->g2_star) * wv[par->k2]->v.f
- +
+ return ( (1 - par->g2_star) * a +
par->g2_star * wv[par->k2 + 1]->v.f);
else
par->g2_star * wv[par->k2 + 1]->v.f);
else
- return ( (1 - par->g2) * wv[par->k2]->v.f
- +
+ return ( (1 - par->g2) * a +
par->g2 * wv[par->k2 + 1]->v.f);
}
par->g2 * wv[par->k2 + 1]->v.f);
}
@@
-137,16
+146,21
@@
double
ptile_waverage(const struct weighted_value **wv,
const struct ptile_params *par)
{
ptile_waverage(const struct weighted_value **wv,
const struct ptile_params *par)
{
+ double a=0;
+
if ( par->g1_star >= 1.0 )
return wv[par->k1 + 1]->v.f ;
if ( par->g1_star >= 1.0 )
return wv[par->k1 + 1]->v.f ;
+ if ( par->k1 >= 0 )
+ {
+ a = wv[par->k1]->v.f;
+ }
+
if ( wv[par->k1 + 1]->w >= 1.0 )
if ( wv[par->k1 + 1]->w >= 1.0 )
- return ( (1 - par->g1_star) * wv[par->k1]->v.f
- +
+ return ( (1 - par->g1_star) * a +
par->g1_star * wv[par->k1 + 1]->v.f);
else
par->g1_star * wv[par->k1 + 1]->v.f);
else
- return ( (1 - par->g1) * wv[par->k1]->v.f
- +
+ return ( (1 - par->g1) * a +
par->g1 * wv[par->k1 + 1]->v.f);
}
par->g1 * wv[par->k1 + 1]->v.f);
}
@@
-305,7
+319,8
@@
void
tukey_hinges(const struct weighted_value **wv,
int n_data,
double w,
tukey_hinges(const struct weighted_value **wv,
int n_data,
double w,
- double hinges[3])
+ double hinge[3]
+ )
{
int i;
double c_star = DBL_MAX;
{
int i;
double c_star = DBL_MAX;
@@
-340,38
+355,47
@@
tukey_hinges(const struct weighted_value **wv,
for ( i = 0 ; i < 3 ; i++ )
{
for ( i = 0 ; i < 3 ; i++ )
{
- assert(h[i] + 1< n_data);
if ( h[i] >= 0 )
a_star = l[i] - wv[h[i]]->cc ;
else
a_star = l[i];
if ( h[i] >= 0 )
a_star = l[i] - wv[h[i]]->cc ;
else
a_star = l[i];
- a = a_star / ( wv[h[i]+1]->cc ) ;
+ if ( h[i] + 1 >= n_data )
+ {
+ assert( a_star < 1 ) ;
+ hinge[i] = (1 - a_star) * wv[h[i]]->v.f;
+ continue;
+ }
+ else
+ {
+ a = a_star / ( wv[h[i] + 1]->cc ) ;
+ }
if ( a_star >= 1.0 )
{
if ( a_star >= 1.0 )
{
- hinge
s
[i] = wv[h[i] + 1]->v.f ;
+ hinge[i] = wv[h[i] + 1]->v.f ;
continue;
}
continue;
}
- if ( wv[h[i]
+
1]->w >= 1)
+ if ( wv[h[i]
+
1]->w >= 1)
{
{
- hinge
s[i] = ( 1 - a_star)
* wv[h[i]]->v.f
- + a_star * wv[h[i]
+
1]->v.f;
+ hinge
[i] = ( 1 - a_star)
* wv[h[i]]->v.f
+ + a_star * wv[h[i]
+
1]->v.f;
continue;
}
continue;
}
- hinge
s[i] = ( 1 - a)* wv[h[i]]->v.f + a * wv[h[i]+
1]->v.f;
+ hinge
[i] = (1 - a) * wv[h[i]]->v.f + a * wv[h[i] +
1]->v.f;
}
}
- assert(hinge
s[0] <= hinges
[1]);
- assert(hinge
s[1] <= hinges
[2]);
+ assert(hinge
[0] <= hinge
[1]);
+ assert(hinge
[1] <= hinge
[2]);
}
}
+
int
ptile_compare(const struct percentile *p1,
const struct percentile *p2,
int
ptile_compare(const struct percentile *p1,
const struct percentile *p2,