output: Introduce pivot tables.
[pspp] / tests / language / stats / means.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
17 AT_BANNER([MEANS procedure])
18
19 AT_SETUP([MEANS simple example])
20 AT_KEYWORDS([categorical categoricals])
21
22 AT_DATA([means-simple.sps], [dnl
23 SET FORMAT=F12.5.
24
25 data list notable list /score * factor *.
26 BEGIN DATA.
27 22 01
28 22 01
29 29 01
30 16 01
31 24 02
32 21 02
33 22 01
34 24 01
35 19 01
36 17 01
37 22 01
38 17 02
39 23 02
40 25 02
41 20 01
42 15 01
43 18 01
44 26 01
45 23 02
46 35 02
47 20 01
48 16 01
49 19 01
50 14 01
51 14 01
52 21 01
53 END DATA.
54
55 MEANS TABLES = score BY factor.
56 ])
57
58 AT_CHECK([pspp -O format=csv means-simple.sps], [0],
59   [dnl
60 Table: Case Processing Summary
61 ,Cases,,,,,
62 ,Included,,Excluded,,Total,
63 ,N,Percent,N,Percent,N,Percent
64 score: factor,26,100.0%,0,.0%,26,100.0%
65 score: ,26,100.0%,0,.0%,26,100.0%
66
67 Table: Report
68 ,factor,Mean,N,Std. Deviation
69 score,1.00000,19.78947,19.00000,4.03566
70 ,2.00000,24.00000,7.00000,5.50757
71
72 Table: Report
73 ,Mean,N,Std. Deviation
74 score,20.92308,26.00000,4.75750
75 ])
76
77 AT_CLEANUP
78
79
80
81 AT_SETUP([MEANS very simple example])
82 AT_KEYWORDS([categorical categoricals])
83
84 AT_DATA([means-vsimple.sps], [dnl
85 SET FORMAT=F12.5.
86
87 data list notable list /score.
88 begin data.
89 1
90 1
91 2
92 2
93 end data.
94
95 means tables = score.
96 ])
97
98 AT_CHECK([pspp -O format=csv means-vsimple.sps], [0],
99   [dnl
100 Table: Case Processing Summary
101 ,Cases,,,,,
102 ,Included,,Excluded,,Total,
103 ,N,Percent,N,Percent,N,Percent
104 score: ,4,100.0%,0,.0%,4,100.0%
105
106 Table: Report
107 ,Mean,N,Std. Deviation
108 score,1.50000,4.00000,.57735
109 ])
110
111 AT_CLEANUP
112
113
114
115
116 AT_SETUP([MEANS default missing])
117 AT_KEYWORDS([categorical categoricals])
118
119 AT_DATA([means-dmiss.sps], [dnl
120 SET FORMAT=F12.2.
121 data list notable list /a * g1 * g2 *.
122 begin data.
123 3 1 . 
124 4 1 11
125 3 1 21
126 6 2 21
127 2 2 31
128 . 2 31
129 8 2 31
130 7 2 31
131 end data.
132
133 MEANS TABLES = 
134       a BY g1 g2
135       BY g2
136       /cells = MEAN COUNT
137       .
138 ])
139
140 AT_CHECK([pspp -O format=csv means-dmiss.sps], [0],
141   [dnl
142 Table: Case Processing Summary
143 ,Cases,,,,,
144 ,Included,,Excluded,,Total,
145 ,N,Percent,N,Percent,N,Percent
146 a: g1 × g2,6,75.0%,2,25.0%,8,100.0%
147 a: g2,6,75.0%,2,25.0%,8,100.0%
148 a: ,7,87.5%,1,12.5%,8,100.0%
149
150 Table: Report
151 ,g1,g2,Mean,N
152 a,1.00,11.00,4.00,1.00
153 ,,21.00,3.00,1.00
154 ,2.00,,6.00,1.00
155 ,,31.00,5.67,3.00
156
157 Table: Report
158 ,g2,Mean,N
159 a,11.00,4.00,1.00
160 ,21.00,4.50,2.00
161 ,31.00,5.67,3.00
162
163 Table: Report
164 ,Mean,N
165 a,5.00,6.00
166 ])
167
168 AT_CLEANUP
169
170
171 AT_SETUP([MEANS linear stats])
172 AT_KEYWORDS([categorical categoricals])
173
174 dnl Slightly more involved example to test the linear statistics
175 AT_DATA([means-linear.sps], [dnl
176 set format F12.4.
177 data list notable list /id * group * test1 *
178 begin data.
179 1 1 85
180 2 1 90
181 3 1 82
182 4 1 75
183 5 1 99
184 6 2 70
185 7 2 66
186 8 2 52
187 9 2 71
188 10 2 50
189 end data.
190
191 add value labels /group 1 "experimental group" 2 "control group".
192
193 means test1 by group
194   /cells = mean count stddev sum min max range variance kurt skew
195   .
196 ])
197
198
199 AT_CHECK([pspp -O format=csv means-linear.sps], [0],
200   [dnl
201 Table: Case Processing Summary
202 ,Cases,,,,,
203 ,Included,,Excluded,,Total,
204 ,N,Percent,N,Percent,N,Percent
205 test1: group,10,100.0%,0,.0%,10,100.0%
206 test1: ,10,100.0%,0,.0%,10,100.0%
207
208 Table: Report
209 ,group,Mean,N,Std. Deviation,Sum,Min,Max,Range,Variance,Kurtosis,Skewness
210 test1,experimental group,86.2000,5.0000,8.9833,431.0000,75.0000,99.0000,24.0000,80.7000,.2727,.3858
211 ,control group,61.8000,5.0000,10.0598,309.0000,50.0000,71.0000,21.0000,101.2000,-3.0437,-.4830
212
213 Table: Report
214 ,Mean,N,Std. Deviation,Sum,Min,Max,Range,Variance,Kurtosis,Skewness
215 test1,74.0000,10.0000,15.6915,740.0000,50.0000,99.0000,49.0000,246.2222,-.5759,-.1262
216 ])
217
218 AT_CLEANUP
219
220
221 AT_SETUP([MEANS standard errors])
222 AT_KEYWORDS([categorical categoricals])
223
224 AT_DATA([means-stderr.sps], [dnl
225 set format F12.4.
226 data list notable list /id * group * test1 *
227 begin data.
228 1 1 85
229 2 1 90
230 3 1 82
231 4 1 75
232 5 1 99
233 6 1 70
234 7 2 66
235 8 2 52
236 9 2 71
237 10 2 50
238 end data.
239
240 means test1 by group 
241         /cells = mean count semean seskew sekurt.
242 ])
243
244
245 AT_CHECK([pspp -O format=csv means-stderr.sps], [0],
246   [dnl
247 Table: Case Processing Summary
248 ,Cases,,,,,
249 ,Included,,Excluded,,Total,
250 ,N,Percent,N,Percent,N,Percent
251 test1: group,10,100.0%,0,.0%,10,100.0%
252 test1: ,10,100.0%,0,.0%,10,100.0%
253
254 Table: Report
255 ,group,Mean,N,S.E. Mean,S.E. Skew,S.E. Kurt
256 test1,1.0000,83.5000,6.0000,4.2485,.8452,1.7408
257 ,2.0000,59.7500,4.0000,5.1700,1.0142,2.6186
258
259 Table: Report
260 ,Mean,N,S.E. Mean,S.E. Skew,S.E. Kurt
261 test1,74.0000,10.0000,4.9621,.6870,1.3342
262 ])
263
264 AT_CLEANUP
265
266
267
268 AT_SETUP([MEANS harmonic and geometric means])
269 AT_KEYWORDS([categorical categoricals])
270
271 AT_DATA([means-hg.sps], [dnl
272 set format F12.4.
273 data list notable list /x * y *.
274 begin data.
275 1 3
276 2 3
277 3 3
278 4 3
279 5 3
280 end data.
281
282
283 means x y
284         /cells = mean harmonic geometric
285 .
286 ])
287
288
289 AT_CHECK([pspp -O format=csv means-hg.sps], [0],
290   [dnl
291 Table: Case Processing Summary
292 ,Cases,,,,,
293 ,Included,,Excluded,,Total,
294 ,N,Percent,N,Percent,N,Percent
295 x: ,5,100.0%,0,.0%,5,100.0%
296 y: ,5,100.0%,0,.0%,5,100.0%
297
298 Table: Report
299 ,Mean,Harmonic Mean,Geom. Mean
300 x,3.0000,2.1898,2.6052
301 y,3.0000,3.0000,3.0000
302 ])
303
304 AT_CLEANUP
305
306
307
308
309
310
311 AT_SETUP([MEANS all/none/default])
312 AT_KEYWORDS([categorical categoricals])
313
314 dnl Make sure that /CELLS = {ALL,NONE,DEFAULT} work properly
315 AT_DATA([means-stat-keywords.sps], [dnl
316 SET FORMAT=F12.2.
317 SET DECIMAL=DOT.
318
319 DATA LIST NOTABLE LIST /score *.
320 BEGIN DATA.
321 22
322 22
323 29
324 16
325 23
326 END DATA.
327
328 MEANS score /CELLS = ALL.
329 MEANS score /CELLS = DEFAULT.
330 MEANS score /CELLS = NONE.
331 ])
332
333
334 AT_CHECK([pspp -O format=csv means-stat-keywords.sps], [0],
335   [dnl
336 Table: Case Processing Summary
337 ,Cases,,,,,
338 ,Included,,Excluded,,Total,
339 ,N,Percent,N,Percent,N,Percent
340 score: ,5,100.0%,0,.0%,5,100.0%
341
342 Table: Report
343 ,Mean,N,Std. Deviation,S.E. Mean,Sum,Min,Max,Range,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,First,Last,Harmonic Mean,Geom. Mean
344 score,22.40,5.00,4.62,2.06,112.00,16.00,29.00,13.00,21.30,1.85,2.00,.11,.91,22.00,23.00,21.61,22.01
345
346 Table: Case Processing Summary
347 ,Cases,,,,,
348 ,Included,,Excluded,,Total,
349 ,N,Percent,N,Percent,N,Percent
350 score: ,5,100.0%,0,.0%,5,100.0%
351
352 Table: Report
353 ,Mean,N,Std. Deviation
354 score,22.40,5.00,4.62
355
356 Table: Case Processing Summary
357 ,Cases,,,,,
358 ,Included,,Excluded,,Total,
359 ,N,Percent,N,Percent,N,Percent
360 score: ,5,100.0%,0,.0%,5,100.0%
361
362 Table: Report
363 ])
364
365 AT_CLEANUP
366
367
368
369
370 AT_SETUP([MEANS missing=table ])
371 AT_KEYWORDS([categorical categoricals])
372
373 AT_DATA([means-miss-table.sps], [dnl
374 data list notable list /a * b * g1.
375 begin data.
376 1 9 1  
377 2 9 1 
378 3 9 1 
379 4 9 2 
380 5 9 2 
381 6 9 2 
382 7 . 2 
383 end data.
384
385 MEANS a b BY g1
386       /a  BY g1
387       /cells =  COUNT
388       /missing = TABLE
389       .
390
391 MEANS a b BY g1
392       /a  BY g1
393       /cells =  COUNT
394       .
395 ])
396
397
398 AT_CHECK([pspp -o pspp.csv -o pspp.txt means-miss-table.sps])
399 AT_CHECK([cat pspp.csv], [0], [dnl
400 Table: Case Processing Summary
401 ,Cases,,,,,
402 ,Included,,Excluded,,Total,
403 ,N,Percent,N,Percent,N,Percent
404 a: g1,7,100.0%,0,.0%,7,100.0%
405 a: ,7,100.0%,0,.0%,7,100.0%
406 b: g1,6,85.7%,1,14.3%,7,100.0%
407 b: ,6,85.7%,1,14.3%,7,100.0%
408
409 Table: Report
410 ,g1,N
411 a,1.00,3.00
412 ,2.00,3.00
413 b,1.00,3.00
414 ,2.00,3.00
415
416 Table: Report
417 ,N
418 a,6.00
419 b,6.00
420
421 Table: Case Processing Summary
422 ,Cases,,,,,
423 ,Included,,Excluded,,Total,
424 ,N,Percent,N,Percent,N,Percent
425 a: g1,7,100.0%,0,.0%,7,100.0%
426 a: ,7,100.0%,0,.0%,7,100.0%
427
428 Table: Report
429 ,g1,N
430 a,1.00,3.00
431 ,2.00,4.00
432
433 Table: Report
434 ,N
435 a,7.00
436
437 Table: Case Processing Summary
438 ,Cases,,,,,
439 ,Included,,Excluded,,Total,
440 ,N,Percent,N,Percent,N,Percent
441 a: g1,7,100.0%,0,.0%,7,100.0%
442 a: ,7,100.0%,0,.0%,7,100.0%
443 b: g1,6,85.7%,1,14.3%,7,100.0%
444 b: ,6,85.7%,1,14.3%,7,100.0%
445
446 Table: Report
447 ,g1,N
448 a,1.00,3.00
449 ,2.00,4.00
450 b,1.00,3.00
451 ,2.00,3.00
452
453 Table: Report
454 ,N
455 a,7.00
456 b,6.00
457
458 Table: Case Processing Summary
459 ,Cases,,,,,
460 ,Included,,Excluded,,Total,
461 ,N,Percent,N,Percent,N,Percent
462 a: g1,7,100.0%,0,.0%,7,100.0%
463 a: ,7,100.0%,0,.0%,7,100.0%
464
465 Table: Report
466 ,g1,N
467 a,1.00,3.00
468 ,2.00,4.00
469
470 Table: Report
471 ,N
472 a,7.00
473 ])
474 AT_CLEANUP
475
476 AT_SETUP([MEANS user missing values])
477 AT_KEYWORDS([categorical categoricals])
478
479 AT_DATA([means-missing.sps], [dnl
480 data list notable list /a * b * g1.
481 begin data.
482 1 2 9  
483 2 2 1 
484 3 2 1 
485 4 2 2 
486 5 2 2 
487 6 2 2 
488 7 9 2 
489 end data.
490
491 MISSING VALUES a b g1 (9).
492
493 MEANS a b BY g1 /cells =  COUNT .
494
495 MEANS a b BY g1 /cells =  COUNT /missing = include .
496
497 MEANS a b BY g1 /cells =  COUNT /missing = dependent .
498 ])
499
500
501 AT_CHECK([pspp -o pspp.csv -o pspp.txt means-missing.sps])
502 AT_CHECK([cat pspp.csv], [0], [dnl
503 Table: Case Processing Summary
504 ,Cases,,,,,
505 ,Included,,Excluded,,Total,
506 ,N,Percent,N,Percent,N,Percent
507 a: g1,6,85.7%,1,14.3%,7,100.0%
508 a: ,7,100.0%,0,.0%,7,100.0%
509 b: g1,5,71.4%,2,28.6%,7,100.0%
510 b: ,6,85.7%,1,14.3%,7,100.0%
511
512 Table: Report
513 ,g1,N
514 a,1.00,2.00
515 ,2.00,4.00
516 b,1.00,2.00
517 ,2.00,3.00
518
519 Table: Report
520 ,N
521 a,6.00
522 b,5.00
523
524 Table: Case Processing Summary
525 ,Cases,,,,,
526 ,Included,,Excluded,,Total,
527 ,N,Percent,N,Percent,N,Percent
528 a: g1,7,100.0%,0,.0%,7,100.0%
529 a: ,7,100.0%,0,.0%,7,100.0%
530 b: g1,7,100.0%,0,.0%,7,100.0%
531 b: ,7,100.0%,0,.0%,7,100.0%
532
533 Table: Report
534 ,g1,N
535 a,1.00,2.00
536 ,2.00,4.00
537 ,9.00,1.00
538 b,1.00,2.00
539 ,2.00,4.00
540 ,9.00,1.00
541
542 Table: Report
543 ,N
544 a,7.00
545 b,7.00
546
547 Table: Case Processing Summary
548 ,Cases,,,,,
549 ,Included,,Excluded,,Total,
550 ,N,Percent,N,Percent,N,Percent
551 a: g1,7,100.0%,0,.0%,7,100.0%
552 a: ,7,100.0%,0,.0%,7,100.0%
553 b: g1,6,85.7%,1,14.3%,7,100.0%
554 b: ,6,85.7%,1,14.3%,7,100.0%
555
556 Table: Report
557 ,g1,N
558 a,1.00,2.00
559 ,2.00,4.00
560 ,9.00,1.00
561 b,1.00,2.00
562 ,2.00,3.00
563 ,9.00,1.00
564
565 Table: Report
566 ,N
567 a,7.00
568 b,6.00
569 ])
570 AT_CLEANUP
571
572
573
574 AT_SETUP([MEANS empty factor spec])
575 AT_KEYWORDS([categorical categoricals])
576
577 AT_DATA([means-bad.sps], [dnl
578 data list list /outcome *.
579 begin data.
580 1
581 2
582 3
583 end data.
584
585 MEANS TABLES =  outcome 
586         BY.
587 ])
588
589 AT_CHECK([pspp -O format=csv means-bad.sps], [1], [ignore])
590
591 AT_CLEANUP
592
593
594
595 AT_SETUP([MEANS parser bug])
596 AT_KEYWORDS([categorical categoricals])
597
598 dnl This bug caused an infinite loop
599 AT_DATA([means-bad.sps], [dnl
600 DATA LIST notable LIST /a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 fylo *.
601 begin data.
602 1 2 3 4 5 6 7 8 9 0 11
603 end data.
604
605 MEANS TABLES = a1 a2 a3 a4 a5 a6 a7 a8 a9 a10a BY fylo.
606 ])
607
608 AT_CHECK([pspp -O format=csv means-bad.sps], [1], [ignore])
609
610 AT_CLEANUP
611
612
613
614