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