CROSSTABS: Fix tabular output when columns or rows are empty.
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 6 Mar 2024 22:32:41 +0000 (14:32 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 6 Mar 2024 22:32:41 +0000 (14:32 -0800)
Thanks to Andreas Hammer for reporting the bug.

src/language/commands/crosstabs.c
tests/language/commands/crosstabs.at

index f662de2b4954b62df106235737abd248474f9dfe..d5c055c21f2052f7212660be5c11e0297a85ee5b 100644 (file)
@@ -1712,7 +1712,6 @@ display_crosstabulation (struct crosstabs_proc *proc,
     indexes[i + 3] = xt->const_indexes[i];
 
   /* Put in the actual cells. */
-  double *mp = xt->mat;
   for (size_t r = 0; r < n_rows; r++)
     {
       if (!xt->row_tot[r] && proc->mode != INTEGER)
@@ -1726,6 +1725,7 @@ display_crosstabulation (struct crosstabs_proc *proc,
 
           indexes[COL_VAR + 1] = c;
 
+          double *mp = xt->mat + r * n_cols + c;
           double expected_value = xt->row_tot[r] * xt->col_tot[c] / xt->total;
           double residual = *mp - expected_value;
           double sresidual = residual / sqrt (expected_value);
@@ -1750,8 +1750,6 @@ display_crosstabulation (struct crosstabs_proc *proc,
               pivot_table_put (table, indexes, table->n_dimensions,
                                pivot_value_new_number (entries[cell]));
             }
-
-          mp++;
         }
     }
 
index f6cc80b9e8ef339b6ba8a15b1e27f4efe2feb384..8a3b1a15d45c18fc4759dd1bd22aebf4cfd733d8 100644 (file)
@@ -446,14 +446,14 @@ Table: x × y × z
 ,,,,,y,,Total
 ,,,,,1,2,
 z,1,x,1,Count,1,0,1
-,,,3,Count,0,0,1
-,,,5,Count,1,0,1
-,,,7,Count,0,0,1
-,,,8,Count,0,1,1
+,,,3,Count,1,0,1
+,,,5,Count,0,1,1
+,,,7,Count,1,0,1
+,,,8,Count,1,0,1
 ,,Total,,Count,4,1,5
-,2,x,2,Count,0,0,1
-,,,4,Count,0,1,1
-,,,6,Count,0,0,1
+,2,x,2,Count,0,1,1
+,,,4,Count,1,0,1
+,,,6,Count,1,0,1
 ,,,9,Count,1,0,1
 ,,Total,,Count,3,1,4