From d1d36e7a9553b6effe6e6839128a05ef82b59466 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 17 Oct 2010 15:04:26 +0200 Subject: [PATCH] Fixed bug in oneway /descriptives subcommand vs. weights. The descriptives option was misinterpreting the weight value when calculating max and min. This change fixes the bug and adds a test to check for it. --- src/language/stats/oneway.c | 34 ++++++------ tests/language/stats/oneway.at | 94 ++++++++++++++++++++++++++++++---- 2 files changed, 101 insertions(+), 27 deletions(-) diff --git a/src/language/stats/oneway.c b/src/language/stats/oneway.c index aa8a2552..ea587cec 100644 --- a/src/language/stats/oneway.c +++ b/src/language/stats/oneway.c @@ -370,11 +370,11 @@ updateit (void *user_data, weight = wv != NULL ? case_data (c, wv)->f : 1.0; moments1_add (dd->mom, valx->f, weight); - if (valx->f * weight < dd->minimum) - dd->minimum = valx->f * weight; + if (valx->f < dd->minimum) + dd->minimum = valx->f; - if (valx->f * weight > dd->maximum) - dd->maximum = valx->f * weight; + if (valx->f > dd->maximum) + dd->maximum = valx->f; { const struct variable *var = dd_total->var; @@ -384,11 +384,11 @@ updateit (void *user_data, val->f, weight); - if (val->f * weight < dd_total->minimum) - dd_total->minimum = val->f * weight; + if (val->f < dd_total->minimum) + dd_total->minimum = val->f; - if (val->f * weight > dd_total->maximum) - dd_total->maximum = val->f * weight; + if (val->f > dd_total->maximum) + dd_total->maximum = val->f; } } @@ -508,21 +508,21 @@ run_oneway (const struct oneway_spec *cmd, totals->sum += weight * val->f; totals->ssq += weight * pow2 (val->f); - if ( val->f * weight < totals->minimum ) - totals->minimum = val->f * weight; + if ( val->f < totals->minimum ) + totals->minimum = val->f; - if ( val->f * weight > totals->maximum ) - totals->maximum = val->f * weight; + if ( val->f > totals->maximum ) + totals->maximum = val->f; gs->n += weight; gs->sum += weight * val->f; gs->ssq += weight * pow2 (val->f); - if ( val->f * weight < gs->minimum ) - gs->minimum = val->f * weight; + if ( val->f < gs->minimum ) + gs->minimum = val->f; - if ( val->f * weight > gs->maximum ) - gs->maximum = val->f * weight; + if ( val->f > gs->maximum ) + gs->maximum = val->f; } gp->n_groups = hsh_count (group_hash ); @@ -906,7 +906,7 @@ show_descriptives (const struct oneway_spec *cmd, const struct oneway_workspace /* Now fill in the numbers ... */ - tab_fixed (t, 2, row + count, 0, n, 8, 0); + tab_double (t, 2, row + count, 0, n, wfmt); tab_double (t, 3, row + count, 0, mean, NULL); diff --git a/tests/language/stats/oneway.at b/tests/language/stats/oneway.at index 47df1883..1649e5ee 100644 --- a/tests/language/stats/oneway.at +++ b/tests/language/stats/oneway.at @@ -6,17 +6,17 @@ AT_DATA([oneway.sps], BEGIN DATA 7 3 4 3 -3 1 -2 1 -1 1 -4 2 -2 2 -3 2 +3 1 +2 1 +1 1 +4 2 +2 2 +3 2 5 3 -1 1 -4 1 -5 2 -2 2 +1 1 +4 1 +5 2 +2 2 3 3 6 3 END DATA @@ -477,3 +477,77 @@ z,Assume equal variances,1,-9.70,8.07,1.20,20,.24 ]) AT_CLEANUP + + + +dnl Tests that everything treats weights properly +AT_SETUP([ONEWAY vs. weights]) + +AT_DATA([oneway-unweighted.sps], +[DATA LIST NOTABLE LIST /QUALITY * BRAND * W *. +BEGIN DATA +3 1 1 +2 1 1 +1 1 1 +1 1 1 +4 1 1 +5 2 1 +2 2 1 +4 2 1 +4 2 1 +4 2 1 +2 2 1 +2 2 1 +3 2 1 +7 3 1 +4 3 1 +5 3 1 +5 3 1 +3 3 1 +6 3 1 +END DATA. + +WEIGHT BY W. + +ONEWAY + quality BY brand + /STATISTICS descriptives homogeneity + . +]) + +AT_CHECK([pspp -o pspp-unweighted.csv oneway-unweighted.sps], [0], [ignore], [ignore]) + +AT_DATA([oneway-weighted.sps], +[DATA LIST NOTABLE LIST /QUALITY * BRAND * W *. +BEGIN DATA +3 1 1 +2 1 1 +1 1 2 +4 1 1 +5 2 1 +2 2 1 +4 2 3 +2 2 2 +3 2 1 +7 3 1 +4 3 1 +5 3 2 +3 3 1 +6 3 1 +END DATA. + +WEIGHT BY W. + +ONEWAY + quality BY brand + /STATISTICS descriptives homogeneity + . +]) + +AT_CHECK([pspp -o pspp-weighted.csv oneway-weighted.sps], [0], [ignore], [ignore]) + + +AT_CHECK([diff pspp-weighted.csv pspp-unweighted.csv], [0]) + + +AT_CLEANUP -- 2.30.2