d29e2e8df6124fc86e4b5d66352423557073fe39
[pspp] / tests / language / stats / rank.at
1 AT_BANNER([RANK])
2
3 AT_SETUP([RANK simple case with defaults])
4 AT_DATA([rank.sps], [dnl
5 DATA LIST LIST NOTABLE /x (f8).
6 BEGIN DATA.
7 -1
8
9
10
11
12
13
14 END DATA.
15
16 RANK x.
17
18 LIST.
19 ])
20 AT_CHECK([pspp -o pspp.csv rank.sps])
21 AT_CHECK([cat pspp.csv], [0], [dnl
22 Variables Created By RANK
23
24
25
26 x into Rx(RANK of x)
27
28 Table: Data List
29 x,Rx
30 -1,1.000
31 0,2.000
32 1,3.000
33 2,4.500
34 2,4.500
35 4,6.000
36 5,7.000
37 ])
38 AT_CLEANUP
39
40 # This checks for regression against a crash reported as bug #38482
41 # that occurred when multiple variables were specified without any
42 # rank specifications.
43 AT_SETUP([RANK multiple variables with defaults])
44 AT_DATA([rank.sps], [dnl
45 DATA LIST LIST NOTABLE /x * y * z *.
46 BEGIN DATA.
47     1.00     2.00     3.00
48     4.00     5.00     6.00
49 END DATA.
50
51 RANK ALL.
52
53 LIST.
54 ])
55 AT_CHECK([pspp -o pspp.csv rank.sps])
56 AT_CHECK([cat pspp.csv], [0], [dnl
57 Variables Created By RANK
58
59
60
61 x into Rx(RANK of x)
62
63 y into Ry(RANK of y)
64
65 z into Rz(RANK of z)
66
67 Table: Data List
68 x,y,z,Rx,Ry,Rz
69 1.00,2.00,3.00,1.000,1.000,1.000
70 4.00,5.00,6.00,2.000,2.000,2.000
71 ])
72 AT_CLEANUP
73
74 AT_SETUP([RANK with RANK, RFRACTION, N])
75 AT_DATA([rank.sps], [dnl
76 DATA LIST LIST NOTABLE /a * b *.
77 BEGIN DATA.
78 0 24
79 1 32
80 2 31
81 2 32
82 4 30
83 5 29
84 6 1
85 7 43
86 8 .
87 9 45
88 END DATA.
89
90 RANK a b (D)
91    /PRINT=YES 
92    /RANK
93    /TIES=HIGH
94    /RFRACTION
95    /N INTO count
96    .
97
98 DISPLAY DICTIONARY.
99
100 LIST.
101 ])
102 AT_CHECK([pspp -o pspp.csv rank.sps])
103 AT_CHECK([cat pspp.csv], [0], [dnl
104 Variables Created By RANK
105
106
107
108 a into Ra(RANK of a)
109
110 b into Rb(RANK of b)
111
112 a into RFR001(RFRACTION of a)
113
114 b into RFR002(RFRACTION of b)
115
116 a into count(N of a)
117
118 b into Nb(N of b)
119
120 Variable,Description,,Position
121 a,Format: F8.2,,1
122 ,Measure: Scale,,
123 ,Display Alignment: Right,,
124 ,Display Width: 8,,
125 b,Format: F8.2,,2
126 ,Measure: Scale,,
127 ,Display Alignment: Right,,
128 ,Display Width: 8,,
129 Ra,Label: RANK of a,,3
130 ,Format: F9.3,,
131 ,Measure: Scale,,
132 ,Display Alignment: Right,,
133 ,Display Width: 8,,
134 RFR001,Label: RFRACTION of a,,4
135 ,Format: F6.4,,
136 ,Measure: Scale,,
137 ,Display Alignment: Right,,
138 ,Display Width: 8,,
139 count,Label: N of a,,5
140 ,Format: F6.0,,
141 ,Measure: Scale,,
142 ,Display Alignment: Right,,
143 ,Display Width: 8,,
144 Rb,Label: RANK of b,,6
145 ,Format: F9.3,,
146 ,Measure: Scale,,
147 ,Display Alignment: Right,,
148 ,Display Width: 8,,
149 RFR002,Label: RFRACTION of b,,7
150 ,Format: F6.4,,
151 ,Measure: Scale,,
152 ,Display Alignment: Right,,
153 ,Display Width: 8,,
154 Nb,Label: N of b,,8
155 ,Format: F6.0,,
156 ,Measure: Scale,,
157 ,Display Alignment: Right,,
158 ,Display Width: 8,,
159
160 Table: Data List
161 a,b,Ra,RFR001,count,Rb,RFR002,Nb
162 .00,24.00,10.000,1.0000,10,8.000,.8889,9
163 1.00,32.00,9.000,.9000,10,4.000,.4444,9
164 2.00,31.00,8.000,.8000,10,5.000,.5556,9
165 2.00,32.00,8.000,.8000,10,4.000,.4444,9
166 4.00,30.00,6.000,.6000,10,6.000,.6667,9
167 5.00,29.00,5.000,.5000,10,7.000,.7778,9
168 6.00,1.00,4.000,.4000,10,9.000,1.0000,9
169 7.00,43.00,3.000,.3000,10,2.000,.2222,9
170 8.00,.  ,2.000,.2000,10,.   ,.    ,.
171 9.00,45.00,1.000,.1000,10,1.000,.1111,9
172 ])
173 AT_CLEANUP
174
175 AT_SETUP([RANK with SAVAGE, PERCENT, PROPORTION, NTILES])
176 AT_DATA([rank.sps], [dnl
177 DATA LIST LIST NOTABLE /a * b *.
178 BEGIN DATA.
179 0 24
180 1 32
181 2 31
182 2 32
183 4 30
184 5 29
185 6 1
186 7 43
187 8 8 
188 9 45
189 END DATA.
190
191 RANK a
192   /PRINT=YES
193   /TIES=CONDENSE
194   /SAVAGE
195   /PERCENT
196   /PROPORTION
197   /NTILES(4)
198   /NORMAL
199 .
200
201 LIST.
202 ])
203 AT_CHECK([pspp -o pspp.csv rank.sps])
204 AT_CHECK([cat pspp.csv], [0], [dnl
205 Variables Created By RANK
206
207
208
209 a into Sa(SAVAGE of a)
210
211 a into Pa(PERCENT of a)
212
213 a into PRO001(PROPORTION of a using BLOM)
214
215 a into Na(NTILES of a)
216
217 a into NOR001(NORMAL of a using BLOM)
218
219 Table: Data List
220 a,b,Sa,Pa,PRO001,Na,NOR001
221 .00,24.00,-.9000,10.00,.0610,1,-1.547
222 1.00,32.00,-.7889,20.00,.1585,1,-1.000
223 2.00,31.00,-.5925,30.00,.2561,2,-.6554
224 2.00,32.00,-.5925,30.00,.2561,2,-.6554
225 4.00,30.00,-.3544,40.00,.3537,2,-.3755
226 5.00,29.00,-.1544,50.00,.4512,2,-.1226
227 6.00,1.00,.0956,60.00,.5488,3,.1226
228 7.00,43.00,.4290,70.00,.6463,3,.3755
229 8.00,8.00,.9290,80.00,.7439,3,.6554
230 9.00,45.00,1.9290,90.00,.8415,4,1.0005
231 ])
232 AT_CLEANUP
233
234 AT_SETUP([RANK with SPLIT FILE])
235 AT_DATA([rank.sps], [dnl
236 DATA LIST LIST NOTABLE /a * g1 g2 *.
237 BEGIN DATA.
238 2 1 2
239 2 1 2
240 3 1 2
241 4 1 2
242 5 1 2
243 1 0 2
244 2 0 2
245 3 0 2
246 4 0 2
247 5 0 2
248 6 0 2
249 7 0 2
250 8 0 2
251 6 1 2
252 7 1 2
253 7 1 2
254 8 1 2
255 9 1 1
256 END DATA.
257
258 RANK a (D) BY g2 g1
259   /PRINT=YES
260   /TIES=LOW
261   /MISSING=INCLUDE
262   /FRACTION=RANKIT
263   /RANK
264   /NORMAL
265   .
266
267 SPLIT FILE BY g1.
268
269 RANK a (D) BY g2
270   /PRINT=YES
271   /TIES=LOW
272   /MISSING=INCLUDE
273   /FRACTION=RANKIT
274   /RANK
275   /NORMAL
276   .
277
278 SPLIT FILE OFF.
279
280 LIST.
281 ])
282 AT_CHECK([pspp -o pspp.csv rank.sps])
283 AT_CHECK([cat pspp.csv], [0], [dnl
284 Variables Created By RANK
285
286
287
288 a into Ra(RANK of a BY g2 g1)
289
290 a into Na(NORMAL of a using RANKIT BY g2 g1)
291
292 Variables Created By RANK
293
294
295
296 a into RAN001(RANK of a BY g2)
297
298 a into NOR001(NORMAL of a using RANKIT BY g2)
299
300 Table: Data List
301 a,g1,g2,Ra,Na,RAN001,NOR001
302 2.00,1.00,2.00,8.000,.9674,4.000,.5244
303 2.00,1.00,2.00,8.000,.9674,4.000,.5244
304 3.00,1.00,2.00,7.000,.5895,3.000,.0000
305 4.00,1.00,2.00,6.000,.2822,2.000,-.5244
306 5.00,1.00,2.00,5.000,.0000,1.000,-1.282
307 1.00,.00,2.00,8.000,1.5341,8.000,1.5341
308 2.00,.00,2.00,7.000,.8871,7.000,.8871
309 3.00,.00,2.00,6.000,.4888,6.000,.4888
310 4.00,.00,2.00,5.000,.1573,5.000,.1573
311 5.00,.00,2.00,4.000,-.1573,4.000,-.1573
312 6.00,.00,2.00,3.000,-.4888,3.000,-.4888
313 7.00,.00,2.00,2.000,-.8871,2.000,-.8871
314 8.00,.00,2.00,1.000,-1.534,1.000,-1.534
315 6.00,1.00,2.00,4.000,-.2822,4.000,1.1503
316 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
317 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
318 8.00,1.00,2.00,1.000,-1.593,1.000,-1.150
319 9.00,1.00,1.00,1.000,.0000,1.000,.0000
320 ])
321 AT_CLEANUP
322
323 # Also tests small ranks for special case of SAVAGE ranks.
324 AT_SETUP([RANK with fractional ranks]) 
325 AT_DATA([rank.sps], [dnl
326 DATA LIST LIST NOTABLE  /a *  w * .
327 BEGIN DATA.
328 1 1.5
329 2 0.2
330 3 0.1
331 4 1
332 5 1
333 6 1
334 7 1
335 8 1
336 END DATA.
337
338 WEIGHT BY w.
339
340 RANK a 
341   /FRACTION=TUKEY
342   /PROPORTION
343   /SAVAGE
344 .
345
346 LIST.
347 ])
348 AT_CHECK([pspp -o pspp.csv rank.sps])
349 AT_CHECK([cat pspp.csv], [0], [dnl
350 Variables Created By RANK
351
352
353
354 a into Pa(PROPORTION of a using TUKEY)
355
356 a into Sa(SAVAGE of a)
357
358 Table: Data List
359 a,w,Pa,Sa
360 1.00,1.50,.1285,-.8016
361 2.00,.20,.1776,-.6905
362 3.00,.10,.1986,-.6905
363 4.00,1.00,.3458,-.5305
364 5.00,1.00,.4860,-.2905
365 6.00,1.00,.6262,.0262
366 7.00,1.00,.7664,.4929
367 8.00,1.00,.9065,1.3929
368 ])
369 AT_CLEANUP
370
371 AT_SETUP([RANK all-ties due to tiny weights])
372 AT_DATA([rank.sps], [dnl
373 DATA LIST LIST NOTABLE /x * w *.
374 BEGIN DATA.
375 1 0.1
376 2 0.1
377 3 0.1
378 4 0.2
379 5 0.1
380 6 0.1
381 7 0.1
382 8 0.1
383 END DATA.
384
385 WEIGHT BY w.
386
387 RANK x
388  /TIES=low
389  /RANK into xl.
390
391
392 RANK x
393  /TIES=high
394  /RANK into xh.
395
396 RANK x
397  /TIES=condense
398  /RANK into xc.
399
400
401 * Test VW fraction
402
403 RANK x
404  /FRACTION=VW
405  /NORMAL.
406
407 LIST.
408 ])
409 AT_CHECK([pspp -o pspp.csv rank.sps])
410 AT_CHECK([cat pspp.csv], [0], [dnl
411 Variables Created By RANK
412
413
414
415 x into xl(RANK of x)
416
417 Variables Created By RANK
418
419
420
421 x into xh(RANK of x)
422
423 Variables Created By RANK
424
425
426
427 x into xc(RANK of x)
428
429 Variables Created By RANK
430
431
432
433 x into Nx(NORMAL of x using VW)
434
435 Table: Data List
436 x,w,xl,xh,xc,Nx
437 1.00,.10,.000,.100,1.000,-1.938
438 2.00,.10,.100,.200,2.000,-1.412
439 3.00,.10,.200,.300,3.000,-1.119
440 4.00,.20,.300,.500,4.000,-.8046
441 5.00,.10,.500,.600,5.000,-.5549
442 6.00,.10,.600,.700,6.000,-.4067
443 7.00,.10,.700,.800,7.000,-.2670
444 8.00,.10,.800,.900,8.000,-.1323
445 ])
446 AT_CLEANUP
447
448 AT_SETUP([RANK and TEMPORARY])
449 AT_DATA([rank.sps], [dnl
450 DATA LIST LIST NOTABLE /age (f2) gender (a1).
451 BEGIN DATA.
452 44 m
453 32 f
454 43 m
455 49 m
456 33 f
457 35 f
458 29 f
459 50 m
460 42 m
461 33 f
462 48 m
463 END DATA.
464
465 TEMPORARY.
466 SELECT IF gender = 'm'.
467 RANK age /RANK INTO Rm.
468
469 TEMPORARY.
470 SELECT IF gender = 'f'.
471 RANK age /RANK INTO Rf.
472
473 LIST.
474 ])
475 AT_CHECK([pspp -O format=csv rank.sps], [0], [dnl
476 Variables Created By RANK
477
478
479
480 age into Rm(RANK of age)
481
482 Variables Created By RANK
483
484
485
486 age into Rf(RANK of age)
487
488 Table: Data List
489 age,gender,Rm,Rf
490 44,m,3.000,.   @&t@
491 32,f,.   ,2.000
492 43,m,2.000,.   @&t@
493 49,m,5.000,.   @&t@
494 33,f,.   ,3.500
495 35,f,.   ,5.000
496 29,f,.   ,1.000
497 50,m,6.000,.   @&t@
498 42,m,1.000,.   @&t@
499 33,f,.   ,3.500
500 48,m,4.000,.   @&t@
501 ])
502 AT_CLEANUP
503
504 AT_SETUP([RANK variable name fallback])
505 AT_DATA([rank.sps], [dnl
506 DATA LIST LIST NOTABLE /foo * rfoo * ran003 *.
507 BEGIN DATA.
508 0 3 2
509 1 3 2
510 2 3 2
511 2 3 2
512 4 3 2
513 5 3 2
514 6 3 2
515 7 3 2
516 8 3 2
517 9 3 2
518 END DATA.
519
520 RANK foo.
521
522
523 DISPLAY DICTIONARY.
524 ])
525 AT_CHECK([pspp -o pspp.csv rank.sps])
526 AT_CHECK([cat pspp.csv], [0], [dnl
527 Variables Created By RANK
528
529
530
531 foo into RAN001(RANK of foo)
532
533 Variable,Description,,Position
534 foo,Format: F8.2,,1
535 ,Measure: Scale,,
536 ,Display Alignment: Right,,
537 ,Display Width: 8,,
538 rfoo,Format: F8.2,,2
539 ,Measure: Scale,,
540 ,Display Alignment: Right,,
541 ,Display Width: 8,,
542 ran003,Format: F8.2,,3
543 ,Measure: Scale,,
544 ,Display Alignment: Right,,
545 ,Display Width: 8,,
546 RAN001,Label: RANK of foo,,4
547 ,Format: F9.3,,
548 ,Measure: Scale,,
549 ,Display Alignment: Right,,
550 ,Display Width: 8,,
551 ])
552 AT_CLEANUP
553
554 AT_SETUP([RANK robust variable name creation])
555 AT_DATA([rank.sps], [dnl
556 DATA LIST LIST notable /x * rx * ran001 TO ran999.
557 BEGIN DATA.
558 1
559 2
560 3
561 4
562 5
563 6
564 7
565 END DATA.
566
567 RANK x.
568
569 DELETE VAR ran001 TO ran999.
570
571 LIST.
572 ])
573 AT_CHECK([pspp -O format=csv rank.sps], [0], [dnl
574 "rank.sps:3: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
575
576 "rank.sps:4: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
577
578 "rank.sps:5: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
579
580 "rank.sps:6: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
581
582 "rank.sps:7: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
583
584 "rank.sps:8: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
585
586 "rank.sps:9: warning: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
587
588 Variables Created By RANK
589
590
591
592 x into RNKRA01(RANK of x)
593
594 Table: Data List
595 x,rx,RNKRA01
596 1.00,.  ,1.000
597 2.00,.  ,2.000
598 3.00,.  ,3.000
599 4.00,.  ,4.000
600 5.00,.  ,5.000
601 6.00,.  ,6.000
602 7.00,.  ,7.000
603 ])
604 AT_CLEANUP
605
606 dnl Test for proper behaviour in the face of invalid input.
607 AT_SETUP([RANK handling of invalid input])
608 AT_DATA([rank.sps], [dnl
609 DATA LIST LIST NOTABLE /x * a (a2).
610 BEGIN DATA.
611 -1 s
612 0  s
613 1  s
614 2  s
615 2  s
616 4  s
617 5  s
618 END DATA.
619
620 DEBUG XFORM FAIL.
621
622 RANK x.
623 ])
624 AT_CHECK([pspp -O format=csv --testing-mode rank.sps], [1], [dnl
625 Variables Created By RANK
626
627
628
629 x into Rx(RANK of x)
630
631 rank.sps:14: error: RANK: DEBUG XFORM FAIL transformation executed
632 ])
633 AT_CLEANUP
634
635 AT_SETUP([RANK handling of invalid syntax])
636 AT_DATA([rank.sps], [dnl
637 DATA LIST LIST NOTABLE /x * a (a2).
638 BEGIN DATA.
639 -1 s
640 0  s
641 1  s
642 2  s
643 2  s
644 4  s
645 5  s
646 END DATA.
647
648 * invalid NTILES (no parameter)
649 RANK x 
650   /NTILES
651 .
652
653 * invalid NTILES (not an integer)
654 RANK x 
655   /NTILES(d)
656 .
657
658
659 * destination variable already exists
660 RANK x 
661  /RANK INTO x.
662
663
664 * Too many variables in INTO
665 RANK x 
666  /RANK INTO foo  bar wiz.
667 ])
668 AT_CHECK([pspp -O format=csv rank.sps], [1], [dnl
669 rank.sps:15.1: error: RANK: Syntax error at end of command: expecting `@{:@'.
670
671 rank.sps:19.11: error: RANK: Syntax error at `d': expecting integer.
672
673 rank.sps:25: error: RANK: Variable x already exists.
674
675 rank.sps:30: error: RANK: Too many variables in INTO clause.
676 ])
677 AT_CLEANUP