Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / descriptives.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([DESCRIPTIVES procedure])
18
19 AT_SETUP([DESCRIPTIVES basics])
20 AT_DATA([descriptives.sps],
21   [title 'Test DESCRIPTIVES procedure'.
22
23 data list / V0 to V16 1-17.
24 begin data.
25 12128989012389023
26 34128080123890128
27 56127781237893217
28 78127378123793112
29 90913781237892318
30 37978547878935789
31 52878237892378279
32 12377912789378932
33 26787654347894348
34 29137178947891888
35 end data.
36
37 descript all/stat=all/format=serial.
38 ])
39 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
40 Table: Reading 1 record from INLINE.
41 Variable,Record,Columns,Format
42 V0,1,1-1,F1.0
43 V1,1,2-2,F1.0
44 V2,1,3-3,F1.0
45 V3,1,4-4,F1.0
46 V4,1,5-5,F1.0
47 V5,1,6-6,F1.0
48 V6,1,7-7,F1.0
49 V7,1,8-8,F1.0
50 V8,1,9-9,F1.0
51 V9,1,10-10,F1.0
52 V10,1,11-11,F1.0
53 V11,1,12-12,F1.0
54 V12,1,13-13,F1.0
55 V13,1,14-14,F1.0
56 V14,1,15-15,F1.0
57 V15,1,16-16,F1.0
58 V16,1,17-17,F1.0
59
60 Table: Descriptive Statistics
61 ,N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
62 V0,10,3.80,.84,2.66,7.07,-.03,1.33,.89,.69,8.00,1,9,38.00
63 V1,10,4.60,.96,3.03,9.16,-1.39,1.33,-.03,.69,9.00,0,9,46.00
64 V2,10,4.10,1.16,3.67,13.43,-2.02,1.33,.48,.69,8.00,1,9,41.00
65 V3,10,4.10,.87,2.77,7.66,-2.05,1.33,.42,.69,7.00,1,8,41.00
66 V4,10,7.00,.47,1.49,2.22,7.15,1.33,-2.52,.69,5.00,3,8,70.00
67 V5,10,4.90,1.03,3.25,10.54,-1.40,1.33,-.20,.69,9.00,0,9,49.00
68 V6,10,5.90,.80,2.51,6.32,-.29,1.33,-.96,.69,7.00,1,8,59.00
69 V7,10,4.70,1.10,3.47,12.01,-1.99,1.33,-.16,.69,9.00,0,9,47.00
70 V8,10,4.10,1.10,3.48,12.10,-1.93,1.33,.37,.69,9.00,0,9,41.00
71 V9,10,4.30,.87,2.75,7.57,-.87,1.33,.73,.69,8.00,1,9,43.00
72 V10,10,5.50,.85,2.68,7.17,-1.84,1.33,-.33,.69,7.00,2,9,55.00
73 V11,10,6.50,.78,2.46,6.06,-1.28,1.33,-.89,.69,6.00,3,9,65.00
74 V12,10,7.90,.60,1.91,3.66,5.24,1.33,-2.21,.69,6.00,3,9,79.00
75 V13,10,4.30,.99,3.13,9.79,-1.25,1.33,.33,.69,9.00,0,9,43.00
76 V14,10,3.60,1.01,3.20,10.27,-.96,1.33,.81,.69,9.00,0,9,36.00
77 V15,10,3.70,.92,2.91,8.46,-1.35,1.33,.71,.69,7.00,1,8,37.00
78 V16,10,6.40,.91,2.88,8.27,-1.14,1.33,-.92,.69,7.00,2,9,64.00
79 Valid N (listwise),10,,,,,,,,,,,,
80 Missing N (listwise),0,,,,,,,,,,,,
81 ])
82 AT_CLEANUP
83
84 m4_define([DESCRIPTIVES_MISSING_DATA],
85   [data list notable / V1 TO V3 1-3.
86 mis val v1 to v3 (1).
87 begin data.
88 111
89
90  1
91 1 1
92 112
93 123
94 234
95 end data.
96 ])
97
98 AT_SETUP([DESCRIPTIVES -- excluding missing data])
99 AT_DATA([descriptives.sps],
100   [DESCRIPTIVES_MISSING_DATA
101 descript all/stat=all/format=serial.
102 ])
103 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
104 Table: Descriptive Statistics
105 ,N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
106 V1,1,2.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,2,2,2.00
107 V2,2,2.50,.50,.71,.50,.  ,.  ,.  ,.  ,1.00,2,3,5.00
108 V3,3,3.00,.58,1.00,1.00,.  ,.  ,.00,1.22,2.00,2,4,9.00
109 Valid N (listwise),7,,,,,,,,,,,,
110 Missing N (listwise),6,,,,,,,,,,,,
111 ])
112 AT_CLEANUP
113
114 AT_SETUP([DESCRIPTIVES -- including missing data])
115 AT_DATA([descriptives.sps],
116   [DESCRIPTIVES_MISSING_DATA
117 descript all/stat=all/format=serial/missing=include.
118 ])
119 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
120 Table: Descriptive Statistics
121 ,N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
122 V1,5,1.20,.20,.45,.20,5.00,2.00,2.24,.91,1.00,1,2,6.00
123 V2,5,1.60,.40,.89,.80,.31,2.00,1.26,.91,2.00,1,3,8.00
124 V3,5,2.20,.58,1.30,1.70,-1.49,2.00,.54,.91,3.00,1,4,11.00
125 Valid N (listwise),7,,,,,,,,,,,,
126 Missing N (listwise),3,,,,,,,,,,,,
127 ])
128 AT_CLEANUP
129
130 AT_SETUP([DESCRIPTIVES -- excluding missing data listwise])
131 AT_DATA([descriptives.sps],
132   [DESCRIPTIVES_MISSING_DATA
133 descript all/stat=all/format=serial/missing=listwise.
134 ])
135 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
136 Table: Descriptive Statistics
137 ,N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
138 V1,1,2.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,2,2,2.00
139 V2,1,3.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,3,3,3.00
140 V3,1,4.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,4,4,4.00
141 Valid N (listwise),1,,,,,,,,,,,,
142 Missing N (listwise),6,,,,,,,,,,,,
143 ])
144 AT_CLEANUP
145
146 AT_SETUP([DESCRIPTIVES -- including missing data listwise])
147 AT_DATA([descriptives.sps],
148   [DESCRIPTIVES_MISSING_DATA
149 descript all/stat=all/format=serial/missing=listwise include.
150 ])
151 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
152 Table: Descriptive Statistics
153 ,N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
154 V1,4,1.25,.25,.50,.25,4.00,2.62,2.00,1.01,1.00,1,2,5.00
155 V2,4,1.75,.48,.96,.92,-1.29,2.62,.85,1.01,2.00,1,3,7.00
156 V3,4,2.50,.65,1.29,1.67,-1.20,2.62,.00,1.01,3.00,1,4,10.00
157 Valid N (listwise),4,,,,,,,,,,,,
158 Missing N (listwise),3,,,,,,,,,,,,
159 ])
160 AT_CLEANUP
161
162 AT_SETUP([DESCRIPTIVES bug calculating mean only])
163 AT_DATA([descriptives.sps],
164   [SET FORMAT F8.3.
165
166 data list notable / X 1.
167 begin data.
168 0
169 1
170 2
171 3
172 4
173 5
174 end data.
175
176 descript all/stat=mean.
177 ])
178 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
179 Table: Descriptive Statistics
180 ,N,Mean
181 X,6,2.500
182 Valid N (listwise),6,
183 Missing N (listwise),0,
184 ])
185 AT_CLEANUP
186
187 dnl Git history shows that this was probably a bug in the PSPP
188 dnl core regarding multipass procedures, not anything specific
189 dnl to DESCRIPTIVES.
190 AT_SETUP([DESCRIPTIVES bug with TEMPORARY])
191 AT_DATA([descriptives.sps], [dnl
192 DATA LIST LIST NOTABLE /id * abc *.
193 BEGIN DATA.
194 1 3.5
195 2 2.0
196 3 2.0
197 4 3.5
198 5 3.0
199 6 4.0
200 7 5.0
201 END DATA.
202
203 TEMPORARY.
204 SELECT IF id < 7 .
205
206 DESCRIPTIVES /VAR=abc.
207 ])
208 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
209 Table: Descriptive Statistics
210 ,N,Mean,Std Dev,Minimum,Maximum
211 abc,6,3.00,.84,2.00,4.00
212 Valid N (listwise),6,,,,
213 Missing N (listwise),0,,,,
214 ])
215 AT_CLEANUP
216
217 AT_SETUP([DESCRIPTIVES -- Z scores])
218 AT_DATA([descriptives.sps], [dnl
219 DATA LIST LIST NOTABLE /a b.
220 BEGIN DATA.
221 1 50
222 2 60
223 3 70
224 END DATA.
225
226 DESCRIPTIVES /VAR=a b /SAVE.
227 LIST.
228 ])
229 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
230 Table: Mapping of Variables to Z-scores
231 Source,Target
232 a,Za
233 b,Zb
234
235 Table: Descriptive Statistics
236 ,N,Mean,Std Dev,Minimum,Maximum
237 a,3,2.00,1.00,1.00,3.00
238 b,3,60.00,10.00,50.00,70.00
239 Valid N (listwise),3,,,,
240 Missing N (listwise),0,,,,
241
242 Table: Data List
243 a,b,Za,Zb
244 1.00,50.00,-1.00,-1.00
245 2.00,60.00,.00,.00
246 3.00,70.00,1.00,1.00
247 ])
248 AT_CLEANUP
249
250 AT_SETUP([DESCRIPTIVES -- Z scores with SPLIT FILE])
251 AT_DATA([descriptives.sps], [dnl
252 DATA LIST LIST NOTABLE /group a b.
253 BEGIN DATA.
254 1 1 50
255 1 2 60
256 1 3 70
257 2 100 6000
258 2 200 7000
259 2 400 9000
260 2 500 10000
261 END DATA.
262
263 SPLIT FILE BY group.
264 DESCRIPTIVES /VAR=a b /SAVE.
265 LIST.
266 ])
267 AT_CHECK([pspp -o pspp.csv -o pspp.txt descriptives.sps])
268 AT_CHECK([cat pspp.csv], [0], [dnl
269 Table: Mapping of Variables to Z-scores
270 Source,Target
271 a,Za
272 b,Zb
273
274 Table: Split Values
275 Variable,Value
276 group,1.00
277
278 Table: Descriptive Statistics
279 ,N,Mean,Std Dev,Minimum,Maximum
280 a,3,2.00,1.00,1.00,3.00
281 b,3,60.00,10.00,50.00,70.00
282 Valid N (listwise),3,,,,
283 Missing N (listwise),0,,,,
284
285 Table: Split Values
286 Variable,Value
287 group,2.00
288
289 Table: Descriptive Statistics
290 ,N,Mean,Std Dev,Minimum,Maximum
291 a,4,300.00,182.57,100.00,500.00
292 b,4,8000.00,1825.74,6000.00,10000.00
293 Valid N (listwise),4,,,,
294 Missing N (listwise),0,,,,
295
296 Table: Split Values
297 Variable,Value
298 group,1.00
299
300 Table: Data List
301 group,a,b,Za,Zb
302 1.00,1.00,50.00,-1.00,-1.00
303 1.00,2.00,60.00,.00,.00
304 1.00,3.00,70.00,1.00,1.00
305
306 Table: Split Values
307 Variable,Value
308 group,2.00
309
310 Table: Data List
311 group,a,b,Za,Zb
312 2.00,100.00,6000.00,-1.10,-1.10
313 2.00,200.00,7000.00,-.55,-.55
314 2.00,400.00,9000.00,.55,.55
315 2.00,500.00,10000.00,1.10,1.10
316 ])
317 AT_CLEANUP
318
319 dnl Ideally DESCRIPTIVES would not make temporary transformations permanent
320 dnl as it does now (bug #38786), so these results are imperfect.  However,
321 dnl this test does verify that DESCRIPTIVES does not crash in this situation
322 dnl (as it once did).
323 AT_SETUP([DESCRIPTIVES -- Z scores bug with TEMPORARY])
324 AT_DATA([descriptives.sps], [dnl
325 DATA LIST LIST NOTABLE /id abc.
326 BEGIN DATA.
327 1 3.5
328 2 2.0
329 3 2.0
330 4 3.5
331 5 3.0
332 6 4.0
333 7 5.0
334 END DATA.
335
336 TEMPORARY.
337 SELECT IF id < 7 .
338
339 DESCRIPTIVES /VAR=abc/SAVE.
340 LIST.
341 ])
342 AT_CHECK([pspp -o pspp.csv -o pspp.txt descriptives.sps], [0], [dnl
343 descriptives.sps:15.23-15.26: warning: DESCRIPTIVES: DESCRIPTIVES with Z scores ignores TEMPORARY.  Temporary transformations will be made permanent.
344    15 | DESCRIPTIVES /VAR=abc/SAVE.
345       |                       ^~~~
346 ])
347 AT_CHECK([cat pspp.csv], [0], [dnl
348 "descriptives.sps:15.23-15.26: warning: DESCRIPTIVES: DESCRIPTIVES with Z scores ignores TEMPORARY.  Temporary transformations will be made permanent.
349    15 | DESCRIPTIVES /VAR=abc/SAVE.
350       |                       ^~~~"
351
352 Table: Mapping of Variables to Z-scores
353 Source,Target
354 abc,Zabc
355
356 Table: Descriptive Statistics
357 ,N,Mean,Std Dev,Minimum,Maximum
358 abc,6,3.00,.84,2.00,4.00
359 Valid N (listwise),6,,,,
360 Missing N (listwise),0,,,,
361
362 Table: Data List
363 id,abc,Zabc
364 1.00,3.50,.60
365 2.00,2.00,-1.20
366 3.00,2.00,-1.20
367 4.00,3.50,.60
368 5.00,3.00,.00
369 6.00,4.00,1.20
370 ])
371 AT_CLEANUP
372
373 dnl This test was supplied by Mindaugus as part of the report for bug #42012.
374 AT_SETUP([DESCRIPTIVES -- Z scores with FILTER])
375 AT_DATA([descriptives.sps], [dnl
376 DATA LIST LIST/filter1 filter2 x.
377 BEGIN DATA.
378 0,0,300
379 0,1,200
380 0,1,100
381 1,0,5
382 1,0,4
383 1,1,3
384 1,1,2
385 1,1,1
386 END DATA.
387
388 FILTER OFF.
389 SPLIT FILE OFF.
390 DESCRIPTIVES /VARIABLES=X /SAVE.
391
392 FILTER BY filter1.
393 SPLIT FILE OFF.
394 DESCRIPTIVES /VARIABLES=X /SAVE.
395
396 FILTER OFF.
397 SORT CASES BY filter1.
398 SPLIT FILE BY filter1.
399 DESCRIPTIVES /VARIABLES=X /SAVE.
400
401 FILTER BY filter2.
402 SPLIT FILE BY filter1.
403 DESCRIPTIVES /VARIABLES=X /SAVE.
404
405 FILTER OFF.
406 SORT CASES BY filter1 filter2.
407 SPLIT FILE BY filter1 filter2.
408 DESCRIPTIVES /VARIABLES=X /SAVE.
409 EXECUTE.
410
411 SPLIT FILE OFF.
412 LIST.
413 ])
414 AT_CHECK([pspp -o pspp.csv descriptives.sps])
415 AT_CHECK([sed -n '/Table: Data List/,$p' < pspp.csv], [0], [dnl
416 Table: Data List
417 filter1,filter2,x,Zx,ZSC001,ZSC002,ZSC003,ZSC004
418 .00,.00,300.00,1.94,.  ,1.00,.  ,.  @&t@
419 .00,1.00,200.00,1.07,.  ,.00,.71,.71
420 .00,1.00,100.00,.20,.  ,-1.00,-.71,-.71
421 1.00,.00,5.00,-.62,1.26,1.26,.  ,.71
422 1.00,.00,4.00,-.63,.63,.63,.  ,-.71
423 1.00,1.00,3.00,-.64,.00,.00,1.00,1.00
424 1.00,1.00,2.00,-.65,-.63,-.63,.00,.00
425 1.00,1.00,1.00,-.66,-1.26,-1.26,-1.00,-1.00
426 ])
427 AT_CLEANUP
428
429 dnl This is an example from doc/tutorial.texi
430 dnl So if the results of this have to be changed in any way,
431 dnl make sure to update that file.
432 AT_SETUP([DESCRIPTIVES tutorial example])
433 cp $top_srcdir/examples/physiology.sav .
434 AT_DATA([descriptives.sps], [dnl
435 GET FILE='physiology.sav'.
436 DESCRIPTIVES sex, weight, height.
437 ])
438 AT_CHECK([pspp -o pspp.csv -o pspp.txt descriptives.sps])
439 AT_CHECK([cat pspp.csv], [0], [dnl
440 Table: Descriptive Statistics
441 ,N,Mean,Std Dev,Minimum,Maximum
442 Sex of subject  ,40,.45,.50,Male,Female
443 Weight in kilograms ,40,72.12,26.70,-55.6,92.1
444 Height in millimeters   ,40,1677.12,262.87,179,1903
445 Valid N (listwise),40,,,,
446 Missing N (listwise),0,,,,
447 ])
448 AT_CLEANUP
449
450 AT_SETUP([DESCRIPTIVES syntax errors])
451 AT_DATA([descriptives.sps], [dnl
452 DATA LIST LIST NOTABLE /x y z.
453 DESCRIPTIVES MISSING=**.
454 DESCRIPTIVES FORMAT=**.
455 DESCRIPTIVES STATISTICS=**.
456 DESCRIPTIVES SORT=**.
457 DESCRIPTIVES SORT=NAME (**).
458 DESCRIPTIVES SORT=NAME (A **).
459 DESCRIPTIVES **.
460 DESCRIPTIVES x/ **.
461 DESCRIPTIVES MISSING=INCLUDE.
462 TEMPORARY.
463 NUMERIC Zx ZSC001 TO ZSC099 STDZ01 TO STDZ09 ZZZZ01 TO ZZZZ09 ZQZQ01 TO ZQZQ09.
464 DESCRIPTIVES x/SAVE.
465 ])
466 AT_CHECK([pspp descriptives.sps], [1], [dnl
467 descriptives.sps:2.22-2.23: error: DESCRIPTIVES: Syntax error expecting
468 VARIABLE, LISTWISE, or INCLUDE.
469     2 | DESCRIPTIVES MISSING=**.
470       |                      ^~
471
472 descriptives.sps:3.21-3.22: error: DESCRIPTIVES: Syntax error expecting LABELS,
473 NOLABELS, INDEX, NOINDEX, LINE, or SERIAL.
474     3 | DESCRIPTIVES FORMAT=**.
475       |                     ^~
476
477 descriptives.sps:5.19-5.20: error: DESCRIPTIVES: Syntax error expecting
478 variable name.
479     5 | DESCRIPTIVES SORT=**.
480       |                   ^~
481
482 descriptives.sps:6.25-6.26: error: DESCRIPTIVES: Syntax error expecting A or D.
483     6 | DESCRIPTIVES SORT=NAME (**).
484       |                         ^~
485
486 descriptives.sps:7.27-7.28: error: DESCRIPTIVES: Syntax error expecting `)'.
487     7 | DESCRIPTIVES SORT=NAME (A **).
488       |                           ^~
489
490 descriptives.sps:8.14-8.15: error: DESCRIPTIVES: Syntax error expecting
491 variable name.
492     8 | DESCRIPTIVES **.
493       |              ^~
494
495 descriptives.sps:9.17-9.18: error: DESCRIPTIVES: Syntax error expecting
496 MISSING, SAVE, FORMAT, STATISTICS, SORT, or VARIABLES.
497     9 | DESCRIPTIVES x/ **.
498       |                 ^~
499
500 descriptives.sps:10: error: DESCRIPTIVES: No variables specified.
501
502 descriptives.sps:13: error: DESCRIPTIVES: Ran out of generic names for Z-score
503 variables.  There are only 126 generic names: ZSC001-ZSC099, STDZ01-STDZ09,
504 ZZZZ01-ZZZZ09, ZQZQ01-ZQZQ09.
505 ])
506 AT_CLEANUP