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