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