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