DESCRIPTIVES: Fix calculation of Z-scores with listwise missing values.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 4 Jun 2025 21:34:03 +0000 (14:34 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 4 Jun 2025 22:03:02 +0000 (15:03 -0700)
src/language/commands/descriptives.c
tests/language/commands/descriptives.at

index db52d9ff69c72fc53c45f970f2a48d4cdb414312..d63fe40d3deb8af1377d25614bd8bdf3205e3cf4 100644 (file)
@@ -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++)
     {
index abe2833dd1b22f3f80fe8e2b5f1d430dc879fc69..9053f33541aa5141ce333ff48cd9ddb2d0de495b 100644 (file)
@@ -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.