bc3bbb66d1ced6322116a9625feb53d2d2e3aab7
[pspp] / tests / language / stats / 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],
40   [Title: Test DESCRIPTIVES procedure
41
42 Table: Reading 1 record from INLINE.
43 Variable,Record,Columns,Format
44 V0,1,1-  1,F1.0
45 V1,1,2-  2,F1.0
46 V2,1,3-  3,F1.0
47 V3,1,4-  4,F1.0
48 V4,1,5-  5,F1.0
49 V5,1,6-  6,F1.0
50 V6,1,7-  7,F1.0
51 V7,1,8-  8,F1.0
52 V8,1,9-  9,F1.0
53 V9,1,10- 10,F1.0
54 V10,1,11- 11,F1.0
55 V11,1,12- 12,F1.0
56 V12,1,13- 13,F1.0
57 V13,1,14- 14,F1.0
58 V14,1,15- 15,F1.0
59 V15,1,16- 16,F1.0
60 V16,1,17- 17,F1.0
61
62 Table: Valid cases = 10; cases with missing value(s) = 0.
63 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
64 V0,10,0,3.80,.84,2.66,7.07,-.03,1.33,.89,.69,8.00,1.00,9.00,38.00
65 V1,10,0,4.60,.96,3.03,9.16,-1.39,1.33,-.03,.69,9.00,.00,9.00,46.00
66 V2,10,0,4.10,1.16,3.67,13.43,-2.02,1.33,.48,.69,8.00,1.00,9.00,41.00
67 V3,10,0,4.10,.87,2.77,7.66,-2.05,1.33,.42,.69,7.00,1.00,8.00,41.00
68 V4,10,0,7.00,.47,1.49,2.22,7.15,1.33,-2.52,.69,5.00,3.00,8.00,70.00
69 V5,10,0,4.90,1.03,3.25,10.54,-1.40,1.33,-.20,.69,9.00,.00,9.00,49.00
70 V6,10,0,5.90,.80,2.51,6.32,-.29,1.33,-.96,.69,7.00,1.00,8.00,59.00
71 V7,10,0,4.70,1.10,3.47,12.01,-1.99,1.33,-.16,.69,9.00,.00,9.00,47.00
72 V8,10,0,4.10,1.10,3.48,12.10,-1.93,1.33,.37,.69,9.00,.00,9.00,41.00
73 V9,10,0,4.30,.87,2.75,7.57,-.87,1.33,.73,.69,8.00,1.00,9.00,43.00
74 V10,10,0,5.50,.85,2.68,7.17,-1.84,1.33,-.33,.69,7.00,2.00,9.00,55.00
75 V11,10,0,6.50,.78,2.46,6.06,-1.28,1.33,-.89,.69,6.00,3.00,9.00,65.00
76 V12,10,0,7.90,.60,1.91,3.66,5.24,1.33,-2.21,.69,6.00,3.00,9.00,79.00
77 V13,10,0,4.30,.99,3.13,9.79,-1.25,1.33,.33,.69,9.00,.00,9.00,43.00
78 V14,10,0,3.60,1.01,3.20,10.27,-.96,1.33,.81,.69,9.00,.00,9.00,36.00
79 V15,10,0,3.70,.92,2.91,8.46,-1.35,1.33,.71,.69,7.00,1.00,8.00,37.00
80 V16,10,0,6.40,.91,2.88,8.27,-1.14,1.33,-.92,.69,7.00,2.00,9.00,64.00
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],
104   [Table: Valid cases = 7; cases with missing value(s) = 6.
105 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
106 V1,1,6,2.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,2.00,2.00,2.00
107 V2,2,5,2.50,.50,.71,.50,.  ,.  ,.  ,.  ,1.00,2.00,3.00,5.00
108 V3,3,4,3.00,.58,1.00,1.00,.  ,.  ,.00,1.22,2.00,2.00,4.00,9.00
109 ])
110 AT_CLEANUP
111
112 AT_SETUP([DESCRIPTIVES -- including missing data])
113 AT_DATA([descriptives.sps],
114   [DESCRIPTIVES_MISSING_DATA
115 descript all/stat=all/format=serial/missing=include.
116 ])
117 AT_CHECK([pspp -O format=csv descriptives.sps], [0],
118   [Table: Valid cases = 7; cases with missing value(s) = 3.
119 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
120 V1,5,2,1.20,.20,.45,.20,5.00,2.00,2.24,.91,1.00,1.00,2.00,6.00
121 V2,5,2,1.60,.40,.89,.80,.31,2.00,1.26,.91,2.00,1.00,3.00,8.00
122 V3,5,2,2.20,.58,1.30,1.70,-1.49,2.00,.54,.91,3.00,1.00,4.00,11.00
123 ])
124 AT_CLEANUP
125
126 AT_SETUP([DESCRIPTIVES -- excluding missing data listwise])
127 AT_DATA([descriptives.sps],
128   [DESCRIPTIVES_MISSING_DATA
129 descript all/stat=all/format=serial/missing=listwise.
130 ])
131 AT_CHECK([pspp -O format=csv descriptives.sps], [0],
132   [Table: Valid cases = 1; cases with missing value(s) = 6.
133 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
134 V1,1,0,2.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,2.00,2.00,2.00
135 V2,1,0,3.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,3.00,3.00,3.00
136 V3,1,0,4.00,.  ,.  ,.  ,.  ,.  ,.  ,.  ,.00,4.00,4.00,4.00
137 ])
138 AT_CLEANUP
139
140 AT_SETUP([DESCRIPTIVES -- including missing data listwise])
141 AT_DATA([descriptives.sps],
142   [DESCRIPTIVES_MISSING_DATA
143 descript all/stat=all/format=serial/missing=listwise include.
144 ])
145 AT_CHECK([pspp -O format=csv descriptives.sps], [0],
146   [Table: Valid cases = 4; cases with missing value(s) = 3.
147 Variable,Valid N,Missing N,Mean,S.E. Mean,Std Dev,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,Range,Minimum,Maximum,Sum
148 V1,4,0,1.25,.25,.50,.25,4.00,2.62,2.00,1.01,1.00,1.00,2.00,5.00
149 V2,4,0,1.75,.48,.96,.92,-1.29,2.62,.85,1.01,2.00,1.00,3.00,7.00
150 V3,4,0,2.50,.65,1.29,1.67,-1.20,2.62,.00,1.01,3.00,1.00,4.00,10.00
151 ])
152 AT_CLEANUP
153
154 AT_SETUP([DESCRIPTIVES bug calculating mean only])
155 AT_DATA([descriptives.sps],
156   [SET FORMAT F8.3.
157
158 data list notable / X 1.
159 begin data.
160 0
161 1
162 2
163 3
164 4
165 5
166 end data.
167
168 descript all/stat=mean.
169 ])
170 AT_CHECK([pspp -O format=csv descriptives.sps], [0],
171   [Table: Valid cases = 6; cases with missing value(s) = 0.
172 Variable,N,Mean
173 X,6,2.500
174 ])
175 AT_CLEANUP
176
177 dnl Git history shows that this was probably a bug in the PSPP
178 dnl core regarding multipass procedures, not anything specific
179 dnl to DESCRIPTIVES.
180 AT_SETUP([DESCRIPTIVES bug with TEMPORARY])
181 AT_DATA([descriptives.sps], [dnl
182 DATA LIST LIST NOTABLE /id * abc *.
183 BEGIN DATA.
184 1 3.5
185 2 2.0
186 3 2.0
187 4 3.5
188 5 3.0
189 6 4.0
190 7 5.0
191 END DATA.
192
193 TEMPORARY.
194 SELECT IF id < 7 .
195
196 DESCRIPTIVES /VAR=abc.
197 ])
198 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
199 Table: Valid cases = 6; cases with missing value(s) = 0.
200 Variable,N,Mean,Std Dev,Minimum,Maximum
201 abc,6,3.00,.84,2.00,4.00
202 ])
203 AT_CLEANUP
204
205 AT_SETUP([DESCRIPTIVES -- Z scores])
206 AT_DATA([descriptives.sps], [dnl
207 DATA LIST LIST NOTABLE /a b.
208 BEGIN DATA.
209 1 50
210 2 60
211 3 70
212 END DATA.
213
214 DESCRIPTIVES /VAR=a b /SAVE.
215 LIST.
216 ])
217 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
218 Table: Mapping of variables to corresponding Z-scores.
219 Source,Target
220 a,Za
221 b,Zb
222
223 Table: Valid cases = 3; cases with missing value(s) = 0.
224 Variable,N,Mean,Std Dev,Minimum,Maximum
225 a,3,2.00,1.00,1.00,3.00
226 b,3,60.00,10.00,50.00,70.00
227
228 Table: Data List
229 a,b,Za,Zb
230 1.00,50.00,-1.00,-1.00
231 2.00,60.00,.00,.00
232 3.00,70.00,1.00,1.00
233 ])
234 AT_CLEANUP
235
236 AT_SETUP([DESCRIPTIVES -- Z scores with SPLIT FILE])
237 AT_DATA([descriptives.sps], [dnl
238 DATA LIST LIST NOTABLE /group a b.
239 BEGIN DATA.
240 1 1 50
241 1 2 60
242 1 3 70
243 2 100 6000
244 2 200 7000
245 2 400 9000
246 2 500 10000
247 END DATA.
248
249 SPLIT FILE BY group.
250 DESCRIPTIVES /VAR=a b /SAVE.
251 LIST.
252 ])
253 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
254 Table: Mapping of variables to corresponding Z-scores.
255 Source,Target
256 a,Za
257 b,Zb
258
259 Variable,Value,Label
260 group,1.00,
261
262 Table: Valid cases = 3; cases with missing value(s) = 0.
263 Variable,N,Mean,Std Dev,Minimum,Maximum
264 a,3,2.00,1.00,1.00,3.00
265 b,3,60.00,10.00,50.00,70.00
266
267 Variable,Value,Label
268 group,2.00,
269
270 Table: Valid cases = 4; cases with missing value(s) = 0.
271 Variable,N,Mean,Std Dev,Minimum,Maximum
272 a,4,300.00,182.57,100.00,500.00
273 b,4,8000.00,1825.74,6000.00,10000.00
274
275 Variable,Value,Label
276 group,1.00,
277
278 Table: Data List
279 group,a,b,Za,Zb
280 1.00,1.00,50.00,-1.00,-1.00
281 1.00,2.00,60.00,.00,.00
282 1.00,3.00,70.00,1.00,1.00
283
284 Variable,Value,Label
285 group,2.00,
286
287 Table: Data List
288 group,a,b,Za,Zb
289 2.00,100.00,6000.00,-1.10,-1.10
290 2.00,200.00,7000.00,-.55,-.55
291 2.00,400.00,9000.00,.55,.55
292 2.00,500.00,10000.00,1.10,1.10
293 ])
294 AT_CLEANUP
295
296 dnl Ideally DESCRIPTIVES would not make temporary transformations permanent
297 dnl as it does now (bug #38786), so these results are imperfect.  However,
298 dnl this test does verify that DESCRIPTIVES does not crash in this situation
299 dnl (as it once did).
300 AT_SETUP([DESCRIPTIVES -- Z scores bug with TEMPORARY])
301 AT_DATA([descriptives.sps], [dnl
302 DATA LIST LIST NOTABLE /id abc.
303 BEGIN DATA.
304 1 3.5
305 2 2.0
306 3 2.0
307 4 3.5
308 5 3.0
309 6 4.0
310 7 5.0
311 END DATA.
312
313 TEMPORARY.
314 SELECT IF id < 7 .
315
316 DESCRIPTIVES /VAR=abc/SAVE.
317 LIST.
318 ])
319 AT_CHECK([pspp -O format=csv descriptives.sps], [0], [dnl
320 descriptives.sps:15: warning: DESCRIPTIVES: DESCRIPTIVES with Z scores ignores TEMPORARY.  Temporary transformations will be made permanent.
321
322 Table: Mapping of variables to corresponding Z-scores.
323 Source,Target
324 abc,Zabc
325
326 Table: Valid cases = 6; cases with missing value(s) = 0.
327 Variable,N,Mean,Std Dev,Minimum,Maximum
328 abc,6,3.00,.84,2.00,4.00
329
330 Table: Data List
331 id,abc,Zabc
332 1.00,3.50,.60
333 2.00,2.00,-1.20
334 3.00,2.00,-1.20
335 4.00,3.50,.60
336 5.00,3.00,.00
337 6.00,4.00,1.20
338 ])
339 AT_CLEANUP
340
341 dnl This test was supplied by Mindaugus as part of the report for bug #42012.
342 AT_SETUP([DESCRIPTIVES -- Z scores with FILTER])
343 AT_DATA([descriptives.sps], [dnl
344 DATA LIST LIST/filter1 filter2 x.
345 BEGIN DATA.
346 0,0,300
347 0,1,200
348 0,1,100
349 1,0,5
350 1,0,4
351 1,1,3
352 1,1,2
353 1,1,1
354 END DATA.
355
356 FILTER OFF.
357 SPLIT FILE OFF.
358 DESCRIPTIVES /VARIABLES=X /SAVE.
359
360 FILTER BY filter1.
361 SPLIT FILE OFF.
362 DESCRIPTIVES /VARIABLES=X /SAVE.
363
364 FILTER OFF.
365 SORT CASES BY filter1.
366 SPLIT FILE BY filter1.
367 DESCRIPTIVES /VARIABLES=X /SAVE.
368
369 FILTER BY filter2.
370 SPLIT FILE BY filter1.
371 DESCRIPTIVES /VARIABLES=X /SAVE.
372
373 FILTER OFF.
374 SORT CASES BY filter1 filter2.
375 SPLIT FILE BY filter1 filter2.
376 DESCRIPTIVES /VARIABLES=X /SAVE.
377 EXECUTE.
378
379 SPLIT FILE OFF.
380 LIST.
381 ])
382 AT_CHECK([pspp -o pspp.csv descriptives.sps])
383 AT_CHECK([sed -n '/Table: Data List/,$p' < pspp.csv], [0], [dnl
384 Table: Data List
385 filter1,filter2,x,Zx,ZSC001,ZSC002,ZSC003,ZSC004
386 .00,.00,300.00,1.94,.  ,1.00,.  ,.  @&t@
387 .00,1.00,200.00,1.07,.  ,.00,.71,.71
388 .00,1.00,100.00,.20,.  ,-1.00,-.71,-.71
389 1.00,.00,5.00,-.62,1.26,1.26,.  ,.71
390 1.00,.00,4.00,-.63,.63,.63,.  ,-.71
391 1.00,1.00,3.00,-.64,.00,.00,1.00,1.00
392 1.00,1.00,2.00,-.65,-.63,-.63,.00,.00
393 1.00,1.00,1.00,-.66,-1.26,-1.26,-1.00,-1.00
394 ])
395 AT_CLEANUP