Merge remote-tracking branch 'origin/master' into sheet
[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
435
436 AT_SETUP([CROSSTABS descending sort order])
437 AT_DATA([crosstabs-descending.sps],
438   [[DATA LIST NOTABLE LIST /x * y *.
439 BEGIN DATA.
440 2 2
441 2 2
442 3 1
443 4 1
444 3 2
445 3 2
446 END DATA.
447
448 CROSSTABS
449         /TABLES= x BY y
450         /FORMAT = DVALUE.
451 ]])
452
453 AT_CHECK([pspp -O format=csv crosstabs-descending.sps], [0],
454   [[Table: Summary.
455 ,Cases,,,,,
456 ,Valid,,Missing,,Total,
457 ,N,Percent,N,Percent,N,Percent
458 x * y,6,100.0%,0,0.0%,6,100.0%
459
460 Table: x * y [count].
461 ,y,,
462 x,2.00,1.00,Total
463 4.00,.00,1.00,1.00
464 3.00,2.00,1.00,3.00
465 2.00,2.00,.00,2.00
466 Total,4.00,2.00,6.00
467 ]])
468 AT_CLEANUP
469
470 # Bug #31260.
471 AT_SETUP([CROSSTABS crash when all cases missing])
472 AT_DATA([crosstabs.sps], [dnl
473 DATA LIST LIST NOTABLE /X1 X2.
474 BEGIN DATA.
475 1 1
476 END DATA.
477
478 MISSING VALUES x2 (1).
479
480 CROSSTABS /TABLES= X1 by X2.
481 ])
482 AT_CHECK([pspp -O format=csv crosstabs.sps], [0], [dnl
483 Table: Summary.
484 ,Cases,,,,,
485 ,Valid,,Missing,,Total,
486 ,N,Percent,N,Percent,N,Percent
487 X1 * X2,0,0.0%,1,100.0%,1,100.0%
488
489 crosstabs.sps:8: warning: CROSSTABS: Crosstabulation X1 * X2 contained no non-missing cases.
490 ])
491 AT_CLEANUP
492
493
494
495 dnl This example comes from http://www.ats.ucla.edu/stat/spss/whatstat/whatstat.htm#chisq
496 AT_SETUP([CROSSTABS Fisher Exact Test])
497
498 AT_DATA([fisher-exact.sps], [dnl
499 SET FORMAT F12.3.
500 SET DECIMAL DOT.
501
502 DATA LIST notable LIST  /schtyp (F9.2) female (F9.2) ses (F9.2) .
503 begin data.
504       1.00       .00      1.00 
505       1.00      1.00      2.00 
506       1.00       .00      3.00 
507       1.00       .00      3.00 
508       1.00       .00      2.00 
509       1.00       .00      2.00 
510       1.00       .00      2.00 
511       1.00       .00      2.00 
512       1.00       .00      2.00 
513       1.00       .00      2.00 
514       1.00       .00      2.00 
515       1.00       .00      2.00 
516       1.00       .00      3.00 
517       1.00       .00      3.00 
518       1.00       .00      1.00 
519       1.00       .00      1.00 
520       1.00       .00      3.00 
521       2.00       .00      2.00 
522       1.00       .00      3.00 
523       1.00       .00      2.00 
524       1.00       .00      2.00 
525       1.00       .00      2.00 
526       1.00       .00      2.00 
527       1.00       .00      3.00 
528       1.00       .00      2.00 
529       1.00       .00      2.00 
530       1.00       .00      3.00 
531       2.00       .00      2.00 
532       2.00       .00      3.00 
533       1.00       .00      1.00 
534       1.00       .00      2.00 
535       1.00       .00      3.00 
536       2.00       .00      3.00 
537       1.00       .00      2.00 
538       2.00       .00      3.00 
539       1.00       .00      3.00 
540       2.00       .00      2.00 
541       1.00       .00      3.00 
542       1.00       .00      1.00 
543       1.00       .00      2.00 
544       2.00       .00      2.00 
545       2.00       .00      2.00 
546       1.00       .00      2.00 
547       1.00       .00      1.00 
548       1.00       .00      3.00 
549       1.00       .00      1.00 
550       1.00       .00      3.00 
551       1.00       .00      2.00 
552       2.00       .00      2.00 
553       1.00       .00      2.00 
554       1.00       .00      2.00 
555       1.00       .00      3.00 
556       1.00       .00      2.00 
557       2.00       .00      2.00 
558       1.00       .00      2.00 
559       1.00       .00      3.00 
560       1.00       .00      1.00 
561       1.00       .00      2.00 
562       2.00       .00      2.00 
563       1.00       .00      2.00 
564       2.00       .00      2.00 
565       1.00       .00      3.00 
566       1.00       .00      1.00 
567       1.00       .00      2.00 
568       2.00       .00      3.00 
569       1.00       .00      2.00 
570       1.00       .00      2.00 
571       1.00       .00      1.00 
572       1.00       .00      1.00 
573       1.00       .00      2.00 
574       1.00       .00      2.00 
575       1.00       .00      3.00 
576       1.00       .00      2.00 
577       1.00       .00      2.00 
578       1.00       .00      2.00 
579       1.00       .00      1.00 
580       1.00       .00      3.00 
581       1.00       .00      3.00 
582       1.00       .00      2.00 
583       1.00       .00      3.00 
584       1.00       .00      3.00 
585       1.00       .00      1.00 
586       2.00       .00      2.00 
587       1.00       .00      1.00 
588       1.00       .00      2.00 
589       1.00       .00      3.00 
590       1.00       .00      3.00 
591       1.00       .00      3.00 
592       1.00       .00      2.00 
593       1.00       .00      3.00 
594       1.00       .00      2.00 
595       1.00       .00      1.00 
596       1.00      1.00      3.00 
597       1.00      1.00      1.00 
598       1.00      1.00      1.00 
599       1.00      1.00      1.00 
600       1.00      1.00      2.00 
601       1.00      1.00      3.00 
602       1.00      1.00      1.00 
603       2.00      1.00      3.00 
604       1.00      1.00      3.00 
605       1.00      1.00      3.00 
606       1.00      1.00      1.00 
607       1.00      1.00      3.00 
608       1.00      1.00      2.00 
609       1.00      1.00      2.00 
610       1.00      1.00      3.00 
611       1.00      1.00      1.00 
612       2.00      1.00      1.00 
613       2.00      1.00      3.00 
614       1.00      1.00      2.00 
615       1.00      1.00      1.00 
616       1.00      1.00      3.00 
617       1.00      1.00      1.00 
618       2.00      1.00      3.00 
619       1.00      1.00      2.00 
620       1.00      1.00      3.00 
621       1.00      1.00      3.00 
622       1.00      1.00      1.00 
623       1.00      1.00      1.00 
624       2.00      1.00      1.00 
625       1.00      1.00      2.00 
626       1.00      1.00      2.00 
627       1.00      1.00      2.00 
628       1.00      1.00      1.00 
629       1.00      1.00      3.00 
630       1.00      1.00      2.00 
631       1.00      1.00      2.00 
632       1.00      1.00      3.00 
633       1.00      1.00      1.00 
634       1.00      1.00      2.00 
635       1.00      1.00      1.00 
636       1.00      1.00      2.00 
637       1.00      1.00      2.00 
638       1.00      1.00      1.00 
639       1.00      1.00      3.00 
640       2.00      1.00      2.00 
641       1.00      1.00      2.00 
642       1.00      1.00      2.00 
643       2.00      1.00      2.00 
644       1.00      1.00      1.00 
645       1.00      1.00      3.00 
646       1.00      1.00      2.00 
647       1.00      1.00      2.00 
648       1.00      1.00      2.00 
649       2.00      1.00      3.00 
650       1.00      1.00      2.00 
651       2.00      1.00      2.00 
652       1.00      1.00      1.00 
653       1.00      1.00      1.00 
654       1.00      1.00      1.00 
655       1.00      1.00      3.00 
656       1.00      1.00      2.00 
657       1.00      1.00      2.00 
658       1.00      1.00      2.00 
659       1.00      1.00      2.00 
660       1.00      1.00      2.00 
661       1.00      1.00      2.00 
662       1.00      1.00      2.00 
663       1.00      1.00      3.00 
664       1.00      1.00      1.00 
665       1.00      1.00      2.00 
666       2.00      1.00      3.00 
667       1.00      1.00      1.00 
668       1.00      1.00      2.00 
669       1.00      1.00      1.00 
670       1.00      1.00      2.00 
671       1.00      1.00      1.00 
672       2.00      1.00      2.00 
673       1.00      1.00      1.00 
674       1.00      1.00      1.00 
675       1.00      1.00      2.00 
676       1.00      1.00      3.00 
677       1.00      1.00      3.00 
678       1.00      1.00      1.00 
679       1.00      1.00      1.00 
680       1.00      1.00      2.00 
681       1.00      1.00      2.00 
682       1.00      1.00      3.00 
683       1.00      1.00      1.00 
684       1.00      1.00      2.00 
685       2.00      1.00      2.00 
686       1.00      1.00      3.00 
687       1.00      1.00      2.00 
688       1.00      1.00      3.00 
689       1.00      1.00      1.00 
690       1.00      1.00      2.00 
691       1.00      1.00      2.00 
692       2.00      1.00      3.00 
693       1.00      1.00      1.00 
694       1.00      1.00      1.00 
695       2.00      1.00      3.00 
696       2.00      1.00      2.00 
697       1.00      1.00      3.00 
698       2.00      1.00      2.00 
699       2.00      1.00      2.00 
700       1.00      1.00      2.00 
701       2.00      1.00      2.00 
702       1.00      1.00      2.00 
703       1.00      1.00      3.00 
704 end data.
705
706 VARIABLE LABEL schtyp 'type of school'.
707 ADD VALUE LABELS female 0 male 1 female.
708 ADD VALUE LABELS ses 1 low 2 middle 3 high.
709 ADD VALUE LABELS schtyp 1 public 2 private.
710
711 crosstabs /tables = schtyp by female /statistic = chisq.
712 crosstabs /tables = female by ses  /statistic = chisq.
713 ])
714
715 AT_CHECK([pspp -O format=csv fisher-exact.sps], [0], [dnl
716 Table: Summary.
717 ,Cases,,,,,
718 ,Valid,,Missing,,Total,
719 ,N,Percent,N,Percent,N,Percent
720 type of school * female,200,100.0%,0,0.0%,200,100.0%
721
722 Table: type of school * female [[count]].
723 ,female,,
724 type of school,male,female,Total
725 public,77.000,91.000,168.000
726 private,14.000,18.000,32.000
727 Total,91.000,109.000,200.000
728
729 Table: Chi-square tests.
730 Statistic,Value,df,Asymp. Sig. (2-tailed),Exact Sig. (2-tailed),Exact Sig. (1-tailed)
731 Pearson Chi-Square,.047,1,.828,,
732 Likelihood Ratio,.047,1,.828,,
733 Fisher's Exact Test,,,,.849,.492
734 Continuity Correction,.001,1,.981,,
735 Linear-by-Linear Association,.047,1,.829,,
736 N of Valid Cases,200,,,,
737
738 Table: Summary.
739 ,Cases,,,,,
740 ,Valid,,Missing,,Total,
741 ,N,Percent,N,Percent,N,Percent
742 female * ses,200,100.0%,0,0.0%,200,100.0%
743
744 Table: female * ses [[count]].
745 ,ses,,,
746 female,low,middle,high,Total
747 male,15.000,47.000,29.000,91.000
748 female,32.000,48.000,29.000,109.000
749 Total,47.000,95.000,58.000,200.000
750
751 Table: Chi-square tests.
752 Statistic,Value,df,Asymp. Sig. (2-tailed)
753 Pearson Chi-Square,4.577,2,.101
754 Likelihood Ratio,4.679,2,.096
755 Linear-by-Linear Association,3.110,1,.078
756 N of Valid Cases,200,,
757 ])
758
759 AT_CLEANUP
760
761 AT_SETUP([CROSSTABS Pearson's R])
762 # Test 1.
763 AT_DATA([pearson.sps], [dnl
764 SET FORMAT F8.3.
765
766 * From http://www.statisticslectures.com/topics/pearsonr/.
767 DATA LIST FREE/x y.
768 BEGIN DATA.
769 1 4
770 3 6
771 5 10
772 5 12
773 6 13
774 END DATA.
775 CROSSTABS x BY y/STATISTICS=CORR.
776 ])
777 AT_CHECK([pspp -O format=csv pearson.sps], [0], [dnl
778 Table: Summary.
779 ,Cases,,,,,
780 ,Valid,,Missing,,Total,
781 ,N,Percent,N,Percent,N,Percent
782 x * y,5,100.0%,0,0.0%,5,100.0%
783
784 Table: x * y [[count]].
785 ,y,,,,,
786 x,4.000,6.000,10.000,12.000,13.000,Total
787 1.000,1.000,.000,.000,.000,.000,1.000
788 3.000,.000,1.000,.000,.000,.000,1.000
789 5.000,.000,.000,1.000,1.000,.000,2.000
790 6.000,.000,.000,.000,.000,1.000,1.000
791 Total,1.000,1.000,1.000,1.000,1.000,5.000
792
793 Table: Symmetric measures.
794 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
795 Ordinal by Ordinal,Spearman Correlation,.975,.022,7.550,
796 Interval by Interval,Pearson's R,.968,.017,6.708,
797 N of Valid Cases,,5,,,
798 ])
799
800 # Test 2.
801 AT_DATA([pearson2.sps], [dnl
802 SET FORMAT F8.3.
803
804 * Checked with http://www.socscistatistics.com/tests/pearson/Default2.aspx.
805 DATA LIST FREE/x y.
806 BEGIN DATA.
807 1 1.5
808 2 1.5
809 3 4
810 4 6
811 5 5
812 6 7
813 7 6.5
814 8 9
815 9 10.5
816 10 11
817 END DATA.
818 CROSSTABS x BY y/STATISTICS=CORR.
819 ])
820 AT_CHECK([pspp -O format=csv pearson2.sps], [0], [dnl
821 Table: Summary.
822 ,Cases,,,,,
823 ,Valid,,Missing,,Total,
824 ,N,Percent,N,Percent,N,Percent
825 x * y,10,100.0%,0,0.0%,10,100.0%
826
827 Table: x * y [[count]].
828 ,y,,,,,,,,,
829 x,1.500,4.000,5.000,6.000,6.500,7.000,9.000,10.500,11.000,Total
830 1.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
831 2.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
832 3.000,.000,1.000,.000,.000,.000,.000,.000,.000,.000,1.000
833 4.000,.000,.000,.000,1.000,.000,.000,.000,.000,.000,1.000
834 5.000,.000,.000,1.000,.000,.000,.000,.000,.000,.000,1.000
835 6.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,1.000
836 7.000,.000,.000,.000,.000,1.000,.000,.000,.000,.000,1.000
837 8.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,1.000
838 9.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,1.000
839 10.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000
840 Total,2.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,10.000
841
842 Table: Symmetric measures.
843 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
844 Ordinal by Ordinal,Spearman Correlation,.973,.015,11.844,
845 Interval by Interval,Pearson's R,.971,.017,11.580,
846 N of Valid Cases,,10,,,
847 ])
848
849 # Test 3.
850 AT_DATA([pearson3.sps], [dnl
851 SET FORMAT F8.3.
852
853 * From http://learntech.uwe.ac.uk/da/Default.aspx?pageid=1442.
854 DATA LIST FREE/x y.
855 BEGIN DATA.
856 56 87
857 56 91
858 65 85
859 65 91
860 50 75
861 25 28
862 87 122
863 44 66
864 35 58
865 END DATA.
866 CROSSTABS x BY y/STATISTICS=CORR.
867 ])
868 AT_CHECK([pspp -O format=csv pearson3.sps], [0], [dnl
869 Table: Summary.
870 ,Cases,,,,,
871 ,Valid,,Missing,,Total,
872 ,N,Percent,N,Percent,N,Percent
873 x * y,9,100.0%,0,0.0%,9,100.0%
874
875 Table: x * y [[count]].
876 ,y,,,,,,,,
877 x,28.000,58.000,66.000,75.000,85.000,87.000,91.000,122.000,Total
878 25.000,1.000,.000,.000,.000,.000,.000,.000,.000,1.000
879 35.000,.000,1.000,.000,.000,.000,.000,.000,.000,1.000
880 44.000,.000,.000,1.000,.000,.000,.000,.000,.000,1.000
881 50.000,.000,.000,.000,1.000,.000,.000,.000,.000,1.000
882 56.000,.000,.000,.000,.000,.000,1.000,1.000,.000,2.000
883 65.000,.000,.000,.000,.000,1.000,.000,1.000,.000,2.000
884 87.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000
885 Total,1.000,1.000,1.000,1.000,1.000,1.000,2.000,1.000,9.000
886
887 Table: Symmetric measures.
888 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
889 Ordinal by Ordinal,Spearman Correlation,.911,.068,5.860,
890 Interval by Interval,Pearson's R,.966,.017,9.915,
891 N of Valid Cases,,9,,,
892 ])
893
894 # Test 4.
895 AT_DATA([pearson4.sps], [dnl
896 SET FORMAT F8.3.
897
898 * From http://psychology.ucdavis.edu/faculty_sites/sommerb/sommerdemo/correlation/hand/pearson_hand.htm.
899 DATA LIST FREE/x y.
900 BEGIN DATA.
901 5 5
902 10 20
903 6 4
904 8 15
905 4 11
906 4 9
907 3 12
908 10 18
909 2 7
910 6 2
911 7 14
912 9 17
913 END DATA.
914 CROSSTABS x BY y/STATISTICS=CORR.
915 ])
916 AT_CHECK([pspp -O format=csv pearson4.sps], [0], [dnl
917 Table: Summary.
918 ,Cases,,,,,
919 ,Valid,,Missing,,Total,
920 ,N,Percent,N,Percent,N,Percent
921 x * y,12,100.0%,0,0.0%,12,100.0%
922
923 Table: x * y [[count]].
924 ,y,,,,,,,,,,,,
925 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
926 2.000,.000,.000,.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
927 3.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,.000,.000,1.000
928 4.000,.000,.000,.000,.000,1.000,1.000,.000,.000,.000,.000,.000,.000,2.000
929 5.000,.000,.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
930 6.000,1.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,2.000
931 7.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,.000,1.000
932 8.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,1.000
933 9.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,1.000
934 10.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000,2.000
935 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
936
937 Table: Symmetric measures.
938 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
939 Ordinal by Ordinal,Spearman Correlation,.657,.140,2.758,
940 Interval by Interval,Pearson's R,.667,.132,2.830,
941 N of Valid Cases,,12,,,
942 ])
943
944 # Test 5.
945 AT_DATA([pearson5.sps], [dnl
946 SET FORMAT F8.3.
947
948 * From http://www.statisticslectures.com/topics/pearsonr/.
949 DATA LIST FREE/x y.
950 BEGIN DATA.
951 18 15000
952 25 29000
953 57 68000
954 45 52000
955 26 32000
956 64 80000
957 37 41000
958 40 45000
959 24 26000
960 33 33000
961 END DATA.
962 CROSSTABS x BY y/STATISTICS=CORR.
963 ])
964 AT_CHECK([pspp -O format=csv pearson5.sps], [0], [dnl
965 Table: Summary.
966 ,Cases,,,,,
967 ,Valid,,Missing,,Total,
968 ,N,Percent,N,Percent,N,Percent
969 x * y,10,100.0%,0,0.0%,10,100.0%
970
971 Table: x * y [[count]].
972 ,y,,,,,,,,,,
973 x,15000.000,26000.000,29000.000,32000.000,33000.000,41000.000,45000.000,52000.000,68000.000,80000.000,Total
974 18.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
975 24.000,.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000
976 25.000,.000,.000,1.000,.000,.000,.000,.000,.000,.000,.000,1.000
977 26.000,.000,.000,.000,1.000,.000,.000,.000,.000,.000,.000,1.000
978 33.000,.000,.000,.000,.000,1.000,.000,.000,.000,.000,.000,1.000
979 37.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,.000,1.000
980 40.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,.000,1.000
981 45.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,.000,1.000
982 57.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,.000,1.000
983 64.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000
984 Total,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,1.000,10.000
985
986 Table: Symmetric measures.
987 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
988 Ordinal by Ordinal,Spearman Correlation,1.000,.000,+Infinity,
989 Interval by Interval,Pearson's R,.992,.004,22.638,
990 N of Valid Cases,,10,,,
991 ])
992 AT_CLEANUP
993
994 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda])
995 AT_DATA([lambda.sps], [dnl
996 SET FORMAT F8.3.
997
998 * From http://www.csupomona.edu/~jlkorey/POWERMUTT/Topics/contingency_tables.html.
999 DATA LIST LIST NOTABLE/x y w.
1000 WEIGHT BY w.
1001 BEGIN DATA.
1002 1 1 424
1003 1 2 213
1004 1 3 59
1005 3 1 55
1006 3 2 188
1007 3 3 357
1008 END DATA.
1009
1010 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1011
1012 * From http://vassarstats.net.
1013 DATA LIST LIST NOTABLE/x y w.
1014 WEIGHT BY w.
1015 BEGIN DATA.
1016 1 1 19
1017 1 2 26
1018 1 3 8
1019 2 1 21
1020 2 2 13
1021 2 3 5
1022 3 1 6
1023 3 2 12
1024 3 3 27
1025 END DATA.
1026
1027 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1028
1029 * From Goodman, L.A., Kruskal, W.H. (1954) "Measures of association for
1030   cross classifications". Part I. Journal of the American Statistical
1031   Association, 49, 732-764.
1032 DATA LIST LIST NOTABLE/x y w.
1033 WEIGHT BY w.
1034 BEGIN DATA.
1035 1 1 1768
1036 1 2 807
1037 1 3 189
1038 1 4 47
1039 2 1 946
1040 2 2 1387
1041 2 3 746
1042 2 4 53
1043 3 1 115
1044 3 2 438
1045 3 3 288
1046 3 4 16
1047 END DATA.
1048 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1049 ])
1050 AT_CHECK([pspp -O format=csv lambda.sps], [0], [dnl
1051 Table: Summary.
1052 ,Cases,,,,,
1053 ,Valid,,Missing,,Total,
1054 ,N,Percent,N,Percent,N,Percent
1055 x * y,1296.000,100.0%,.000,0.0%,1296.000,100.0%
1056
1057 Table: Directional measures.
1058 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1059 Nominal by Nominal,Lambda,Symmetric,.423,.021,16.875,.000
1060 ,,x Dependent,.497,.024,15.986,.000
1061 ,,y Dependent,.370,.020,16.339,.000
1062 ,Goodman and Kruskal tau,x Dependent,.382,,,.   @&t@
1063 ,,y Dependent,.198,,,.   @&t@
1064
1065 Table: Summary.
1066 ,Cases,,,,,
1067 ,Valid,,Missing,,Total,
1068 ,N,Percent,N,Percent,N,Percent
1069 x * y,137.000,100.0%,.000,0.0%,137.000,100.0%
1070
1071 Table: Directional measures.
1072 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1073 Nominal by Nominal,Lambda,Symmetric,.259,.081,2.902,.004
1074 ,,x Dependent,.250,.089,2.479,.013
1075 ,,y Dependent,.267,.085,2.766,.006
1076 ,Goodman and Kruskal tau,x Dependent,.129,,,.   @&t@
1077 ,,y Dependent,.123,,,.   @&t@
1078
1079 Table: Summary.
1080 ,Cases,,,,,
1081 ,Valid,,Missing,,Total,
1082 ,N,Percent,N,Percent,N,Percent
1083 x * y,6800.000,100.0%,.000,0.0%,6800.000,100.0%
1084
1085 Table: Directional measures.
1086 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1087 Nominal by Nominal,Lambda,Symmetric,.208,.010,18.793,.000
1088 ,,x Dependent,.224,.013,16.076,.000
1089 ,,y Dependent,.192,.012,14.438,.000
1090 ,Goodman and Kruskal tau,x Dependent,.089,,,.   @&t@
1091 ,,y Dependent,.081,,,.   @&t@
1092 ])
1093 AT_CLEANUP
1094
1095 AT_SETUP([CROSSTABS Goodman and Kruskal's lambda - treatment of ties])
1096 AT_DATA([lambda.sps], [dnl
1097 SET FORMAT F8.3.
1098
1099 * From Douglas Bonett.
1100 DATA LIST LIST NOTABLE/x y w.
1101 WEIGHT BY w.
1102 BEGIN DATA.
1103 1 1 225
1104 1 2 43
1105 1 3 216
1106 2 1 3
1107 2 2 1
1108 2 3 12
1109 END DATA.
1110
1111 CROSSTABS x BY y/CELLS=NONE/STATISTICS=LAMBDA.
1112 ])
1113 AT_CHECK([pspp -O format=csv lambda.sps], [0], [dnl
1114 Table: Summary.
1115 ,Cases,,,,,
1116 ,Valid,,Missing,,Total,
1117 ,N,Percent,N,Percent,N,Percent
1118 x * y,500.000,100.0%,.000,0.0%,500.000,100.0%
1119
1120 Table: Directional measures.
1121 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1122 Nominal by Nominal,Lambda,Symmetric,.031,.013,2.336,.019
1123 ,,x Dependent,.000,.000,NaN,NaN
1124 ,,y Dependent,.033,.014,2.336,.019
1125 ,Goodman and Kruskal tau,x Dependent,.012,,,.   @&t@
1126 ,,y Dependent,.009,,,.   @&t@
1127 ])
1128 AT_CLEANUP
1129
1130 AT_SETUP([CROSSTABS Somers' D, Tau-B, Tau-C, Gamma])
1131 AT_DATA([somersd.sps], [dnl
1132 SET FORMAT F8.3.
1133
1134 * From http://stats.stackexchange.com/questions/72203/problem-with-calculating-asymptotic-standard-error-for-somers-d.
1135 DATA LIST LIST NOTABLE/x y * w (F10.6).
1136 WEIGHT BY w.
1137 BEGIN DATA.
1138 1 1 0.000025
1139 1 2 0.0001
1140 1 3 0.001
1141 1 4 0.0025
1142 1 5 0.004
1143 1 6 0.0075
1144 1 7 0.0125
1145 2 1 0.049975
1146 2 2 0.0999
1147 2 3 0.199
1148 2 4 0.2475
1149 2 5 0.196
1150 2 6 0.1425
1151 2 7 0.0375
1152 END DATA.
1153 CROSSTABS x BY y/STATISTICS=D/CELLS=NONE.
1154
1155 * From http://uregina.ca/~gingrich/gamma.pdf.
1156 DATA LIST LIST NOTABLE/x y w.
1157 WEIGHT BY w.
1158 BEGIN DATA.
1159 1 1 34
1160 1 2 24
1161 1 3 15
1162 2 1 42
1163 2 2 74
1164 2 3 67
1165 3 1 28
1166 3 2 111
1167 3 3 292
1168 END DATA.
1169 CROSSTABS x BY y/STATISTICS=BTAU CTAU GAMMA D/CELLS=NONE.
1170 ])
1171 AT_CHECK([pspp -O format=csv somersd.sps], [0], [dnl
1172 Table: Summary.
1173 ,Cases,,,,,
1174 ,Valid,,Missing,,Total,
1175 ,N,Percent,N,Percent,N,Percent
1176 x * y,1.000000,100.0%,.000000,0.0%,1.000000,100.0%
1177
1178 Table: Directional measures.
1179 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1180 Ordinal by Ordinal,Somers' d,Symmetric,-.084,,-.149,.882
1181 ,,x Dependent,-.045,.300,-.149,.882
1182 ,,y Dependent,-.684,2.378,-.149,.882
1183
1184 Table: Summary.
1185 ,Cases,,,,,
1186 ,Valid,,Missing,,Total,
1187 ,N,Percent,N,Percent,N,Percent
1188 x * y,687.000,100.0%,.000,0.0%,687.000,100.0%
1189
1190 Table: Symmetric measures.
1191 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1192 Ordinal by Ordinal,Kendall's tau-b,.372,.033,10.669,
1193 ,Kendall's tau-c,.310,.029,10.669,
1194 ,Gamma,.591,.043,10.669,
1195 N of Valid Cases,,687.000,,,
1196
1197 Table: Directional measures.
1198 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1199 Ordinal by Ordinal,Somers' d,Symmetric,.371,,10.669,.000
1200 ,,x Dependent,.351,.032,10.669,.000
1201 ,,y Dependent,.394,.035,10.669,.000
1202 ])
1203
1204 AT_DATA([ordinal.sps], [dnl
1205 SET FORMAT F8.3.
1206
1207 * From https://www.iup.edu/WorkArea/DownloadAsset.aspx?id=9829, "Case 1".
1208 DATA LIST LIST NOTABLE /x y w.
1209 WEIGHT BY w.
1210 BEGIN DATA.
1211 1 2 40
1212 2 3 80
1213 3 4 30
1214 END DATA.
1215 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1216
1217 * Same site, case 2.
1218 DATA LIST LIST NOTABLE /x y w.
1219 WEIGHT BY w.
1220 BEGIN DATA.
1221 1 1 40
1222 2 3 80
1223 3 4 30
1224 END DATA.
1225 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1226
1227 * Same site, case 3.
1228 DATA LIST LIST NOTABLE /x y w.
1229 WEIGHT BY w.
1230 BEGIN DATA.
1231 1 4 40
1232 2 3 80
1233 3 2 30
1234 END DATA.
1235 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1236
1237 * Same site, case 4.
1238 DATA LIST LIST NOTABLE /x y w.
1239 WEIGHT BY w.
1240 BEGIN DATA.
1241 1 1 20
1242 1 2 20
1243 2 3 80
1244 3 4 30
1245 END DATA.
1246 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1247
1248 * Same site, case 5.
1249 DATA LIST LIST NOTABLE /x y w.
1250 WEIGHT BY w.
1251 BEGIN DATA.
1252 1 2 40
1253 2 2 80
1254 3 2 29
1255 3 3 1
1256 END DATA.
1257 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1258
1259 * Same site, case 6.
1260 DATA LIST LIST NOTABLE /x y w.
1261 WEIGHT BY w.
1262 BEGIN DATA.
1263 1 1 3
1264 1 2 6
1265 1 3 28
1266 1 4 61
1267 2 1 4
1268 2 2 5
1269 2 3 21
1270 2 4 20
1271 END DATA.
1272 CROSSTABS x BY y/STATISTICS=GAMMA D BTAU/CELLS=NONE.
1273
1274 * Same site, case 7.
1275 DATA LIST LIST NOTABLE /x y w.
1276 WEIGHT BY w.
1277 BEGIN DATA.
1278 1 1 38
1279 1 2 6
1280 1 3 3
1281 1 4 51
1282 2 1 4
1283 2 2 20
1284 2 3 21
1285 2 4 5
1286 END DATA.
1287 CROSSTABS x BY y/STATISTICS=LAMBDA D PHI GAMMA/CELLS=NONE.
1288
1289 * Same site, case 8.
1290 DATA LIST LIST NOTABLE /x y w.
1291 WEIGHT BY w.
1292 BEGIN DATA.
1293 1 1 2
1294 1 2 3
1295 1 3 5
1296 1 4 1
1297 2 1 2
1298 2 2 16
1299 2 3 3
1300 2 4 6
1301 3 1 3
1302 3 2 10
1303 3 3 35
1304 3 4 27
1305 4 1 6
1306 4 2 15
1307 4 3 33
1308 4 4 45
1309 END DATA.
1310 CROSSTABS x BY y/STATISTICS=LAMBDA D PHI BTAU/CELLS=NONE.
1311 ])
1312 AT_CHECK([pspp -O format=csv ordinal.sps], [0], [dnl
1313 Table: Summary.
1314 ,Cases,,,,,
1315 ,Valid,,Missing,,Total,
1316 ,N,Percent,N,Percent,N,Percent
1317 x * y,150.000,100.0%,.000,0.0%,150.000,100.0%
1318
1319 Table: Symmetric measures.
1320 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1321 Ordinal by Ordinal,Kendall's tau-b,1.000,.000,24.841,
1322 ,Gamma,1.000,.000,24.841,
1323 N of Valid Cases,,150.000,,,
1324
1325 Table: Directional measures.
1326 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1327 Ordinal by Ordinal,Somers' d,Symmetric,1.000,,24.841,.000
1328 ,,x Dependent,1.000,.000,24.841,.000
1329 ,,y Dependent,1.000,.000,24.841,.000
1330
1331 Table: Summary.
1332 ,Cases,,,,,
1333 ,Valid,,Missing,,Total,
1334 ,N,Percent,N,Percent,N,Percent
1335 x * y,150.000,100.0%,.000,0.0%,150.000,100.0%
1336
1337 Table: Symmetric measures.
1338 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1339 Ordinal by Ordinal,Kendall's tau-b,1.000,.000,24.841,
1340 ,Gamma,1.000,.000,24.841,
1341 N of Valid Cases,,150.000,,,
1342
1343 Table: Directional measures.
1344 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1345 Ordinal by Ordinal,Somers' d,Symmetric,1.000,,24.841,.000
1346 ,,x Dependent,1.000,.000,24.841,.000
1347 ,,y Dependent,1.000,.000,24.841,.000
1348
1349 Table: Summary.
1350 ,Cases,,,,,
1351 ,Valid,,Missing,,Total,
1352 ,N,Percent,N,Percent,N,Percent
1353 x * y,150.000,100.0%,.000,0.0%,150.000,100.0%
1354
1355 Table: Symmetric measures.
1356 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1357 Ordinal by Ordinal,Kendall's tau-b,-1.000,.000,-24.841,
1358 ,Gamma,-1.000,.000,-24.841,
1359 N of Valid Cases,,150.000,,,
1360
1361 Table: Directional measures.
1362 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1363 Ordinal by Ordinal,Somers' d,Symmetric,-1.000,,-24.841,.000
1364 ,,x Dependent,-1.000,.000,-24.841,.000
1365 ,,y Dependent,-1.000,.000,-24.841,.000
1366
1367 Table: Summary.
1368 ,Cases,,,,,
1369 ,Valid,,Missing,,Total,
1370 ,N,Percent,N,Percent,N,Percent
1371 x * y,150.000,100.0%,.000,0.0%,150.000,100.0%
1372
1373 Table: Symmetric measures.
1374 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1375 Ordinal by Ordinal,Kendall's tau-b,.972,.007,24.841,
1376 ,Gamma,1.000,.000,24.841,
1377 N of Valid Cases,,150.000,,,
1378
1379 Table: Directional measures.
1380 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1381 Ordinal by Ordinal,Somers' d,Symmetric,.971,,24.841,.000
1382 ,,x Dependent,.944,.013,24.841,.000
1383 ,,y Dependent,1.000,.000,24.841,.000
1384
1385 Table: Summary.
1386 ,Cases,,,,,
1387 ,Valid,,Missing,,Total,
1388 ,N,Percent,N,Percent,N,Percent
1389 x * y,150.000,100.0%,.000,0.0%,150.000,100.0%
1390
1391 Table: Symmetric measures.
1392 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1393 Ordinal by Ordinal,Kendall's tau-b,.119,.059,1.009,
1394 ,Gamma,1.000,.000,1.009,
1395 N of Valid Cases,,150.000,,,
1396
1397 Table: Directional measures.
1398 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1399 Ordinal by Ordinal,Somers' d,Symmetric,.035,,1.009,.313
1400 ,,x Dependent,.805,.032,1.009,.313
1401 ,,y Dependent,.018,.017,1.009,.313
1402
1403 Table: Summary.
1404 ,Cases,,,,,
1405 ,Valid,,Missing,,Total,
1406 ,N,Percent,N,Percent,N,Percent
1407 x * y,148.000,100.0%,.000,0.0%,148.000,100.0%
1408
1409 Table: Symmetric measures.
1410 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1411 Ordinal by Ordinal,Kendall's tau-b,-.208,.078,-2.641,
1412 ,Gamma,-.381,.130,-2.641,
1413 N of Valid Cases,,148.000,,,
1414
1415 Table: Directional measures.
1416 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1417 Ordinal by Ordinal,Somers' d,Symmetric,-.206,,-2.641,.008
1418 ,,x Dependent,-.182,.069,-2.641,.008
1419 ,,y Dependent,-.237,.089,-2.641,.008
1420
1421 Table: Summary.
1422 ,Cases,,,,,
1423 ,Valid,,Missing,,Total,
1424 ,N,Percent,N,Percent,N,Percent
1425 x * y,148.000,100.0%,.000,0.0%,148.000,100.0%
1426
1427 Table: Symmetric measures.
1428 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1429 Nominal by Nominal,Phi,.731,,,
1430 ,Cramer's V,.731,,,
1431 Ordinal by Ordinal,Gamma,-.110,.107,-1.022,
1432 N of Valid Cases,,148.000,,,
1433
1434 Table: Directional measures.
1435 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1436 Nominal by Nominal,Lambda,Symmetric,.338,.059,4.743,.000
1437 ,,x Dependent,.640,.085,4.875,.000
1438 ,,y Dependent,.174,.050,3.248,.001
1439 ,Goodman and Kruskal tau,x Dependent,.534,,,.   @&t@
1440 ,,y Dependent,.167,,,.   @&t@
1441 Ordinal by Ordinal,Somers' d,Symmetric,-.074,,-1.022,.307
1442 ,,x Dependent,-.060,.059,-1.022,.307
1443 ,,y Dependent,-.096,.094,-1.022,.307
1444
1445 Table: Summary.
1446 ,Cases,,,,,
1447 ,Valid,,Missing,,Total,
1448 ,N,Percent,N,Percent,N,Percent
1449 x * y,212.000,100.0%,.000,0.0%,212.000,100.0%
1450
1451 Table: Symmetric measures.
1452 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1453 Nominal by Nominal,Phi,.432,,,
1454 ,Cramer's V,.249,,,
1455 Ordinal by Ordinal,Kendall's tau-b,.209,.062,3.338,
1456 N of Valid Cases,,212.000,,,
1457
1458 Table: Directional measures.
1459 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1460 Nominal by Nominal,Lambda,Symmetric,.102,.067,1.473,.141
1461 ,,x Dependent,.027,.087,.302,.763
1462 ,,y Dependent,.165,.065,2.349,.019
1463 ,Goodman and Kruskal tau,x Dependent,.051,,,.   @&t@
1464 ,,y Dependent,.068,,,.   @&t@
1465 Ordinal by Ordinal,Somers' d,Symmetric,.209,,3.338,.001
1466 ,,x Dependent,.202,.060,3.338,.001
1467 ,,y Dependent,.217,.064,3.338,.001
1468 ])
1469 AT_CLEANUP
1470
1471 AT_SETUP([CROSSTABS Cohens Kappa])
1472
1473 dnl Example from Wood J. M. 
1474 dnl "Understanding and Computing Cohen's Kappa: A Tutorial"
1475 dnl WebPsychEmpiricist. Oct 3 2007
1476 AT_DATA([kappa.sps], [dnl
1477 SET FORMAT=F8.3.
1478
1479 data list notable list /p1 * p2 * w *.
1480 begin data.
1481 0 0 18
1482 1 0 1
1483 0 1 1
1484 end data.
1485
1486 weight by w.
1487
1488 crosstabs /table = p1 by p2
1489         statistics = kappa
1490         .
1491 ])
1492
1493 AT_CHECK([pspp -O format=csv kappa.sps], [0], [dnl
1494 Table: Summary.
1495 ,Cases,,,,,
1496 ,Valid,,Missing,,Total,
1497 ,N,Percent,N,Percent,N,Percent
1498 p1 * p2,20.000,100.0%,.000,0.0%,20.000,100.0%
1499
1500 Table: p1 * p2 [[count]].
1501 ,p2,,
1502 p1,.000,1.000,Total
1503 .000,18.000,1.000,19.000
1504 1.000,1.000,.000,1.000
1505 Total,19.000,1.000,20.000
1506
1507 Table: Symmetric measures.
1508 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1509 Measure of Agreement,Kappa,-.053,.037,-.235,
1510 N of Valid Cases,,20.000,,,
1511 ])
1512
1513 AT_CLEANUP
1514
1515
1516 AT_SETUP([CROSSTABS many statistics])
1517 AT_DATA([crosstabs.sps], [dnl
1518 SET FORMAT=F8.4.
1519
1520 * From http://www4.stat.ncsu.edu/~dzhang2/st744/table3.9.lst.txt.
1521 DATA LIST LIST NOTABLE/x y w.
1522 WEIGHT BY w.
1523 BEGIN DATA.
1524 1 1 25
1525 1 2 25
1526 1 3 12
1527 2 2 1
1528 2 3 3
1529 END DATA.
1530 CROSSTABS x BY y/STATISTICS=CHISQ PHI CC LAMBDA UC BTAU CTAU GAMMA D CORR/CELLS=NONE.
1531 ])
1532 AT_CHECK([pspp -O format=csv crosstabs.sps], [0], [dnl
1533 Table: Summary.
1534 ,Cases,,,,,
1535 ,Valid,,Missing,,Total,
1536 ,N,Percent,N,Percent,N,Percent
1537 x * y,66.0000,100.0%,.0000,0.0%,66.0000,100.0%
1538
1539 Table: Chi-square tests.
1540 Statistic,Value,df,Asymp. Sig. (2-tailed)
1541 Pearson Chi-Square,6.9562,2.0000,.031
1542 Likelihood Ratio,6.6901,2.0000,.035
1543 Linear-by-Linear Association,5.8450,1.0000,.016
1544 N of Valid Cases,66.0000,,
1545
1546 Table: Symmetric measures.
1547 Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1548 Nominal by Nominal,Phi,.3246,,,
1549 ,Cramer's V,.3246,,,
1550 ,Contingency Coefficient,.3088,,,
1551 Ordinal by Ordinal,Kendall's tau-b,.2752,.0856,1.9920,
1552 ,Kendall's tau-c,.1497,.0751,1.9920,
1553 ,Gamma,.8717,.1250,1.9920,
1554 ,Spearman Correlation,.2908,.0906,2.4311,
1555 Interval by Interval,Pearson's R,.2999,.0973,2.5147,
1556 N of Valid Cases,,66.0000,,,
1557
1558 Table: Directional measures.
1559 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1560 Nominal by Nominal,Lambda,Symmetric,.0455,.1629,.2723,.785
1561 ,,x Dependent,.0000,.0000,NaN,NaN
1562 ,,y Dependent,.0500,.1791,.2723,.785
1563 ,Goodman and Kruskal tau,x Dependent,.1054,,,.   @&t@
1564 ,,y Dependent,.0434,,,.   @&t@
1565 ,Uncertainty Coefficient,Symmetric,.0780,.0474,,.   @&t@
1566 ,,x Dependent,.2217,.1062,1.5373,.   @&t@
1567 ,,y Dependent,.0473,.0306,1.5373,.   @&t@
1568 Ordinal by Ordinal,Somers' d,Symmetric,.1960,,1.9920,.046
1569 ,,x Dependent,.1152,.0572,1.9920,.046
1570 ,,y Dependent,.6573,.1417,1.9920,.046
1571 ])
1572 AT_CLEANUP
1573
1574 AT_SETUP([CROSSTABS uncertainy coefficient])
1575 AT_DATA([uc.sps], [dnl
1576 * From http://groups.chass.utoronto.ca/pol242/5bMeasuringAssociation.htm.
1577 SET FORMAT=F8.3.
1578
1579 DATA LIST LIST NOTABLE/x y w.
1580 WEIGHT BY w.
1581 BEGIN DATA.
1582 1 1 416
1583 1 2 121
1584 2 1 335
1585 2 2 2
1586 3 1 112
1587 3 2 1
1588 END DATA.
1589 CROSSTABS x BY y/STATISTICS=LAMBDA UC/CELLS=NONE.
1590 ])
1591 AT_CHECK([pspp -O format=csv uc.sps], [0], [dnl
1592 Table: Summary.
1593 ,Cases,,,,,
1594 ,Valid,,Missing,,Total,
1595 ,N,Percent,N,Percent,N,Percent
1596 x * y,987.000,100.0%,.000,0.0%,987.000,100.0%
1597
1598 Table: Directional measures.
1599 Category,Statistic,Type,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
1600 Nominal by Nominal,Lambda,Symmetric,.000,.000,NaN,NaN
1601 ,,x Dependent,.000,.000,NaN,NaN
1602 ,,y Dependent,.000,.000,NaN,NaN
1603 ,Goodman and Kruskal tau,x Dependent,.076,,,.   @&t@
1604 ,,y Dependent,.108,,,.   @&t@
1605 ,Uncertainty Coefficient,Symmetric,.105,.012,,.   @&t@
1606 ,,x Dependent,.073,.009,7.890,.   @&t@
1607 ,,y Dependent,.184,.019,7.890,.   @&t@
1608 ])
1609 AT_CLEANUP
1610
1611
1612
1613 AT_SETUP([CROSSTABS barchart])
1614 AT_DATA([bc.sps], [dnl
1615 SET FORMAT=F8.3.
1616
1617 DATA LIST LIST NOTABLE /x (a20) y (f8) z (f8) w (f8) .
1618 BEGIN DATA.
1619 This  1  0 416
1620 That  2  0 121
1621 Other 2  0 335
1622 This  2  0 231
1623 That  3  0 112
1624 Other 4  0 130
1625 This  1  1 160
1626 That  2  1 211
1627 Other 2  1 352
1628 This  2  1 212
1629 That  3  1 121
1630 Other 4  1 101
1631 END DATA.
1632
1633 WEIGHT BY w.
1634
1635 CROSSTABS 
1636           /table x BY y BY z
1637           /table x BY y
1638           /barchart.
1639 ])
1640
1641 AT_CHECK([pspp -O format=txt -o xxx bc.sps], [0], [ignore])
1642
1643 AT_CHECK([test -e xxx-1.png], [0], [ignore])
1644 AT_CHECK([test -e xxx-2.png], [0], [ignore])
1645
1646 AT_CHECK([diff xxx-1.png xxx-2.png], [0], [ignore])
1647
1648 AT_CLEANUP