CROSSTABS: Fix computation of adjusted standardized residual.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 5 Apr 2022 14:49:17 +0000 (07:49 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 5 Apr 2022 14:49:17 +0000 (07:49 -0700)
Bug #60982.

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

index 9e77c666a5c19dc9a3c3fb9ac43f72059b2a83fe..bb63e982538b30a912e52ae94cfcce96c83a76b0 100644 (file)
@@ -1717,7 +1717,8 @@ display_crosstabulation (struct crosstabs_proc *proc,
           double expected_value = xt->row_tot[r] * xt->col_tot[c] / xt->total;
           double residual = *mp - expected_value;
           double sresidual = residual / sqrt (expected_value);
-          double asresidual = (sresidual
+          double asresidual
+            = residual / sqrt (expected_value
                                * (1. - xt->row_tot[r] / xt->total)
                                * (1. - xt->col_tot[c] / xt->total));
           double entries[CRS_N_CELLS] = {
index eab403e3c91a396a6ad25836e44f0c7143c9118e..f51c3345a4132c92ac83573634f009c954aea7d6 100644 (file)
@@ -16,6 +16,67 @@ dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
 dnl
 AT_BANNER([CROSSTABS procedure])
 
+dnl Based on bug #60982.
+AT_SETUP([CROSSTABS residuals])
+AT_DATA([crosstabs.sps],
+  [DATASET CLOSE ALL.
+DATA LIST LIST NOTABLE/ r c n.
+BEGIN DATA
+1 1 26
+1 2 31
+2 1 12
+2 2 32
+3 1 27
+3 2 18
+4 1 8
+4 2 7
+END DATA.
+WEIGHT by n.
+CROSSTABS r by c /STATISTICS=CHISQ
+/CELLS=COUNT EXPECTED RESID SRESID ASRESID.
+])
+AT_CHECK([pspp -O format=csv crosstabs.sps], [0],
+  [Table: Summary
+,Cases,,,,,
+,Valid,,Missing,,Total,
+,N,Percent,N,Percent,N,Percent
+r × c,161.00,100.0%,.00,.0%,161.00,100.0%
+
+Table: r × c
+,,,c,,Total
+,,,1.00,2.00,
+r,1.00,Count,26.00,31.00,57.00
+,,Expected,25.84,31.16,.35
+,,Residual,.16,-.16,
+,,Std. Residual,.03,-.03,
+,,Adjusted Residual,.05,-.05,
+,2.00,Count,12.00,32.00,44.00
+,,Expected,19.95,24.05,.27
+,,Residual,-7.95,7.95,
+,,Std. Residual,-1.78,1.62,
+,,Adjusted Residual,-2.82,2.82,
+,3.00,Count,27.00,18.00,45.00
+,,Expected,20.40,24.60,.28
+,,Residual,6.60,-6.60,
+,,Std. Residual,1.46,-1.33,
+,,Adjusted Residual,2.33,-2.33,
+,4.00,Count,8.00,7.00,15.00
+,,Expected,6.80,8.20,.09
+,,Residual,1.20,-1.20,
+,,Std. Residual,.46,-.42,
+,,Adjusted Residual,.65,-.65,
+Total,,Count,73.00,88.00,161.00
+,,Expected,.45,.55,1.00
+
+Table: Chi-Square Tests
+,Value,df,Asymptotic Sig. (2-tailed)
+Pearson Chi-Square,10.09,3.00,.018
+Likelihood Ratio,10.35,3.00,.016
+Linear-by-Linear Association,1.96,1.00,.162
+N of Valid Cases,161.00,,
+])
+AT_CLEANUP
+
 AT_SETUP([CROSSTABS integer mode crash])
 AT_DATA([crosstabs.sps],
   [DATA LIST LIST /A * B * X * Y * .