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