From 591ba84cfb5aae4fcab6af506deb0d0c39a7070e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 4 Jun 2025 14:34:03 -0700 Subject: [PATCH] DESCRIPTIVES: Fix calculation of Z-scores with listwise missing values. --- src/language/commands/descriptives.c | 30 ++++++++++----------- tests/language/commands/descriptives.at | 35 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/language/commands/descriptives.c b/src/language/commands/descriptives.c index db52d9ff69..d63fe40d3d 100644 --- a/src/language/commands/descriptives.c +++ b/src/language/commands/descriptives.c @@ -614,6 +614,21 @@ descriptives_trns_proc (void *trns_, struct ccase **c, } } + if (t->missing_type == DSC_LISTWISE) + { + assert (t->vars != NULL); + for (const struct variable **vars = t->vars; vars < t->vars + t->n_vars; + vars++) + { + double score = case_num (*c, *vars); + if (var_is_num_missing (*vars, score) & t->exclude) + { + descriptives_set_all_sysmis_zscores (t, *c); + return TRNS_CONTINUE; + } + } + } + if (t->count <= 0) { struct ccase *z_case = casereader_read (t->z_reader); @@ -645,21 +660,6 @@ descriptives_trns_proc (void *trns_, struct ccase **c, } t->count--; - if (t->missing_type == DSC_LISTWISE) - { - assert (t->vars != NULL); - for (const struct variable **vars = t->vars; vars < t->vars + t->n_vars; - vars++) - { - double score = case_num (*c, *vars); - if (var_is_num_missing (*vars, score) & t->exclude) - { - descriptives_set_all_sysmis_zscores (t, *c); - return TRNS_CONTINUE; - } - } - } - for (struct dsc_z_score *z = t->z_scores; z < t->z_scores + t->n_z_scores; z++) { diff --git a/tests/language/commands/descriptives.at b/tests/language/commands/descriptives.at index abe2833dd1..9053f33541 100644 --- a/tests/language/commands/descriptives.at +++ b/tests/language/commands/descriptives.at @@ -247,6 +247,41 @@ a,b,Za,Zb ]) AT_CLEANUP +AT_SETUP([DESCRIPTIVES -- Z scores, listwise missing]) +AT_DATA([descriptives.sps], [dnl +DATA LIST LIST NOTABLE /a b. +BEGIN DATA. +1 50 +2 60 +3 70 +. . +END DATA. + +DESCRIPTIVES /VAR=a b /MISSING=LISTWISE /SAVE. +LIST. +]) +AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl +Table: Mapping of Variables to Z-scores +Source,Target +a,Za +b,Zb + +Table: Descriptive Statistics +,N,Mean,Std Dev,Minimum,Maximum +a,3,2.00,1.00,1.00,3.00 +b,3,60.00,10.00,50.00,70.00 +Valid N (listwise),3,,,, +Missing N (listwise),1,,,, + +Table: Data List +a,b,Za,Zb +1.00,50.00,-1.00,-1.00 +2.00,60.00,.00,.00 +3.00,70.00,1.00,1.00 +. ,. ,. ,. @&t@ +]) +AT_CLEANUP + AT_SETUP([DESCRIPTIVES -- Z scores with SPLIT FILE]) AT_DATA([descriptives.sps], [dnl DATA LIST LIST NOTABLE /group a b. -- 2.30.2