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