Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / crosstabs.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([CROSSTABS procedure])
18
19 dnl Based on bug #60982.
20 AT_SETUP([CROSSTABS residuals])
21 AT_DATA([crosstabs.sps],
22   [DATASET CLOSE ALL.
23 DATA LIST LIST NOTABLE/ r c n.
24 BEGIN DATA
25 1 1 26
26 1 2 31
27 2 1 12
28 2 2 32
29 3 1 27
30 3 2 18
31 4 1 8
32 4 2 7
33 END DATA.
34 WEIGHT by n.
35 CROSSTABS r by c /STATISTICS=CHISQ
36 /CELLS=COUNT EXPECTED RESID SRESID ASRESID.
37 ])
38 AT_CHECK([pspp -O format=csv crosstabs.sps], [0],
39   [Table: Summary
40 ,Cases,,,,,
41 ,Valid,,Missing,,Total,
42 ,N,Percent,N,Percent,N,Percent
43 r × c,161.00,100.0%,.00,.0%,161.00,100.0%
44
45 Table: r × c
46 ,,,c,,Total
47 ,,,1.00,2.00,
48 r,1.00,Count,26.00,31.00,57.00
49 ,,Expected,25.84,31.16,.35
50 ,,Residual,.16,-.16,
51 ,,Std. Residual,.03,-.03,
52 ,,Adjusted Residual,.05,-.05,
53 ,2.00,Count,12.00,32.00,44.00
54 ,,Expected,19.95,24.05,.27
55 ,,Residual,-7.95,7.95,
56 ,,Std. Residual,-1.78,1.62,
57 ,,Adjusted Residual,-2.82,2.82,
58 ,3.00,Count,27.00,18.00,45.00
59 ,,Expected,20.40,24.60,.28
60 ,,Residual,6.60,-6.60,
61 ,,Std. Residual,1.46,-1.33,
62 ,,Adjusted Residual,2.33,-2.33,
63 ,4.00,Count,8.00,7.00,15.00
64 ,,Expected,6.80,8.20,.09
65 ,,Residual,1.20,-1.20,
66 ,,Std. Residual,.46,-.42,
67 ,,Adjusted Residual,.65,-.65,
68 Total,,Count,73.00,88.00,161.00
69 ,,Expected,.45,.55,1.00
70
71 Table: Chi-Square Tests
72 ,Value,df,Asymptotic Sig. (2-tailed)
73 Pearson Chi-Square,10.09,3.00,.018
74 Likelihood Ratio,10.35,3.00,.016
75 Linear-by-Linear Association,1.96,1.00,.162
76 N of Valid Cases,161.00,,
77 ])
78 AT_CLEANUP
79
80 AT_SETUP([CROSSTABS integer mode crash])
81 AT_DATA([crosstabs.sps],
82   [DATA LIST LIST /A * B * X * Y * .
83 BEGIN DATA.
84 2 3 4 5
85 END DATA.
86
87 CROSSTABS VARIABLES X (1,7) Y (1,7) /TABLES X BY Y.
88 ])
89 AT_CHECK([pspp -o pspp.csv -o pspp.txt crosstabs.sps])
90 AT_CHECK([cat pspp.csv], [0],
91   [[Table: Reading free-form data from INLINE.
92 Variable,Format
93 A,F8.0
94 B,F8.0
95 X,F8.0
96 Y,F8.0
97
98 Table: Summary
99 ,Cases,,,,,
100 ,Valid,,Missing,,Total,
101 ,N,Percent,N,Percent,N,Percent
102 X × Y,1,100.0%,0,.0%,1,100.0%
103
104 Table: X × Y
105 ,,,Y,,,,,,,Total
106 ,,,1.00,2.00,3.00,4.00,5.00,6.00,7.00,
107 X,1.00,Count,0,0,0,0,0,0,0,0
108 ,2.00,Count,0,0,0,0,0,0,0,0
109 ,3.00,Count,0,0,0,0,0,0,0,0
110 ,4.00,Count,0,0,0,0,1,0,0,1
111 ,5.00,Count,0,0,0,0,0,0,0,0
112 ,6.00,Count,0,0,0,0,0,0,0,0
113 ,7.00,Count,0,0,0,0,0,0,0,0
114 Total,,Count,0,0,0,0,1,0,0,1
115 ]])
116 AT_CLEANUP
117
118 # Bug #47600.
119 AT_SETUP([CROSSTABS integer mode crash 2])
120 AT_DATA([crosstabs.sps], [dnl
121 DATA LIST lIST /x y.
122 BEGIN DATA.
123 4 5
124 END DATA.
125
126 CROSSTABS
127         VARIABLES x (1,3) y (1,7)
128       /TABLES x BY y.
129 ])
130 AT_CHECK([pspp -O format=csv crosstabs.sps], [0],
131   [[Table: Reading free-form data from INLINE.
132 Variable,Format
133 x,F8.0
134 y,F8.0
135
136 Table: Summary
137 ,Cases,,,,,
138 ,Valid,,Missing,,Total,
139 ,N,Percent,N,Percent,N,Percent
140 x × y,0,.0%,1,100.0%,1,100.0%
141
142 Table: x × y
143 ,,,y,,,,,,,Total
144 ,,,1.00,2.00,3.00,4.00,5.00,6.00,7.00,
145 x,1.00,Count,,,,,,,,
146 ,2.00,Count,,,,,,,,
147 ,3.00,Count,,,,,,,,
148 Total,,Count,,,,,,,,
149 ]])
150 AT_CLEANUP
151
152 # Bug #22037.
153 AT_SETUP([CROSSTABS long string crash])
154 AT_DATA([crosstabs.sps],
155   [data list list /x * y (a18).
156
157 begin data.
158
159    1. 'zero none'
160
161 1 'one unity'
162 2 'two duality'
163 3 'three lots'
164 end data.
165
166 CROSSTABS /TABLES = x BY y.
167 ])
168 AT_CHECK([pspp -o - -O format=csv -o pspp.txt crosstabs.sps], [0],
169   [[Table: Reading free-form data from INLINE.
170 Variable,Format
171 x,F8.0
172 y,A18
173
174 "crosstabs.sps:4: warning: Missing value(s) for all variables from x onward.  These will be filled with the system-missing value or blanks, as appropriate."
175
176 "crosstabs.sps:6: warning: Missing value(s) for all variables from x onward.  These will be filled with the system-missing value or blanks, as appropriate."
177
178 Table: Summary
179 ,Cases,,,,,
180 ,Valid,,Missing,,Total,
181 ,N,Percent,N,Percent,N,Percent
182 x × y,4,66.7%,2,33.3%,6,100.0%
183
184 Table: x × y
185 ,,,y,,,,Total
186 ,,,one unity,three lots,two duality,zero none,
187 x,1.00,Count,1,0,0,1,2
188 ,2.00,Count,0,0,1,0,1
189 ,3.00,Count,0,1,0,0,1
190 Total,,Count,1,1,1,1,4
191 ]])
192 AT_CLEANUP
193
194 AT_SETUP([CROSSTABS crash])
195 AT_DATA([crosstabs.sps],
196   [[DATA LIST FIXED
197      / x   1-2
198        y   3
199        z   4.
200
201 BEGIN DATA.
202 0111
203 0222
204 0311
205 0412
206 0521
207 0612
208 0711
209 0811
210 0912
211 END DATA.
212
213 LIST.
214
215
216 CROSSTABS TABLES  y by z.
217 ]])
218 AT_CHECK([pspp -o - -O format=csv -o pspp.txt crosstabs.sps], [0],
219   [Table: Reading 1 record from INLINE.
220 Variable,Record,Columns,Format
221 x,1,1-2,F2.0
222 y,1,3-3,F1.0
223 z,1,4-4,F1.0
224
225 Table: Data List
226 x,y,z
227 1,1,1
228 2,2,2
229 3,1,1
230 4,1,2
231 5,2,1
232 6,1,2
233 7,1,1
234 8,1,1
235 9,1,2
236
237 Table: Summary
238 ,Cases,,,,,
239 ,Valid,,Missing,,Total,
240 ,N,Percent,N,Percent,N,Percent
241 y × z,9,100.0%,0,.0%,9,100.0%
242
243 Table: y × z
244 ,,,z,,Total
245 ,,,1,2,
246 y,1,Count,4,3,7
247 ,2,Count,1,1,2
248 Total,,Count,5,4,9
249 ])
250 AT_CLEANUP
251
252 # Bug #26739, which caused CROSSTABS to crash or to fail to output
253 # chi-square results.
254 AT_SETUP([CROSSTABS chi-square crash])
255 AT_DATA([crosstabs.sps],
256   [[DATA LIST LIST /x * y *.
257 BEGIN DATA.
258 2 2
259 3 1
260 4 2
261 4 1
262 END DATA.
263
264 CROSSTABS
265         /TABLES= x BY y
266         /STATISTICS=CHISQ.
267 ]])
268 AT_CHECK([pspp -O format=csv crosstabs.sps], [0],
269   [[Table: Reading free-form data from INLINE.
270 Variable,Format
271 x,F8.0
272 y,F8.0
273
274 Table: Summary
275 ,Cases,,,,,
276 ,Valid,,Missing,,Total,
277 ,N,Percent,N,Percent,N,Percent
278 x × y,4,100.0%,0,.0%,4,100.0%
279
280 Table: x × y
281 ,,,y,,Total
282 ,,,1.00,2.00,
283 x,2.00,Count,0,1,1
284 ,3.00,Count,1,0,1
285 ,4.00,Count,1,1,2
286 Total,,Count,2,2,4
287
288 Table: Chi-Square Tests
289 ,Value,df,Asymptotic Sig. (2-tailed)
290 Pearson Chi-Square,2.00,2,.368
291 Likelihood Ratio,2.77,2,.250
292 Linear-by-Linear Association,.27,1,.602
293 N of Valid Cases,4,,
294 ]])
295 AT_CLEANUP
296
297 # Bug #27883.
298 AT_SETUP([CROSSTABS crash with SPLIT FILE])
299 AT_DATA([crosstabs.sps],
300   [data list notable / v0 to v2 1-6 (A)
301 begin data.
302 a c e
303 a c e
304 a c e
305 a d e
306 a d f
307 b d f
308 b d f
309 b c f
310 b d e
311 a c f
312 end data.
313 SORT CASES BY v0.
314 SPLIT FILE SEPARATE BY v0.
315
316 CROSSTABS
317     /TABLES= v1 BY v2
318     /FORMAT=AVALUE TABLES
319     /STATISTICS=CHISQ
320     /CELLS=COUNT ROW COLUMN TOTAL.
321 ])
322
323 AT_CHECK([pspp -o pspp.csv -o pspp.txt crosstabs.sps])
324 AT_CHECK([cat pspp.csv], [0], [dnl
325 Table: Split Values
326 Variable,Value
327 v0,a
328
329 Table: Summary
330 ,Cases,,,,,
331 ,Valid,,Missing,,Total,
332 ,N,Percent,N,Percent,N,Percent
333 v1 × v2,6,100.0%,0,.0%,6,100.0%
334
335 Table: v1 × v2
336 ,,,v2,,Total
337 ,,,e,f,
338 v1,c,Count,3,1,4
339 ,,Row %,75.0%,25.0%,100.0%
340 ,,Column %,75.0%,50.0%,66.7%
341 ,,Total %,50.0%,16.7%,66.7%
342 ,d,Count,1,1,2
343 ,,Row %,50.0%,50.0%,100.0%
344 ,,Column %,25.0%,50.0%,33.3%
345 ,,Total %,16.7%,16.7%,33.3%
346 Total,,Count,4,2,6
347 ,,Row %,66.7%,33.3%,100.0%
348 ,,Column %,100.0%,100.0%,100.0%
349 ,,Total %,66.7%,33.3%,100.0%
350
351 Table: Chi-Square Tests
352 ,Value,df,Asymptotic Sig. (2-tailed),Exact Sig. (2-tailed),Exact Sig. (1-tailed)
353 Pearson Chi-Square,.38,1,.540,,
354 Likelihood Ratio,.37,1,.545,,
355 Fisher's Exact Test,,,,1.000,.600
356 Continuity Correction,.00,1,1.000,,
357 N of Valid Cases,6,,,,
358
359 Table: Split Values
360 Variable,Value
361 v0,b
362
363 Table: Summary
364 ,Cases,,,,,
365 ,Valid,,Missing,,Total,
366 ,N,Percent,N,Percent,N,Percent
367 v1 × v2,4,100.0%,0,.0%,4,100.0%
368
369 Table: v1 × v2
370 ,,,v2,,Total
371 ,,,e,f,
372 v1,c,Count,0,1,1
373 ,,Row %,.0%,100.0%,100.0%
374 ,,Column %,.0%,33.3%,25.0%
375 ,,Total %,.0%,25.0%,25.0%
376 ,d,Count,1,2,3
377 ,,Row %,33.3%,66.7%,100.0%
378 ,,Column %,100.0%,66.7%,75.0%
379 ,,Total %,25.0%,50.0%,75.0%
380 Total,,Count,1,3,4
381 ,,Row %,25.0%,75.0%,100.0%
382 ,,Column %,100.0%,100.0%,100.0%
383 ,,Total %,25.0%,75.0%,100.0%
384
385 Table: Chi-Square Tests
386 ,Value,df,Asymptotic Sig. (2-tailed),Exact Sig. (2-tailed),Exact Sig. (1-tailed)
387 Pearson Chi-Square,.44,1,.505,,
388 Likelihood Ratio,.68,1,.410,,
389 Fisher's Exact Test,,,,1.000,.750
390 Continuity Correction,.00,1,1.000,,
391 N of Valid Cases,4,,,,
392 ])
393 AT_CLEANUP
394
395 # Bug #24752.
396 AT_SETUP([3-way CROSSTABS])
397 AT_DATA([crosstabs.sps],
398   [[DATA LIST FIXED
399      / x   1-2
400        y   3
401        z   4.
402
403 BEGIN DATA.
404 0111
405 0222
406 0311
407 0412
408 0521
409 0612
410 0711
411 0811
412 0912
413 END DATA.
414
415 LIST.
416
417
418 CROSSTABS TABLES  x BY y BY z/STATISTICS=ALL.
419 ]])
420 AT_CHECK([pspp -o - -O format=csv -o pspp.csv -o pspp.txt crosstabs.sps], [0],
421   [Table: Reading 1 record from INLINE.
422 Variable,Record,Columns,Format
423 x,1,1-2,F2.0
424 y,1,3-3,F1.0
425 z,1,4-4,F1.0
426
427 Table: Data List
428 x,y,z
429 1,1,1
430 2,2,2
431 3,1,1
432 4,1,2
433 5,2,1
434 6,1,2
435 7,1,1
436 8,1,1
437 9,1,2
438
439 Table: Summary
440 ,Cases,,,,,
441 ,Valid,,Missing,,Total,
442 ,N,Percent,N,Percent,N,Percent
443 x × y × z,9,100.0%,0,.0%,9,100.0%
444
445 Table: x × y × z
446 ,,,,,y,,Total
447 ,,,,,1,2,
448 z,1,x,1,Count,1,0,1
449 ,,,3,Count,0,0,1
450 ,,,5,Count,1,0,1
451 ,,,7,Count,0,0,1
452 ,,,8,Count,0,1,1
453 ,,Total,,Count,4,1,5
454 ,2,x,2,Count,0,0,1
455 ,,,4,Count,0,1,1
456 ,,,6,Count,0,0,1
457 ,,,9,Count,1,0,1
458 ,,Total,,Count,3,1,4
459
460 Table: Chi-Square Tests
461 ,,,Value,df,Asymptotic Sig. (2-tailed)
462 z,1,Pearson Chi-Square,5.00,4,.287
463 ,,Likelihood Ratio,5.00,4,.287
464 ,,Linear-by-Linear Association,.01,1,.938
465 ,,N of Valid Cases,5,,
466 ,2,Pearson Chi-Square,4.00,3,.261
467 ,,Likelihood Ratio,4.50,3,.212
468 ,,Linear-by-Linear Association,1.58,1,.209
469 ,,N of Valid Cases,4,,
470
471 Table: Symmetric Measures
472 ,,,,Value,Asymp. Std. Error,Approx. T
473 z,1,Nominal by Nominal,Phi,1.00,,
474 ,,,Cramer's V,1.00,,
475 ,,,Contingency Coefficient,.71,,
476 ,,Ordinal by Ordinal,Kendall's tau-b,.00,.32,.00
477 ,,,Kendall's tau-c,.00,.32,.00
478 ,,,Gamma,.00,.50,.00
479 ,,,Spearman Correlation,.00,.22,.00
480 ,,Interval by Interval,Pearson's R,.04,.22,.07
481 ,,N of Valid Cases,,5,,
482 ,2,Nominal by Nominal,Phi,1.00,,
483 ,,,Cramer's V,1.00,,
484 ,,,Contingency Coefficient,.71,,
485 ,,Ordinal by Ordinal,Kendall's tau-b,-.71,.20,-1.73
486 ,,,Kendall's tau-c,-.75,.43,-1.73
487 ,,,Gamma,-1.00,.00,-1.73
488 ,,,Spearman Correlation,-.77,.17,-1.73
489 ,,Interval by Interval,Pearson's R,-.73,.18,-1.49
490 ,,N of Valid Cases,,4,,
491
492 Table: Directional Measures
493 ,,,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
494 z,1,Nominal by Nominal,Lambda,Symmetric,.40,.28,1.12,.264
495 ,,,,x Dependent,.25,.22,1.12,.264
496 ,,,,y Dependent,1.00,.00,1.12,.264
497 ,,,Goodman and Kruskal tau,x Dependent,.25,,,
498 ,,,,y Dependent,1.00,,,
499 ,,,Uncertainty Coefficient,Symmetric,.47,.18,,
500 ,,,,x Dependent,.31,.15,2.02,
501 ,,,,y Dependent,1.00,.00,2.02,
502 ,,Ordinal by Ordinal,Somers' d,Symmetric,.00,,.00,1.000
503 ,,,,x Dependent,.00,.50,.00,1.000
504 ,,,,y Dependent,.00,.20,.00,1.000
505 ,,Nominal by Interval,Eta,x Dependent,.04,,,
506 ,,,,y Dependent,1.00,,,
507 ,2,Nominal by Nominal,Lambda,Symmetric,.50,.25,2.00,.046
508 ,,,,x Dependent,.33,.27,1.15,.248
509 ,,,,y Dependent,1.00,.00,1.15,.248
510 ,,,Goodman and Kruskal tau,x Dependent,.33,,,
511 ,,,,y Dependent,1.00,,,
512 ,,,Uncertainty Coefficient,Symmetric,.58,.17,,
513 ,,,,x Dependent,.41,.17,2.36,
514 ,,,,y Dependent,1.00,.00,2.36,
515 ,,Ordinal by Ordinal,Somers' d,Symmetric,-.67,,-1.73,.083
516 ,,,,x Dependent,-1.00,.00,-1.73,.083
517 ,,,,y Dependent,-.50,.29,-1.73,.083
518 ,,Nominal by Interval,Eta,x Dependent,.73,,,
519 ,,,,y Dependent,1.00,,,
520 ])
521 AT_CLEANUP
522
523 AT_SETUP([CROSSTABS rounding weights with COUNT])
524 AT_DATA([crosstabs.sps],
525   [[DATA LIST NOTABLE LIST /x y w.
526 BEGIN DATA.
527 1 1 1.4
528 1 1 1.4
529 1 2 1.6
530 1 2 1.6
531 2 1 1
532 2 2 2
533 END DATA.
534 WEIGHT BY w.
535
536 * These should have the same effect (no rounding).
537 CROSSTABS /TABLES x BY y.
538 CROSSTABS /TABLES x BY y /COUNT ASIS.
539
540 * Round input weights.
541 CROSSTABS /TABLES x BY y /COUNT CASE ROUND.
542 CROSSTABS /TABLES x BY y /COUNT CASE TRUNCATE.
543
544 * Round cell weights.
545 CROSSTABS /TABLES x BY y /COUNT.
546 CROSSTABS /TABLES x BY y /COUNT TRUNCATE.
547 ]])
548
549 AT_CHECK([pspp -o pspp.csv -o pspp.txt crosstabs.sps])
550 AT_CHECK([cat pspp.csv], [0],
551   [Table: Summary
552 ,Cases,,,,,
553 ,Valid,,Missing,,Total,
554 ,N,Percent,N,Percent,N,Percent
555 x × y,9.00,100.0%,.00,.0%,9.00,100.0%
556
557 Table: x × y
558 ,,,y,,Total
559 ,,,1.00,2.00,
560 x,1.00,Count,2.80,3.20,6.00
561 ,2.00,Count,1.00,2.00,3.00
562 Total,,Count,3.80,5.20,9.00
563
564 Table: Summary
565 ,Cases,,,,,
566 ,Valid,,Missing,,Total,
567 ,N,Percent,N,Percent,N,Percent
568 x × y,9.00,100.0%,.00,.0%,9.00,100.0%
569
570 Table: x × y
571 ,,,y,,Total
572 ,,,1.00,2.00,
573 x,1.00,Count,2.80,3.20,6.00
574 ,2.00,Count,1.00,2.00,3.00
575 Total,,Count,3.80,5.20,9.00
576
577 Table: Summary
578 ,Cases,,,,,
579 ,Valid,,Missing,,Total,
580 ,N,Percent,N,Percent,N,Percent
581 x × y,9.00,100.0%,.00,.0%,9.00,100.0%
582
583 Table: x × y
584 ,,,y,,Total
585 ,,,1.00,2.00,
586 x,1.00,Count,2.00,4.00,6.00
587 ,2.00,Count,1.00,2.00,3.00
588 Total,,Count,3.00,6.00,9.00
589
590 Table: Summary
591 ,Cases,,,,,
592 ,Valid,,Missing,,Total,
593 ,N,Percent,N,Percent,N,Percent
594 x × y,7.00,100.0%,.00,.0%,7.00,100.0%
595
596 Table: x × y
597 ,,,y,,Total
598 ,,,1.00,2.00,
599 x,1.00,Count,2.00,2.00,4.00
600 ,2.00,Count,1.00,2.00,3.00
601 Total,,Count,3.00,4.00,7.00
602
603 Table: Summary
604 ,Cases,,,,,
605 ,Valid,,Missing,,Total,
606 ,N,Percent,N,Percent,N,Percent
607 x × y,9.00,100.0%,.00,.0%,9.00,100.0%
608
609 Table: x × y
610 ,,,y,,Total
611 ,,,1.00,2.00,
612 x,1.00,Count,3.00,3.00,6.00
613 ,2.00,Count,1.00,2.00,3.00
614 Total,,Count,4.00,5.00,9.00
615
616 Table: Summary
617 ,Cases,,,,,
618 ,Valid,,Missing,,Total,
619 ,N,Percent,N,Percent,N,Percent
620 x × y,8.00,100.0%,.00,.0%,8.00,100.0%
621
622 Table: x × y
623 ,,,y,,Total
624 ,,,1.00,2.00,
625 x,1.00,Count,2.00,3.00,5.00
626 ,2.00,Count,1.00,2.00,3.00
627 Total,,Count,3.00,5.00,8.00
628 ])
629 AT_CLEANUP
630
631 AT_SETUP([CROSSTABS descending sort order])
632 AT_DATA([crosstabs-descending.sps],
633   [[DATA LIST NOTABLE LIST /x * y *.
634 BEGIN DATA.
635 2 2
636 2 2
637 3 1
638 4 1
639 3 2
640 3 2
641 END DATA.
642
643 CROSSTABS
644         /TABLES= x BY y
645         /FORMAT = DVALUE.
646 ]])
647
648 AT_CHECK([pspp -o pspp.csv -o pspp.txt crosstabs-descending.sps])
649 AT_CHECK([cat pspp.csv], [0],
650   [Table: Summary
651 ,Cases,,,,,
652 ,Valid,,Missing,,Total,
653 ,N,Percent,N,Percent,N,Percent
654 x × y,6,100.0%,0,.0%,6,100.0%
655
656 Table: x × y
657 ,,,y,,Total
658 ,,,2.00,1.00,
659 x,4.00,Count,0,1,1
660 ,3.00,Count,2,1,3
661 ,2.00,Count,2,0,2
662 Total,,Count,4,2,6
663 ])
664 AT_CLEANUP
665
666 # Bug #31260.
667 AT_SETUP([CROSSTABS crash when all cases missing])
668 AT_DATA([crosstabs.sps], [dnl
669 DATA LIST LIST NOTABLE /X1 X2.
670 BEGIN DATA.
671 1 1
672 END DATA.
673
674 MISSING VALUES x2 (1).
675
676 CROSSTABS /TABLES= X1 by X2.
677 ])
678 AT_CHECK([pspp -O format=csv crosstabs.sps], [0], [dnl
679 Table: Summary
680 ,Cases,,,,,
681 ,Valid,,Missing,,Total,
682 ,N,Percent,N,Percent,N,Percent
683 X1 × X2,0,.0%,1,100.0%,1,100.0%
684
685 "crosstabs.sps:8.20-8.27: warning: CROSSTABS: Crosstabulation X1 × X2 contained no non-missing cases.
686     8 | CROSSTABS /TABLES= X1 by X2.
687       |                    ^~~~~~~~"
688 ])
689 AT_CLEANUP
690
691
692
693 dnl This example comes from http://www.ats.ucla.edu/stat/spss/whatstat/whatstat.htm#chisq
694 AT_SETUP([CROSSTABS Fisher Exact Test])
695
696 AT_DATA([fisher-exact.sps], [dnl
697 SET FORMAT F12.3.
698 SET DECIMAL DOT.
699
700 DATA LIST notable LIST  /schtyp (F9.2) female (F9.2) ses (F9.2) .
701 begin data.
702       1.00       .00      1.00
703       1.00      1.00      2.00
704       1.00       .00      3.00
705       1.00       .00      3.00
706       1.00       .00      2.00
707       1.00       .00      2.00
708       1.00       .00      2.00
709       1.00       .00      2.00
710       1.00       .00      2.00
711       1.00       .00      2.00
712       1.00       .00      2.00
713       1.00       .00      2.00
714       1.00       .00      3.00
715       1.00       .00      3.00
716       1.00       .00      1.00
717       1.00       .00      1.00
718       1.00       .00      3.00
719       2.00       .00      2.00
720       1.00       .00      3.00
721       1.00       .00      2.00
722       1.00       .00      2.00
723       1.00       .00      2.00
724       1.00       .00      2.00
725       1.00       .00      3.00
726       1.00       .00      2.00
727       1.00       .00      2.00
728       1.00       .00      3.00
729       2.00       .00      2.00
730       2.00       .00      3.00
731       1.00       .00      1.00
732       1.00       .00      2.00
733       1.00       .00      3.00
734       2.00       .00      3.00
735       1.00       .00      2.00
736       2.00       .00      3.00
737       1.00       .00      3.00
738       2.00       .00      2.00
739       1.00       .00      3.00
740       1.00       .00      1.00
741       1.00       .00      2.00
742       2.00       .00      2.00
743       2.00       .00      2.00
744       1.00       .00      2.00
745       1.00       .00      1.00
746       1.00       .00      3.00
747       1.00       .00      1.00
748       1.00       .00      3.00
749       1.00       .00      2.00
750       2.00       .00      2.00
751       1.00       .00      2.00
752       1.00       .00      2.00
753       1.00       .00      3.00
754       1.00       .00      2.00
755       2.00       .00      2.00
756       1.00       .00      2.00
757       1.00       .00      3.00
758       1.00       .00      1.00
759       1.00       .00      2.00
760       2.00       .00      2.00
761       1.00       .00      2.00
762       2.00       .00      2.00
763       1.00       .00      3.00
764       1.00       .00      1.00
765       1.00       .00      2.00
766       2.00       .00      3.00
767       1.00       .00      2.00
768       1.00       .00      2.00
769       1.00       .00      1.00
770       1.00       .00      1.00
771       1.00       .00      2.00
772       1.00       .00      2.00
773       1.00       .00      3.00
774       1.00       .00      2.00
775       1.00       .00      2.00
776       1.00       .00      2.00
777       1.00       .00      1.00
778       1.00       .00      3.00
779       1.00       .00      3.00
780       1.00       .00      2.00
781       1.00       .00      3.00
782       1.00       .00      3.00
783       1.00       .00      1.00
784       2.00       .00      2.00
785       1.00       .00      1.00
786       1.00       .00      2.00
787       1.00       .00      3.00
788       1.00       .00      3.00
789       1.00       .00      3.00
790       1.00       .00      2.00
791       1.00       .00      3.00
792       1.00       .00      2.00
793       1.00       .00      1.00
794       1.00      1.00      3.00
795       1.00      1.00      1.00
796       1.00      1.00      1.00
797       1.00      1.00      1.00
798       1.00      1.00      2.00
799       1.00      1.00      3.00
800       1.00      1.00      1.00
801       2.00      1.00      3.00
802       1.00      1.00      3.00
803       1.00      1.00      3.00
804       1.00      1.00      1.00
805       1.00      1.00      3.00
806       1.00      1.00      2.00
807       1.00      1.00      2.00
808       1.00      1.00      3.00
809       1.00      1.00      1.00
810       2.00      1.00      1.00
811       2.00      1.00      3.00
812       1.00      1.00      2.00
813       1.00      1.00      1.00
814       1.00      1.00      3.00
815       1.00      1.00      1.00
816       2.00      1.00      3.00
817       1.00      1.00      2.00
818       1.00      1.00      3.00
819       1.00      1.00      3.00
820       1.00      1.00      1.00
821       1.00      1.00      1.00
822       2.00      1.00      1.00
823       1.00      1.00      2.00
824       1.00      1.00      2.00
825       1.00      1.00      2.00
826       1.00      1.00      1.00
827       1.00      1.00      3.00
828       1.00      1.00      2.00
829       1.00      1.00      2.00
830       1.00      1.00      3.00
831       1.00      1.00      1.00
832       1.00      1.00      2.00
833       1.00      1.00      1.00
834       1.00      1.00      2.00
835       1.00      1.00      2.00
836       1.00      1.00      1.00
837       1.00      1.00      3.00
838       2.00      1.00      2.00
839       1.00      1.00      2.00
840       1.00      1.00      2.00
841       2.00      1.00      2.00
842       1.00      1.00      1.00
843       1.00      1.00      3.00
844       1.00      1.00      2.00
845       1.00      1.00      2.00
846       1.00      1.00      2.00
847       2.00      1.00      3.00
848       1.00      1.00      2.00
849       2.00      1.00      2.00
850       1.00      1.00      1.00
851       1.00      1.00      1.00
852       1.00      1.00      1.00
853       1.00      1.00      3.00
854       1.00      1.00      2.00
855       1.00      1.00      2.00
856       1.00      1.00      2.00
857       1.00      1.00      2.00
858       1.00      1.00      2.00
859       1.00      1.00      2.00
860       1.00      1.00      2.00
861       1.00      1.00      3.00
862       1.00      1.00      1.00
863       1.00      1.00      2.00
864       2.00      1.00      3.00
865       1.00      1.00      1.00
866       1.00      1.00      2.00
867       1.00      1.00      1.00
868       1.00      1.00      2.00
869       1.00      1.00      1.00
870       2.00      1.00      2.00
871       1.00      1.00      1.00
872       1.00      1.00      1.00
873       1.00      1.00      2.00
874       1.00      1.00      3.00
875       1.00      1.00      3.00
876       1.00      1.00      1.00
877       1.00      1.00      1.00
878       1.00      1.00      2.00
879       1.00      1.00      2.00
880       1.00      1.00      3.00
881       1.00      1.00      1.00
882       1.00      1.00      2.00
883       2.00      1.00      2.00
884       1.00      1.00      3.00
885       1.00      1.00      2.00
886       1.00      1.00      3.00
887       1.00      1.00      1.00
888       1.00      1.00      2.00
889       1.00      1.00      2.00
890       2.00      1.00      3.00
891       1.00      1.00      1.00
892       1.00      1.00      1.00
893       2.00      1.00      3.00
894       2.00      1.00      2.00
895       1.00      1.00      3.00
896       2.00      1.00      2.00
897       2.00      1.00      2.00
898       1.00      1.00      2.00
899       2.00      1.00      2.00
900       1.00      1.00      2.00
901       1.00      1.00      3.00
902 end data.
903
904 VARIABLE LABEL schtyp 'type of school'.
905 ADD VALUE LABELS female 0 male 1 female.
906 ADD VALUE LABELS ses 1 low 2 middle 3 high.
907 ADD VALUE LABELS schtyp 1 public 2 private.
908
909 crosstabs /tables = schtyp by female /statistic = chisq.
910 crosstabs /tables = female by ses  /statistic = chisq.
911 ])
912
913 AT_CHECK([pspp -o pspp.csv -o pspp.txt fisher-exact.sps])
914 AT_CHECK([cat pspp.csv], [0], [Table: Summary
915 ,Cases,,,,,
916 ,Valid,,Missing,,Total,
917 ,N,Percent,N,Percent,N,Percent
918 type of school × female,200,100.0%,0,.0%,200,100.0%
919
920 Table: type of school × female
921 ,,,female,,Total
922 ,,,male,female,
923 type of school,public,Count,77,91,168
924 ,private,Count,14,18,32
925 Total,,Count,91,109,200
926
927 Table: Chi-Square Tests
928 ,Value,df,Asymptotic Sig. (2-tailed),Exact Sig. (2-tailed),Exact Sig. (1-tailed)
929 Pearson Chi-Square,.047,1,.828,,
930 Likelihood Ratio,.047,1,.828,,
931 Fisher's Exact Test,,,,.849,.492
932 Continuity Correction,.001,1,.981,,
933 Linear-by-Linear Association,.047,1,.829,,
934 N of Valid Cases,200,,,,
935
936 Table: Summary
937 ,Cases,,,,,
938 ,Valid,,Missing,,Total,
939 ,N,Percent,N,Percent,N,Percent
940 female × ses,200,100.0%,0,.0%,200,100.0%
941
942 Table: female × ses
943 ,,,ses,,,Total
944 ,,,low,middle,high,
945 female,male,Count,15,47,29,91
946 ,female,Count,32,48,29,109
947 Total,,Count,47,95,58,200
948
949 Table: Chi-Square Tests
950 ,Value,df,Asymptotic Sig. (2-tailed)
951 Pearson Chi-Square,4.577,2,.101
952 Likelihood Ratio,4.679,2,.096
953 Linear-by-Linear Association,3.110,1,.078
954 N of Valid Cases,200,,
955 ])
956
957 AT_CLEANUP
958
959 AT_SETUP([CROSSTABS Pearson's R - 1])
960 AT_DATA([pearson.sps], [dnl
961 SET FORMAT F8.3.
962
963 * From http://www.statisticslectures.com/topics/pearsonr/.
964 DATA LIST FREE/x y.
965 BEGIN DATA.
966 1 4
967 3 6
968 5 10
969 5 12
970 6 13
971 END DATA.
972 CROSSTABS x BY y/STATISTICS=CORR.
973 ])
974 AT_CHECK([pspp -o pspp.csv -o pspp.txt pearson.sps])
975 AT_CHECK([cat pspp.csv], [0], [dnl
976 Table: Summary
977 ,Cases,,,,,
978 ,Valid,,Missing,,Total,
979 ,N,Percent,N,Percent,N,Percent
980 x × y,5,100.0%,0,.0%,5,100.0%
981
982 Table: x × y
983 ,,,y,,,,,Total
984 ,,,4.000,6.000,10.000,12.000,13.000,
985 x,1.000,Count,1,0,0,0,0,1
986 ,3.000,Count,0,1,0,0,0,1
987 ,5.000,Count,0,0,1,1,0,2
988 ,6.000,Count,0,0,0,0,1,1
989 Total,,Count,1,1,1,1,1,5
990
991 Table: Symmetric Measures
992 ,,Value,Asymp. Std. Error,Approx. T
993 Ordinal by Ordinal,Spearman Correlation,.975,.022,7.550
994 Interval by Interval,Pearson's R,.968,.017,6.708
995 N of Valid Cases,,5,,
996 ])
997 AT_CLEANUP
998
999 AT_SETUP([CROSSTABS Pearson's R - 2])
1000 AT_DATA([pearson2.sps], [dnl
1001 SET FORMAT F8.3.
1002
1003 * Checked with http://www.socscistatistics.com/tests/pearson/Default2.aspx.
1004 DATA LIST FREE/x y.
1005 BEGIN DATA.
1006 1 1.5
1007 2 1.5
1008 3 4
1009 4 6
1010 5 5
1011 6 7
1012 7 6.5
1013 8 9
1014 9 10.5
1015 10 11
1016 END DATA.
1017 CROSSTABS x BY y/STATISTICS=CORR.
1018 ])
1019 AT_CHECK([pspp -o pspp.csv -o pspp.txt pearson2.sps])
1020 AT_CHECK([cat pspp.csv], [0], [dnl
1021 Table: Summary
1022 ,Cases,,,,,
1023 ,Valid,,Missing,,Total,
1024 ,N,Percent,N,Percent,N,Percent
1025 x × y,10,100.0%,0,.0%,10,100.0%
1026
1027 Table: x × y
1028 ,,,y,,,,,,,,,Total
1029 ,,,1.500,4.000,5.000,6.000,6.500,7.000,9.000,10.500,11.000,
1030 x,1.000,Count,1,0,0,0,0,0,0,0,0,1
1031 ,2.000,Count,1,0,0,0,0,0,0,0,0,1
1032 ,3.000,Count,0,1,0,0,0,0,0,0,0,1
1033 ,4.000,Count,0,0,0,1,0,0,0,0,0,1
1034 ,5.000,Count,0,0,1,0,0,0,0,0,0,1
1035 ,6.000,Count,0,0,0,0,0,1,0,0,0,1
1036 ,7.000,Count,0,0,0,0,1,0,0,0,0,1
1037 ,8.000,Count,0,0,0,0,0,0,1,0,0,1
1038 ,9.000,Count,0,0,0,0,0,0,0,1,0,1
1039 ,10.000,Count,0,0,0,0,0,0,0,0,1,1
1040 Total,,Count,2,1,1,1,1,1,1,1,1,10
1041
1042 Table: Symmetric Measures
1043 ,,Value,Asymp. Std. Error,Approx. T
1044 Ordinal by Ordinal,Spearman Correlation,.973,.015,11.844
1045 Interval by Interval,Pearson's R,.971,.017,11.580
1046 N of Valid Cases,,10,,
1047 ])
1048 AT_CLEANUP
1049
1050 AT_SETUP([CROSSTABS Pearson's R - 3])
1051 AT_DATA([pearson3.sps], [dnl
1052 SET FORMAT F8.3.
1053
1054 * From http://learntech.uwe.ac.uk/da/Default.aspx?pageid=1442.
1055 DATA LIST FREE/x y.
1056 BEGIN DATA.
1057 56 87
1058 56 91
1059 65 85
1060 65 91
1061 50 75
1062 25 28
1063 87 122
1064 44 66
1065 35 58
1066 END DATA.
1067 CROSSTABS x BY y/STATISTICS=CORR.
1068 ])
1069 AT_CHECK([pspp -o pspp.csv -o pspp.txt pearson3.sps])
1070 AT_CHECK([cat pspp.csv], [0], [dnl
1071 Table: Summary
1072 ,Cases,,,,,
1073 ,Valid,,Missing,,Total,
1074 ,N,Percent,N,Percent,N,Percent
1075 x × y,9,100.0%,0,.0%,9,100.0%
1076
1077 Table: x × y
1078 ,,,y,,,,,,,,Total
1079 ,,,28.000,58.000,66.000,75.000,85.000,87.000,91.000,122.000,
1080 x,25.000,Count,1,0,0,0,0,0,0,0,1
1081 ,35.000,Count,0,1,0,0,0,0,0,0,1
1082 ,44.000,Count,0,0,1,0,0,0,0,0,1
1083 ,50.000,Count,0,0,0,1,0,0,0,0,1
1084 ,56.000,Count,0,0,0,0,0,1,1,0,2
1085 ,65.000,Count,0,0,0,0,1,0,1,0,2
1086 ,87.000,Count,0,0,0,0,0,0,0,1,1
1087 Total,,Count,1,1,1,1,1,1,2,1,9
1088
1089 Table: Symmetric Measures
1090 ,,Value,Asymp. Std. Error,Approx. T
1091 Ordinal by Ordinal,Spearman Correlation,.911,.068,5.860
1092 Interval by Interval,Pearson's R,.966,.017,9.915
1093 N of Valid Cases,,9,,
1094 ])
1095 AT_CLEANUP
1096
1097 AT_SETUP([CROSSTABS Pearson's R - 4])
1098 AT_DATA([pearson4.sps], [dnl
1099 SET FORMAT F8.3.
1100
1101 * From http://psychology.ucdavis.edu/faculty_sites/sommerb/sommerdemo/correlation/hand/pearson_hand.htm.
1102 DATA LIST FREE/x y.
1103 BEGIN DATA.
1104 5 5
1105 10 20
1106 6 4
1107 8 15
1108 4 11
1109 4 9
1110 3 12
1111 10 18
1112 2 7
1113 6 2
1114 7 14
1115 9 17
1116 END DATA.
1117 CROSSTABS x BY y/STATISTICS=CORR.
1118 ])
1119 AT_CHECK([pspp -o pspp.csv -o pspp.txt pearson4.sps])
1120 AT_CHECK([cat pspp.csv], [0], [dnl
1121 Table: Summary
1122 ,Cases,,,,,
1123 ,Valid,,Missing,,Total,
1124 ,N,Percent,N,Percent,N,Percent
1125 x × y,12,100.0%,0,.0%,12,100.0%
1126
1127 Table: x × y
1128 ,,,y,,,,,,,,,,,,Total
1129 ,,,2.000,4.000,5.000,7.000,9.000,11.000,12.000,14.000,15.000,17.000,18.000,20.000,
1130 x,2.000,Count,0,0,0,1,0,0,0,0,0,0,0,0,1
1131 ,3.000,Count,0,0,0,0,0,0,1,0,0,0,0,0,1
1132 ,4.000,Count,0,0,0,0,1,1,0,0,0,0,0,0,2
1133 ,5.000,Count,0,0,1,0,0,0,0,0,0,0,0,0,1
1134 ,6.000,Count,1,1,0,0,0,0,0,0,0,0,0,0,2
1135 ,7.000,Count,0,0,0,0,0,0,0,1,0,0,0,0,1
1136 ,8.000,Count,0,0,0,0,0,0,0,0,1,0,0,0,1
1137 ,9.000,Count,0,0,0,0,0,0,0,0,0,1,0,0,1
1138 ,10.000,Count,0,0,0,0,0,0,0,0,0,0,1,1,2
1139 Total,,Count,1,1,1,1,1,1,1,1,1,1,1,1,12
1140
1141 Table: Symmetric Measures
1142 ,,Value,Asymp. Std. Error,Approx. T
1143 Ordinal by Ordinal,Spearman Correlation,.657,.140,2.758
1144 Interval by Interval,Pearson's R,.667,.132,2.830
1145 N of Valid Cases,,12,,
1146 ])
1147 AT_CLEANUP
1148
1149 AT_SETUP([CROSSTABS Pearson's R - 5])
1150 AT_DATA([pearson5.sps], [dnl
1151 SET FORMAT F8.3.
1152
1153 * From http://www.statisticslectures.com/topics/pearsonr/.
1154 DATA LIST FREE/x y.
1155 BEGIN DATA.
1156 18 15000
1157 25 29000
1158 57 68000
1159 45 52000
1160 26 32000
1161 64 80000
1162 37 41000
1163 40 45000
1164 24 26000
1165 33 33000
1166 END DATA.
1167 CROSSTABS x BY y/STATISTICS=CORR.
1168 ])
1169 AT_CHECK([pspp -o pspp.csv -o pspp.txt pearson5.sps])
1170 AT_CHECK([cat pspp.csv], [0], [dnl
1171 Table: Summary
1172 ,Cases,,,,,
1173 ,Valid,,Missing,,Total,
1174 ,N,Percent,N,Percent,N,Percent
1175 x × y,10,100.0%,0,.0%,10,100.0%
1176
1177 Table: x × y
1178 ,,,y,,,,,,,,,,Total
1179 ,,,15000.00,26000.00,29000.00,32000.00,33000.00,41000.00,45000.00,52000.00,68000.00,80000.00,
1180 x,18.000,Count,1,0,0,0,0,0,0,0,0,0,1
1181 ,24.000,Count,0,1,0,0,0,0,0,0,0,0,1
1182 ,25.000,Count,0,0,1,0,0,0,0,0,0,0,1
1183 ,26.000,Count,0,0,0,1,0,0,0,0,0,0,1
1184 ,33.000,Count,0,0,0,0,1,0,0,0,0,0,1
1185 ,37.000,Count,0,0,0,0,0,1,0,0,0,0,1
1186 ,40.000,Count,0,0,0,0,0,0,1,0,0,0,1
1187 ,45.000,Count,0,0,0,0,0,0,0,1,0,0,1
1188 ,57.000,Count,0,0,0,0,0,0,0,0,1,0,1
1189 ,64.000,Count,0,0,0,0,0,0,0,0,0,1,1
1190 Total,,Count,1,1,1,1,1,1,1,1,1,1,10
1191
1192 Table: Symmetric Measures
1193 ,,Value,Asymp. Std. Error,Approx. T
1194 Ordinal by Ordinal,Spearman Correlation,1.000,.000,+Infinit
1195 Interval by Interval,Pearson's R,.992,.004,22.638
1196 N of Valid Cases,,10,,
1197 ])
1198 AT_CLEANUP
1199
1200 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda - 1])
1201 AT_DATA([lambda.sps], [dnl
1202 SET FORMAT F8.3.
1203
1204 * From http://www.csupomona.edu/~jlkorey/POWERMUTT/Topics/contingency_tables.html.
1205 DATA LIST LIST NOTABLE/x y w.
1206 WEIGHT BY w.
1207 BEGIN DATA.
1208 1 1 424
1209 1 2 213
1210 1 3 59
1211 3 1 55
1212 3 2 188
1213 3 3 357
1214 END DATA.
1215
1216 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1217 ])
1218 AT_CHECK([pspp -o pspp.csv -o pspp.txt lambda.sps])
1219 AT_CHECK([cat pspp.csv], [0], [dnl
1220 Table: Summary
1221 ,Cases,,,,,
1222 ,Valid,,Missing,,Total,
1223 ,N,Percent,N,Percent,N,Percent
1224 x × y,1296.000,100.0%,.000,.0%,1296.000,100.0%
1225
1226 Table: Directional Measures
1227 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1228 Nominal by Nominal,Lambda,Symmetric,.423,.021,16.875,.000
1229 ,,x Dependent,.497,.024,15.986,.000
1230 ,,y Dependent,.370,.020,16.339,.000
1231 ,Goodman and Kruskal tau,x Dependent,.382,,,
1232 ,,y Dependent,.198,,,
1233 ])
1234 AT_CLEANUP
1235
1236 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda - 2])
1237 AT_DATA([lambda.sps], [dnl
1238 SET FORMAT F8.3.
1239
1240 * From http://vassarstats.net.
1241 DATA LIST LIST NOTABLE/x y w.
1242 WEIGHT BY w.
1243 BEGIN DATA.
1244 1 1 19
1245 1 2 26
1246 1 3 8
1247 2 1 21
1248 2 2 13
1249 2 3 5
1250 3 1 6
1251 3 2 12
1252 3 3 27
1253 END DATA.
1254
1255 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1256 ])
1257 AT_CHECK([pspp -o pspp.csv -o pspp.txt lambda.sps])
1258 AT_CHECK([cat pspp.csv], [0], [dnl
1259 Table: Summary
1260 ,Cases,,,,,
1261 ,Valid,,Missing,,Total,
1262 ,N,Percent,N,Percent,N,Percent
1263 x × y,137.000,100.0%,.000,.0%,137.000,100.0%
1264
1265 Table: Directional Measures
1266 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1267 Nominal by Nominal,Lambda,Symmetric,.259,.081,2.902,.004
1268 ,,x Dependent,.250,.089,2.479,.013
1269 ,,y Dependent,.267,.085,2.766,.006
1270 ,Goodman and Kruskal tau,x Dependent,.129,,,
1271 ,,y Dependent,.123,,,
1272 ])
1273 AT_CLEANUP
1274
1275 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda - 3])
1276 AT_DATA([lambda.sps], [dnl
1277 SET FORMAT F8.3.
1278
1279 * From Goodman, L.A., Kruskal, W.H. (1954) "Measures of association for
1280   cross classifications". Part I. Journal of the American Statistical
1281   Association, 49, 732-764.
1282 DATA LIST LIST NOTABLE/x y w.
1283 WEIGHT BY w.
1284 BEGIN DATA.
1285 1 1 1768
1286 1 2 807
1287 1 3 189
1288 1 4 47
1289 2 1 946
1290 2 2 1387
1291 2 3 746
1292 2 4 53
1293 3 1 115
1294 3 2 438
1295 3 3 288
1296 3 4 16
1297 END DATA.
1298 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1299 ])
1300 AT_CHECK([pspp -o pspp.csv -o pspp.txt lambda.sps])
1301 AT_CHECK([cat pspp.csv], [0], [dnl
1302 Table: Summary
1303 ,Cases,,,,,
1304 ,Valid,,Missing,,Total,
1305 ,N,Percent,N,Percent,N,Percent
1306 x × y,6800.000,100.0%,.000,.0%,6800.000,100.0%
1307
1308 Table: Directional Measures
1309 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1310 Nominal by Nominal,Lambda,Symmetric,.208,.010,18.793,.000
1311 ,,x Dependent,.224,.013,16.076,.000
1312 ,,y Dependent,.192,.012,14.438,.000
1313 ,Goodman and Kruskal tau,x Dependent,.089,,,
1314 ,,y Dependent,.081,,,
1315 ])
1316 AT_CLEANUP
1317
1318 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda - treatment of ties])
1319 AT_DATA([lambda.sps], [dnl
1320 SET FORMAT F8.3.
1321
1322 * From Douglas Bonett.
1323 DATA LIST LIST NOTABLE/x y w.
1324 WEIGHT BY w.
1325 BEGIN DATA.
1326 1 1 225
1327 1 2 43
1328 1 3 216
1329 2 1 3
1330 2 2 1
1331 2 3 12
1332 END DATA.
1333
1334 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1335 ])
1336 AT_CHECK([pspp -o pspp.csv -o pspp.txt lambda.sps])
1337 AT_CHECK([cat pspp.csv], [0], [dnl
1338 Table: Summary
1339 ,Cases,,,,,
1340 ,Valid,,Missing,,Total,
1341 ,N,Percent,N,Percent,N,Percent
1342 x × y,500.000,100.0%,.000,.0%,500.000,100.0%
1343
1344 Table: Directional Measures
1345 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1346 Nominal by Nominal,Lambda,Symmetric,.031,.013,2.336,.019
1347 ,,x Dependent,.000,.000,NaN,NaN
1348 ,,y Dependent,.033,.014,2.336,.019
1349 ,Goodman and Kruskal tau,x Dependent,.012,,,
1350 ,,y Dependent,.009,,,
1351 ])
1352 AT_CLEANUP
1353
1354 AT_SETUP([CROSSTABS Somers' D, Tau-B, Tau-C, Gamma - 1])
1355 AT_DATA([somersd.sps], [dnl
1356 SET FORMAT F8.3.
1357
1358 * From http://stats.stackexchange.com/questions/72203/problem-with-calculating-asymptotic-standard-error-for-somers-d.
1359 DATA LIST LIST NOTABLE/x y * w (F10.6).
1360 WEIGHT BY w.
1361 BEGIN DATA.
1362 1 1 0.000025
1363 1 2 0.0001
1364 1 3 0.001
1365 1 4 0.0025
1366 1 5 0.004
1367 1 6 0.0075
1368 1 7 0.0125
1369 2 1 0.049975
1370 2 2 0.0999
1371 2 3 0.199
1372 2 4 0.2475
1373 2 5 0.196
1374 2 6 0.1425
1375 2 7 0.0375
1376 END DATA.
1377 CROSSTABS x BY y/STATISTICS=D/CELLS=NONE.
1378 ])
1379 AT_CHECK([pspp -o pspp.csv -o pspp.txt somersd.sps])
1380 AT_CHECK([cat pspp.csv], [0], [dnl
1381 Table: Summary
1382 ,Cases,,,,,
1383 ,Valid,,Missing,,Total,
1384 ,N,Percent,N,Percent,N,Percent
1385 x × y,1.000000,100.0%,.000000,.0%,1.000000,100.0%
1386
1387 Table: Directional Measures
1388 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1389 Ordinal by Ordinal,Somers' d,Symmetric,-.084,,-.149,.882
1390 ,,x Dependent,-.045,.300,-.149,.882
1391 ,,y Dependent,-.684,2.378,-.149,.882
1392 ])
1393 AT_CLEANUP
1394
1395 AT_SETUP([CROSSTABS Somers' D, Tau-B, Tau-C, Gamma - 2])
1396 AT_DATA([somersd.sps], [dnl
1397 SET FORMAT F8.3.
1398
1399 * From http://uregina.ca/~gingrich/gamma.pdf.
1400 DATA LIST LIST NOTABLE/x y w.
1401 WEIGHT BY w.
1402 BEGIN DATA.
1403 1 1 34
1404 1 2 24
1405 1 3 15
1406 2 1 42
1407 2 2 74
1408 2 3 67
1409 3 1 28
1410 3 2 111
1411 3 3 292
1412 END DATA.
1413 CROSSTABS x BY y/STATISTICS=BTAU CTAU GAMMA D/CELLS=NONE.
1414 ])
1415 AT_CHECK([pspp -o pspp.csv -o pspp.txt somersd.sps])
1416 AT_CHECK([cat pspp.csv], [0], [dnl
1417 Table: Summary
1418 ,Cases,,,,,
1419 ,Valid,,Missing,,Total,
1420 ,N,Percent,N,Percent,N,Percent
1421 x × y,687.000,100.0%,.000,.0%,687.000,100.0%
1422
1423 Table: Symmetric Measures
1424 ,,Value,Asymp. Std. Error,Approx. T
1425 Ordinal by Ordinal,Kendall's tau-b,.372,.033,10.669
1426 ,Kendall's tau-c,.310,.029,10.669
1427 ,Gamma,.591,.043,10.669
1428 N of Valid Cases,,687.000,,
1429
1430 Table: Directional Measures
1431 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1432 Ordinal by Ordinal,Somers' d,Symmetric,.371,,10.669,.000
1433 ,,x Dependent,.351,.032,10.669,.000
1434 ,,y Dependent,.394,.035,10.669,.000
1435 ])
1436 AT_CLEANUP
1437
1438 AT_SETUP([CROSSTABS Somers' D, Tau-B, Tau-C, Gamma - 3])
1439 AT_DATA([ordinal.sps], [dnl
1440 SET FORMAT F8.3.
1441
1442 * From https://www.iup.edu/WorkArea/DownloadAsset.aspx?id=9829, "Case 1".
1443 DATA LIST LIST NOTABLE /x y w.
1444 WEIGHT BY w.
1445 BEGIN DATA.
1446 1 2 40
1447 2 3 80
1448 3 4 30
1449 END DATA.
1450 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1451
1452 * Same site, case 2.
1453 DATA LIST LIST NOTABLE /x y w.
1454 WEIGHT BY w.
1455 BEGIN DATA.
1456 1 1 40
1457 2 3 80
1458 3 4 30
1459 END DATA.
1460 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1461
1462 * Same site, case 3.
1463 DATA LIST LIST NOTABLE /x y w.
1464 WEIGHT BY w.
1465 BEGIN DATA.
1466 1 4 40
1467 2 3 80
1468 3 2 30
1469 END DATA.
1470 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1471
1472 * Same site, case 4.
1473 DATA LIST LIST NOTABLE /x y w.
1474 WEIGHT BY w.
1475 BEGIN DATA.
1476 1 1 20
1477 1 2 20
1478 2 3 80
1479 3 4 30
1480 END DATA.
1481 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1482
1483 * Same site, case 5.
1484 DATA LIST LIST NOTABLE /x y w.
1485 WEIGHT BY w.
1486 BEGIN DATA.
1487 1 2 40
1488 2 2 80
1489 3 2 29
1490 3 3 1
1491 END DATA.
1492 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1493
1494 * Same site, case 6.
1495 DATA LIST LIST NOTABLE /x y w.
1496 WEIGHT BY w.
1497 BEGIN DATA.
1498 1 1 3
1499 1 2 6
1500 1 3 28
1501 1 4 61
1502 2 1 4
1503 2 2 5
1504 2 3 21
1505 2 4 20
1506 END DATA.
1507 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1508
1509 * Same site, case 7.
1510 DATA LIST LIST NOTABLE /x y w.
1511 WEIGHT BY w.
1512 BEGIN DATA.
1513 1 1 38
1514 1 2 6
1515 1 3 3
1516 1 4 51
1517 2 1 4
1518 2 2 20
1519 2 3 21
1520 2 4 5
1521 END DATA.
1522 CROSSTABS x BY y/STATISTICS=LAMBDA D PHI GAMMA/CELLS=NONE.
1523
1524 * Same site, case 8.
1525 DATA LIST LIST NOTABLE /x y w.
1526 WEIGHT BY w.
1527 BEGIN DATA.
1528 1 1 2
1529 1 2 3
1530 1 3 5
1531 1 4 1
1532 2 1 2
1533 2 2 16
1534 2 3 3
1535 2 4 6
1536 3 1 3
1537 3 2 10
1538 3 3 35
1539 3 4 27
1540 4 1 6
1541 4 2 15
1542 4 3 33
1543 4 4 45
1544 END DATA.
1545 CROSSTABS x BY y/STATISTICS=LAMBDA D PHI BTAU/CELLS=NONE.
1546 ])
1547 AT_CHECK([pspp -o pspp.csv -o pspp.txt ordinal.sps])
1548 AT_CHECK([cat pspp.csv], [0], [dnl
1549 Table: Summary
1550 ,Cases,,,,,
1551 ,Valid,,Missing,,Total,
1552 ,N,Percent,N,Percent,N,Percent
1553 x × y,150.000,100.0%,.000,.0%,150.000,100.0%
1554
1555 Table: Symmetric Measures
1556 ,,Value,Asymp. Std. Error,Approx. T
1557 Ordinal by Ordinal,Kendall's tau-b,1.000,.000,24.841
1558 ,Gamma,1.000,.000,24.841
1559 N of Valid Cases,,150.000,,
1560
1561 Table: Directional Measures
1562 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1563 Ordinal by Ordinal,Somers' d,Symmetric,1.000,,24.841,.000
1564 ,,x Dependent,1.000,.000,24.841,.000
1565 ,,y Dependent,1.000,.000,24.841,.000
1566
1567 Table: Summary
1568 ,Cases,,,,,
1569 ,Valid,,Missing,,Total,
1570 ,N,Percent,N,Percent,N,Percent
1571 x × y,150.000,100.0%,.000,.0%,150.000,100.0%
1572
1573 Table: Symmetric Measures
1574 ,,Value,Asymp. Std. Error,Approx. T
1575 Ordinal by Ordinal,Kendall's tau-b,1.000,.000,24.841
1576 ,Gamma,1.000,.000,24.841
1577 N of Valid Cases,,150.000,,
1578
1579 Table: Directional Measures
1580 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1581 Ordinal by Ordinal,Somers' d,Symmetric,1.000,,24.841,.000
1582 ,,x Dependent,1.000,.000,24.841,.000
1583 ,,y Dependent,1.000,.000,24.841,.000
1584
1585 Table: Summary
1586 ,Cases,,,,,
1587 ,Valid,,Missing,,Total,
1588 ,N,Percent,N,Percent,N,Percent
1589 x × y,150.000,100.0%,.000,.0%,150.000,100.0%
1590
1591 Table: Symmetric Measures
1592 ,,Value,Asymp. Std. Error,Approx. T
1593 Ordinal by Ordinal,Kendall's tau-b,-1.000,.000,-24.841
1594 ,Gamma,-1.000,.000,-24.841
1595 N of Valid Cases,,150.000,,
1596
1597 Table: Directional Measures
1598 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1599 Ordinal by Ordinal,Somers' d,Symmetric,-1.000,,-24.841,.000
1600 ,,x Dependent,-1.000,.000,-24.841,.000
1601 ,,y Dependent,-1.000,.000,-24.841,.000
1602
1603 Table: Summary
1604 ,Cases,,,,,
1605 ,Valid,,Missing,,Total,
1606 ,N,Percent,N,Percent,N,Percent
1607 x × y,150.000,100.0%,.000,.0%,150.000,100.0%
1608
1609 Table: Symmetric Measures
1610 ,,Value,Asymp. Std. Error,Approx. T
1611 Ordinal by Ordinal,Kendall's tau-b,.972,.007,24.841
1612 ,Gamma,1.000,.000,24.841
1613 N of Valid Cases,,150.000,,
1614
1615 Table: Directional Measures
1616 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1617 Ordinal by Ordinal,Somers' d,Symmetric,.971,,24.841,.000
1618 ,,x Dependent,.944,.013,24.841,.000
1619 ,,y Dependent,1.000,.000,24.841,.000
1620
1621 Table: Summary
1622 ,Cases,,,,,
1623 ,Valid,,Missing,,Total,
1624 ,N,Percent,N,Percent,N,Percent
1625 x × y,150.000,100.0%,.000,.0%,150.000,100.0%
1626
1627 Table: Symmetric Measures
1628 ,,Value,Asymp. Std. Error,Approx. T
1629 Ordinal by Ordinal,Kendall's tau-b,.119,.059,1.009
1630 ,Gamma,1.000,.000,1.009
1631 N of Valid Cases,,150.000,,
1632
1633 Table: Directional Measures
1634 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1635 Ordinal by Ordinal,Somers' d,Symmetric,.035,,1.009,.313
1636 ,,x Dependent,.805,.032,1.009,.313
1637 ,,y Dependent,.018,.017,1.009,.313
1638
1639 Table: Summary
1640 ,Cases,,,,,
1641 ,Valid,,Missing,,Total,
1642 ,N,Percent,N,Percent,N,Percent
1643 x × y,148.000,100.0%,.000,.0%,148.000,100.0%
1644
1645 Table: Symmetric Measures
1646 ,,Value,Asymp. Std. Error,Approx. T
1647 Ordinal by Ordinal,Kendall's tau-b,-.208,.078,-2.641
1648 ,Gamma,-.381,.130,-2.641
1649 N of Valid Cases,,148.000,,
1650
1651 Table: Directional Measures
1652 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1653 Ordinal by Ordinal,Somers' d,Symmetric,-.206,,-2.641,.008
1654 ,,x Dependent,-.182,.069,-2.641,.008
1655 ,,y Dependent,-.237,.089,-2.641,.008
1656
1657 Table: Summary
1658 ,Cases,,,,,
1659 ,Valid,,Missing,,Total,
1660 ,N,Percent,N,Percent,N,Percent
1661 x × y,148.000,100.0%,.000,.0%,148.000,100.0%
1662
1663 Table: Symmetric Measures
1664 ,,Value,Asymp. Std. Error,Approx. T
1665 Nominal by Nominal,Phi,.731,,
1666 ,Cramer's V,.731,,
1667 Ordinal by Ordinal,Gamma,-.110,.107,-1.022
1668 N of Valid Cases,,148.000,,
1669
1670 Table: Directional Measures
1671 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1672 Nominal by Nominal,Lambda,Symmetric,.338,.059,4.743,.000
1673 ,,x Dependent,.640,.085,4.875,.000
1674 ,,y Dependent,.174,.050,3.248,.001
1675 ,Goodman and Kruskal tau,x Dependent,.534,,,
1676 ,,y Dependent,.167,,,
1677 Ordinal by Ordinal,Somers' d,Symmetric,-.074,,-1.022,.307
1678 ,,x Dependent,-.060,.059,-1.022,.307
1679 ,,y Dependent,-.096,.094,-1.022,.307
1680
1681 Table: Summary
1682 ,Cases,,,,,
1683 ,Valid,,Missing,,Total,
1684 ,N,Percent,N,Percent,N,Percent
1685 x × y,212.000,100.0%,.000,.0%,212.000,100.0%
1686
1687 Table: Symmetric Measures
1688 ,,Value,Asymp. Std. Error,Approx. T
1689 Nominal by Nominal,Phi,.432,,
1690 ,Cramer's V,.249,,
1691 Ordinal by Ordinal,Kendall's tau-b,.209,.062,3.338
1692 N of Valid Cases,,212.000,,
1693
1694 Table: Directional Measures
1695 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1696 Nominal by Nominal,Lambda,Symmetric,.102,.067,1.473,.141
1697 ,,x Dependent,.027,.087,.302,.763
1698 ,,y Dependent,.165,.065,2.349,.019
1699 ,Goodman and Kruskal tau,x Dependent,.051,,,
1700 ,,y Dependent,.068,,,
1701 Ordinal by Ordinal,Somers' d,Symmetric,.209,,3.338,.001
1702 ,,x Dependent,.202,.060,3.338,.001
1703 ,,y Dependent,.217,.064,3.338,.001
1704 ])
1705 AT_CLEANUP
1706
1707 AT_SETUP([CROSSTABS Cohens Kappa])
1708
1709 dnl Example from Wood J. M.
1710 dnl "Understanding and Computing Cohen's Kappa: A Tutorial"
1711 dnl WebPsychEmpiricist. Oct 3 2007
1712 AT_DATA([kappa.sps], [dnl
1713 SET FORMAT=F8.3.
1714
1715 data list notable list /p1 * p2 * w *.
1716 begin data.
1717 0 0 18
1718 1 0 1
1719 0 1 1
1720 end data.
1721
1722 weight by w.
1723
1724 crosstabs /table = p1 by p2
1725         /statistics = kappa
1726         .
1727 ])
1728
1729 AT_CHECK([pspp -o pspp.csv -o pspp.txt kappa.sps])
1730 AT_CHECK([cat pspp.csv], [0], [dnl
1731 Table: Summary
1732 ,Cases,,,,,
1733 ,Valid,,Missing,,Total,
1734 ,N,Percent,N,Percent,N,Percent
1735 p1 × p2,20.000,100.0%,.000,.0%,20.000,100.0%
1736
1737 Table: p1 × p2
1738 ,,,p2,,Total
1739 ,,,.000,1.000,
1740 p1,.000,Count,18.000,1.000,19.000
1741 ,1.000,Count,1.000,.000,1.000
1742 Total,,Count,19.000,1.000,20.000
1743
1744 Table: Symmetric Measures
1745 ,,Value,Asymp. Std. Error,Approx. T
1746 Measure of Agreement,Kappa,-.053,.037,-.235
1747 N of Valid Cases,,20.000,,
1748 ])
1749
1750 AT_CLEANUP
1751
1752
1753 AT_SETUP([CROSSTABS many statistics])
1754 AT_DATA([crosstabs.sps], [dnl
1755 SET FORMAT=F8.4.
1756
1757 * From http://www4.stat.ncsu.edu/~dzhang2/st744/table3.9.lst.txt.
1758 DATA LIST LIST NOTABLE/x y w.
1759 WEIGHT BY w.
1760 BEGIN DATA.
1761 1 1 25
1762 1 2 25
1763 1 3 12
1764 2 2 1
1765 2 3 3
1766 END DATA.
1767 CROSSTABS x BY y/STATISTICS=CHISQ PHI CC LAMBDA UC BTAU CTAU GAMMA D CORR/CELLS=NONE.
1768 ])
1769 AT_CHECK([pspp -o pspp.csv -o pspp.txt crosstabs.sps])
1770 AT_CHECK([cat pspp.csv], [0], [dnl
1771 Table: Summary
1772 ,Cases,,,,,
1773 ,Valid,,Missing,,Total,
1774 ,N,Percent,N,Percent,N,Percent
1775 x × y,66.0000,100.0%,.0000,.0%,66.0000,100.0%
1776
1777 Table: Chi-Square Tests
1778 ,Value,df,Asymptotic Sig. (2-tailed)
1779 Pearson Chi-Square,6.9562,2.0000,.031
1780 Likelihood Ratio,6.6901,2.0000,.035
1781 Linear-by-Linear Association,5.8450,1.0000,.016
1782 N of Valid Cases,66.0000,,
1783
1784 Table: Symmetric Measures
1785 ,,Value,Asymp. Std. Error,Approx. T
1786 Nominal by Nominal,Phi,.3246,,
1787 ,Cramer's V,.3246,,
1788 ,Contingency Coefficient,.3088,,
1789 Ordinal by Ordinal,Kendall's tau-b,.2752,.0856,1.9920
1790 ,Kendall's tau-c,.1497,.0751,1.9920
1791 ,Gamma,.8717,.1250,1.9920
1792 ,Spearman Correlation,.2908,.0906,2.4311
1793 Interval by Interval,Pearson's R,.2999,.0973,2.5147
1794 N of Valid Cases,,66.0000,,
1795
1796 Table: Directional Measures
1797 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1798 Nominal by Nominal,Lambda,Symmetric,.0455,.1629,.2723,.785
1799 ,,x Dependent,.0000,.0000,NaN,NaN
1800 ,,y Dependent,.0500,.1791,.2723,.785
1801 ,Goodman and Kruskal tau,x Dependent,.1054,,,
1802 ,,y Dependent,.0434,,,
1803 ,Uncertainty Coefficient,Symmetric,.0780,.0474,,
1804 ,,x Dependent,.2217,.1062,1.5373,
1805 ,,y Dependent,.0473,.0306,1.5373,
1806 Ordinal by Ordinal,Somers' d,Symmetric,.1960,,1.9920,.046
1807 ,,x Dependent,.1152,.0572,1.9920,.046
1808 ,,y Dependent,.6573,.1417,1.9920,.046
1809 ])
1810 AT_CLEANUP
1811
1812 AT_SETUP([CROSSTABS uncertainy coefficient])
1813 AT_DATA([uc.sps], [dnl
1814 * From http://groups.chass.utoronto.ca/pol242/5bMeasuringAssociation.htm.
1815 SET FORMAT=F8.3.
1816
1817 DATA LIST LIST NOTABLE/x y w.
1818 WEIGHT BY w.
1819 BEGIN DATA.
1820 1 1 416
1821 1 2 121
1822 2 1 335
1823 2 2 2
1824 3 1 112
1825 3 2 1
1826 END DATA.
1827 CROSSTABS x BY y/STATISTICS=LAMBDA UC/CELLS=NONE.
1828 ])
1829 AT_CHECK([pspp -o pspp.csv -o pspp.txt uc.sps])
1830 AT_CHECK([cat pspp.csv], [0], [dnl
1831 Table: Summary
1832 ,Cases,,,,,
1833 ,Valid,,Missing,,Total,
1834 ,N,Percent,N,Percent,N,Percent
1835 x × y,987.000,100.0%,.000,.0%,987.000,100.0%
1836
1837 Table: Directional Measures
1838 ,,,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1839 Nominal by Nominal,Lambda,Symmetric,.000,.000,NaN,NaN
1840 ,,x Dependent,.000,.000,NaN,NaN
1841 ,,y Dependent,.000,.000,NaN,NaN
1842 ,Goodman and Kruskal tau,x Dependent,.076,,,
1843 ,,y Dependent,.108,,,
1844 ,Uncertainty Coefficient,Symmetric,.105,.012,,
1845 ,,x Dependent,.073,.009,7.890,
1846 ,,y Dependent,.184,.019,7.890,
1847 ])
1848 AT_CLEANUP
1849
1850 AT_SETUP([CROSSTABS estimated risk])
1851 dnl Example data and expected output from
1852 dnl http://www.psychology.nottingham.ac.uk/staff/ddc/c8cxpa/further/Project_resources/SPSSCrosstabW.pdf
1853 AT_DATA([risk.sps], [dnl
1854 DATA LIST LIST /factor disease count (F8.0).
1855 WEIGHT BY count.
1856 VALUE LABELS /factor 0 'Placebo' 1 'Aspirin'
1857              /disease 1 'No' 0 'Yes'.
1858 BEGIN DATA.
1859 0 1 80
1860 0 0 20
1861 1 1 135
1862 1 0 15
1863 END DATA.
1864 CROSSTABS factor BY disease/STATISTICS=RISK CHISQ.
1865 ])
1866 AT_CHECK([pspp -o pspp.csv -o pspp.txt risk.sps])
1867 AT_CHECK([cat pspp.csv], [0], [dnl
1868 Table: Reading free-form data from INLINE.
1869 Variable,Format
1870 factor,F8.0
1871 disease,F8.0
1872 count,F8.0
1873
1874 Table: Summary
1875 ,Cases,,,,,
1876 ,Valid,,Missing,,Total,
1877 ,N,Percent,N,Percent,N,Percent
1878 factor × disease,250,100.0%,0,.0%,250,100.0%
1879
1880 Table: factor × disease
1881 ,,,disease,,Total
1882 ,,,Yes,No,
1883 factor,Placebo,Count,20,80,100
1884 ,Aspirin,Count,15,135,150
1885 Total,,Count,35,215,250
1886
1887 Table: Chi-Square Tests
1888 ,Value,df,Asymptotic Sig. (2-tailed),Exact Sig. (2-tailed),Exact Sig. (1-tailed)
1889 Pearson Chi-Square,4.98,1,.026,,
1890 Likelihood Ratio,4.88,1,.027,,
1891 Fisher's Exact Test,,,,.039,.021
1892 Continuity Correction,4.19,1,.041,,
1893 Linear-by-Linear Association,4.96,1,.026,,
1894 N of Valid Cases,250,,,,
1895
1896 Table: Risk Estimate
1897 ,Value,95% Confidence Interval,
1898 ,,Lower,Upper
1899 Odds Ratio for factor (Placebo / Aspirin),2.25,2.25,2.25
1900 For cohort disease = Yes,1.08,1.08,1.08
1901 For cohort disease = No,.99,.99,.99
1902 N of Valid Cases,250.00,,
1903 ])
1904 AT_CLEANUP
1905
1906 AT_SETUP([CROSSTABS barchart])
1907 AT_DATA([bc.sps], [dnl
1908 SET FORMAT=F8.3.
1909
1910 DATA LIST LIST NOTABLE /x (a20) y (f8) z (f8) w (f8) .
1911 BEGIN DATA.
1912 This  1  0 416
1913 That  2  0 121
1914 Other 2  0 335
1915 This  2  0 231
1916 That  3  0 112
1917 Other 4  0 130
1918 This  1  1 160
1919 That  2  1 211
1920 Other 2  1 352
1921 This  2  1 212
1922 That  3  1 121
1923 Other 4  1 101
1924 END DATA.
1925
1926 WEIGHT BY w.
1927
1928 CROSSTABS
1929           /table x BY y BY z
1930           /table x BY y
1931           /barchart.
1932 ])
1933
1934 AT_CHECK([pspp -O format=txt -o xxx bc.sps], [0], [ignore])
1935
1936 AT_CHECK([test -e xxx-1.png], [0], [ignore])
1937 AT_CHECK([test -e xxx-2.png], [0], [ignore])
1938
1939 AT_CHECK([diff xxx-1.png xxx-2.png], [0], [ignore])
1940
1941 AT_CLEANUP
1942
1943 AT_SETUP([CROSSTABS syntax errors])
1944 AT_DATA([crosstabs.sps], [dnl
1945 DATA LIST LIST NOTABLE/x y v1 to v100.
1946 CROSSTABS TABLES=x BY y/VARIABLES **.
1947 CROSSTABS VARIABLES=**.
1948 CROSSTABS VARIABLES=x **.
1949 CROSSTABS VARIABLES=x (**).
1950 CROSSTABS VARIABLES=x (1,**).
1951 CROSSTABS VARIABLES=x (1,5**).
1952 CROSSTABS MISSING=**.
1953 CROSSTABS COUNT=**.
1954 CROSSTABS FORMAT=**.
1955 CROSSTABS CELLS=**.
1956 CROSSTABS STATISTICS=**.
1957 CROSSTABS **.
1958 CROSSTABS
1959        v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
1960     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
1961     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
1962     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
1963     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
1964     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100.
1965 CROSSTABS BARCHART.
1966 CROSSTABS x BY y/MISSING=REPORT.
1967 ])
1968 AT_CHECK([pspp -O format=csv crosstabs.sps], [1], [dnl
1969 "crosstabs.sps:2.25-2.33: error: CROSSTABS: VARIABLES must be specified before TABLES.
1970     2 | CROSSTABS TABLES=x BY y/VARIABLES **.
1971       |                         ^~~~~~~~~"
1972
1973 "crosstabs.sps:3.21-3.22: error: CROSSTABS: Syntax error expecting variable name.
1974     3 | CROSSTABS VARIABLES=**.
1975       |                     ^~"
1976
1977 "crosstabs.sps:4.23-4.24: error: CROSSTABS: Syntax error expecting `('.
1978     4 | CROSSTABS VARIABLES=x **.
1979       |                       ^~"
1980
1981 "crosstabs.sps:5.24-5.25: error: CROSSTABS: Syntax error expecting integer.
1982     5 | CROSSTABS VARIABLES=x (**).
1983       |                        ^~"
1984
1985 "crosstabs.sps:6.26-6.27: error: CROSSTABS: Syntax error expecting positive integer.
1986     6 | CROSSTABS VARIABLES=x (1,**).
1987       |                          ^~"
1988
1989 "crosstabs.sps:7.27-7.28: error: CROSSTABS: Syntax error expecting `)'.
1990     7 | CROSSTABS VARIABLES=x (1,5**).
1991       |                           ^~"
1992
1993 "crosstabs.sps:8.19-8.20: error: CROSSTABS: Syntax error expecting TABLE, INCLUDE, or REPORT.
1994     8 | CROSSTABS MISSING=**.
1995       |                   ^~"
1996
1997 "crosstabs.sps:9.17-9.18: error: CROSSTABS: Syntax error expecting ASIS, CASE, CELL, ROUND, or TRUNCATE.
1998     9 | CROSSTABS COUNT=**.
1999       |                 ^~"
2000
2001 "crosstabs.sps:10.18-10.19: error: CROSSTABS: Syntax error expecting AVALUE, DVALUE, TABLES, or NOTABLES.
2002    10 | CROSSTABS FORMAT=**.
2003       |                  ^~"
2004
2005 "crosstabs.sps:11.17-11.18: error: CROSSTABS: Syntax error expecting COUNT, EXPECTED, ROW, COLUMN, TOTAL, RESIDUAL, SRESIDUAL, or ASRESIDUAL.
2006    11 | CROSSTABS CELLS=**.
2007       |                 ^~"
2008
2009 "crosstabs.sps:12.22-12.23: error: CROSSTABS: Syntax error expecting one of the following: CHISQ, PHI, CC, LAMBDA, UC, BTAU, CTAU, RISK, GAMMA, D, KAPPA, ETA, CORR.
2010    12 | CROSSTABS STATISTICS=**.
2011       |                      ^~"
2012
2013 "crosstabs.sps:13.11-13.12: error: CROSSTABS: Syntax error expecting subcommand name or variable name.
2014    13 | CROSSTABS **.
2015       |           ^~"
2016
2017 "crosstabs.sps:15.8-16.59: error: CROSSTABS: Too many cross-tabulation variables or dimensions.
2018    15 |        v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
2019       |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020    16 |     BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100 BY v1 to v100
2021       | -----------------------------------------------------------"
2022
2023 crosstabs.sps:21: error: CROSSTABS: At least one crosstabulation must be requested (using the TABLES subcommand).
2024
2025 "crosstabs.sps:22.26-22.31: warning: CROSSTABS: Missing mode REPORT not allowed in general mode.  Assuming MISSING=TABLE.
2026    22 | CROSSTABS x BY y/MISSING=REPORT.
2027       |                          ^~~~~~"
2028
2029 error: CROSSTABS: At end of input: Syntax error expecting `BEGIN DATA'.
2030 ])
2031 AT_CLEANUP