From dff7c7a05e6da0de78544fa97c6882bd4a40d977 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 10 Feb 2009 09:55:58 +0900 Subject: [PATCH] Use the sum of weights of only those cases which are valid to calculate percentiles. Fixes bug #25522 --- src/language/stats/examine.q | 15 +++++++++++---- tests/bugs/examine-missing2.sh | 31 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index b564ba44..78ea0e63 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -122,6 +122,9 @@ struct factor_metrics /* Sum of all weights, including those for missing values */ double n; + /* Sum of weights of non_missing values */ + double n_valid; + double mean; double variance; @@ -934,23 +937,27 @@ examine_group (struct cmd_examine *cmd, struct casereader *reader, int level, case_data_idx (c, casereader_get_value_cnt (reader) - 1)->f; const double weight = wv ? case_data (c, wv)->f : 1.0; + const union value *value = case_data (c, dependent_vars[v]); if (weight != SYSMIS) minimize (&result->metrics[v].cmin, weight); moments1_add (result->metrics[v].moments, - case_data (c, dependent_vars[v])->f, + value->f, weight); result->metrics[v].n += weight; + if ( ! var_is_value_missing (dependent_vars[v], value, MV_ANY) ) + result->metrics[v].n_valid += weight; + extrema_add (result->metrics[v].maxima, - case_data (c, dependent_vars[v])->f, + value->f, weight, loc); extrema_add (result->metrics[v].minima, - case_data (c, dependent_vars[v])->f, + value->f, weight, loc); @@ -985,7 +992,7 @@ examine_group (struct cmd_examine *cmd, struct casereader *reader, int level, for (i = 0 ; i < metric->n_ptiles; ++i) { metric->ptl[i] = (struct percentile *) - percentile_create (percentile_list.data[i] / 100.0, metric->n); + percentile_create (percentile_list.data[i] / 100.0, metric->n_valid); if ( percentile_list.data[i] == 25) metric->quartiles[0] = metric->ptl[i]; diff --git a/tests/bugs/examine-missing2.sh b/tests/bugs/examine-missing2.sh index 97b19262..2cd6c14a 100755 --- a/tests/bugs/examine-missing2.sh +++ b/tests/bugs/examine-missing2.sh @@ -59,7 +59,7 @@ mkdir -p $TEMPDIR cd $TEMPDIR -activity="create program" +activity="create program 1" cat > $TESTFILE << EOF DATA LIST LIST /x * y *. BEGIN DATA. @@ -77,7 +77,7 @@ EOF if [ $? -ne 0 ] ; then no_result ; fi -activity="run program" +activity="run program 1" $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE if [ $? -ne 0 ] ; then no_result ; fi @@ -115,4 +115,31 @@ diff -b $TEMPDIR/pspp.list - < $TESTFILE << EOF +DATA LIST LIST /X *. +BEGIN DATA. +99 +99 +5.00 +END DATA. + +MISSING VALUE X (99). + +EXAMINE /x + /PERCENTILES=HAVERAGE. + + +EOF +if [ $? -ne 0 ] ; then no_result ; fi + + +activity="run program 2" +$SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE +if [ $? -ne 0 ] ; then fail ; fi + + pass; -- 2.30.2