Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / correlations.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([CORRELATIONS])
18
19 AT_SETUP([CORRELATIONS -- unweighted])
20 AT_DATA([correlations.sps], [dnl
21 set format = F11.3.
22 data list notable list /foo * bar * wiz * bang *.
23 begin data.
24 1   0   3   1
25 3   9 -50   5
26 3   4   3 203
27 4  -9   0  -4
28 98 78 104   2
29 3  50 -49 200
30 .   4   4   4
31 5   3   0   .
32 end data.
33
34 correlations
35         variables = foo bar wiz bang
36         /print nosig
37         /missing = listwise
38         .
39
40 correlations
41         variables = bar wiz
42         /print nosig
43         /missing = listwise
44         .
45
46 correlations
47         variables = foo bar wiz bang
48         /print nosig
49         /missing = pairwise
50         .
51 ])
52 AT_CHECK([pspp -o pspp.csv -o pspp.txt correlations.sps])
53 AT_CHECK([cat pspp.csv], [0],
54 [[Table: Correlations
55 ,,foo,bar,wiz,bang
56 foo,Pearson Correlation,1.000,.802,.890[a],-.308
57 ,Sig. (2-tailed),,.055,.017,.553
58 bar,Pearson Correlation,.802,1.000,.519,.118
59 ,Sig. (2-tailed),.055,,.291,.824
60 wiz,Pearson Correlation,.890[a],.519,1.000,-.344
61 ,Sig. (2-tailed),.017,.291,,.505
62 bang,Pearson Correlation,-.308,.118,-.344,1.000
63 ,Sig. (2-tailed),.553,.824,.505,
64 Footnote: a. Significant at .05 level
65
66 Table: Correlations
67 ,,bar,wiz
68 bar,Pearson Correlation,1.000,.497
69 ,Sig. (2-tailed),,.210
70 wiz,Pearson Correlation,.497,1.000
71 ,Sig. (2-tailed),.210,
72
73 Table: Correlations
74 ,,foo,bar,wiz,bang
75 foo,Pearson Correlation,1.000,.805[a],.883[a],-.308
76 ,Sig. (2-tailed),,.029,.008,.553
77 ,N,7,7,7,6
78 bar,Pearson Correlation,.805[a],1.000,.497,.164
79 ,Sig. (2-tailed),.029,,.210,.725
80 ,N,7,8,8,7
81 wiz,Pearson Correlation,.883[a],.497,1.000,-.337
82 ,Sig. (2-tailed),.008,.210,,.460
83 ,N,7,8,8,7
84 bang,Pearson Correlation,-.308,.164,-.337,1.000
85 ,Sig. (2-tailed),.553,.725,.460,
86 ,N,6,7,7,7
87 Footnote: a. Significant at .05 level
88 ]])
89 AT_CLEANUP
90
91 AT_SETUP([CORRELATIONS -- weighted])
92 AT_DATA([correlations1.sps], [dnl
93 set format = F11.3.
94 data list notable list /foo * bar * wiz * bang * w *.
95 begin data.
96 1   0   3   1  1
97 3   9 -50   5  2
98 3   4   3 203  1
99 4  -9   0  -4  1
100 98 78 104   2  3
101 3  50 -49 200  1
102 end data.
103
104 weight by w.
105
106 correlations
107         variables = foo bar wiz bang
108         /statistics=descriptives xprod
109         .
110 ])
111 AT_DATA([correlations2.sps], [dnl
112 set format = F11.3.
113 data list notable list /foo * bar * wiz * bang * w *.
114 begin data.
115 1   0   3   1  1
116 3   9 -50   5  1
117 3   9 -50   5  1
118 3   4   3 203  1
119 4  -9   0  -4  1
120 98 78 104   2  1
121 98 78 104   2  1
122 98 78 104   2  1
123 3  50 -49 200  1
124 end data.
125
126 weight by w.
127
128 correlations
129         variables = foo bar wiz bang
130         /statistics=descriptives xprod
131         .
132 ])
133 AT_CHECK([pspp -O format=csv correlations1.sps], [0], [stdout])
134 mv stdout expout
135 AT_CHECK([pspp -O format=csv correlations2.sps], [0], [expout])
136 AT_CLEANUP
137
138
139 AT_SETUP([CORRELATIONS -- non-square])
140 AT_DATA([corr-ns.sps], [dnl
141 set format = F11.3.
142 data list notable list /foo * bar * wiz *.
143 begin data.
144 1 1 6
145 2 2 5
146 3 3 4
147 4 4 3
148 5 5 2
149 6 6 1
150 end data.
151
152 correlations
153         variables = foo with bar wiz
154         .
155 ])
156
157 AT_CHECK([pspp -O format=csv corr-ns.sps], [0], [dnl
158 Table: Correlations
159 ,,bar,wiz
160 foo,Pearson Correlation,1.000,-1.000
161 ,Sig. (2-tailed),.000,.000
162 ,N,6,6
163 ])
164
165 AT_CLEANUP
166
167 dnl Checks for bug #38661.
168 AT_SETUP([CORRELATIONS -- crash with WITH keyword])
169 AT_DATA([correlations.sps], [dnl
170 DATA LIST LIST NOTABLE /a b c d e f g h i.
171 .
172 BEGIN DATA.
173 20 21 17 28 23 4.35 24 19 25
174 28 18 29 30 23 4.55 17 23 28
175 47 18 30 30 29 4.35 26 31 31
176 20 7 19 22 22 4.80 24 16 27
177 19 12 17 27 22 . 22 14 25
178 22 9 19 30 33 5 29 30 27
179 41 16 22 32 23 3.90 26 27 23
180 18 18 20 26 22 5.80 17 20 39
181 18 24 25 25 31 5.15 27 27 34
182 19 22 26 23 37 6 41 32 27
183 23 12 15 29 25 4.10 21 27 20
184 21 4 28 37 31 5.65 27 18 42
185 19 5 17 17 29 3.10 19 16 19
186 21 17 20 35 31 . 28 30 22
187 END DATA.
188
189 CORRELATIONS VARIABLE=a f b WITH c g h i e d/STATISTICS=DESCRIPTIVES.
190 ])
191 AT_CHECK([pspp -o pspp.csv correlations.sps])
192 # Check the output, ignoring the actual correlations values since
193 # they look pretty nonsensical to me for this input (they include NaNs).
194 AT_CHECK([sed '/a,Pearson/,$s/,\([[^,]]*\),.*/,\1,.../' pspp.csv], [0], [dnl
195 Table: Descriptive Statistics
196 ,Mean,Std. Deviation,N
197 a,24.00,8.93,14
198 f,4.73,.85,12
199 b,14.50,6.41,14
200 c,21.71,4.98,14
201 g,24.86,6.09,14
202 h,23.57,6.30,14
203 i,27.79,6.73,14
204 e,27.21,4.95,14
205 d,27.93,5.23,14
206
207 Table: Correlations
208 ,,c,g,h,i,e,d
209 a,Pearson Correlation,...
210 ,Sig. (2-tailed),...
211 ,N,...
212 f,Pearson Correlation,...
213 ,Sig. (2-tailed),...
214 ,N,...
215 b,Pearson Correlation,...
216 ,Sig. (2-tailed),...
217 ,N,...
218 ])
219 AT_CLEANUP
220
221
222
223 dnl Checks for bug #40661
224 AT_SETUP([CORRELATIONS -- incorrect subtable selection])
225 AT_DATA([correlations.sps], [dnl
226 set format = F12.4.
227 OUTPUT MODIFY /SELECT TABLES /TABLECELLS SELECT = [[CORRELATIONS]] FORMAT=F12.4.
228 set decimal = dot.
229 data list notable list /var1 var2 var3 var4 var5 *.
230 begin data.
231 7,6,9,2,3
232 9,12,8,5,8
233 8,9,7,8,6
234 8,8,9,10,8
235 7,6,4,5,3
236 7,9,8,2,1
237 9,8,11,,10
238 8,7,6,,5
239 6,7,6,,8
240 6,,3,,4
241 6,,7,3,3
242 5,4,2,7,8
243 9,8,6,11,10
244 5,6,2,2,4
245 8,7,6,8,7
246 10,13,8,12,10
247 7,8,7,11,2
248 8,7,7,9,6
249 10,11,11,8,1
250 5,8,6,9,9
251 8,7,5,5,6
252 5,7,2,1,8
253 9,8,8,13,6
254 5,8,5,6,4
255 ,7,5,4,5
256 ,8,4,4,3
257 ,6,4,9,5
258 8,11,9,12,3
259 9,11,8,10,6
260 10,10,7,8,1
261 6,6,3,8,9
262 10,9,7,12,2
263 6,8,,7,4
264 6,8,3,2,9
265 7,8,8,2,9
266 5,6,5,5,5
267 9,9,7,7,5
268 9,10,11,7,8
269 8,11,9,3,3
270 5,4,4,0,5
271 9,9,11,14,2
272 5,6,2,4,4
273 8,8,7,4,1
274 9,9,8,14,
275 6,8,7,2,
276 10,9,9,6,
277 8,8,10,9,
278 7,8,4,12,
279 6,6,6,7,1
280 5,7,7,4,10
281 9,10,10,13,4
282 9,11,9,8,7
283 10,13,12,6,8
284 8,11,6,8,5
285 7,8,7,12,2
286 6,7,4,1,10
287 5,4,5,6,10
288 7,8,6,12,10
289 6,5,3,9,2
290 7,8,8,7,2
291 5,4,4,9,8
292 5,7,6,3,9
293 10,10,9,13,1
294 8,10,9,5,4
295 8,9,8,8,7
296 7,9,9,6,7
297 10,9,7,12,6
298 10,13,12,12,4
299 7,10,9,7,2
300 6,8,7,11,6
301 8,11,5,13,2
302 7,10,6,12,8
303 10,10,9,7,9
304 9,12,6,7,10
305 6,6,8,2,9
306 10,9,12,13,10
307 8,9,8,3,6
308 8,7,6,4,10
309 8,7,10,12,2
310 7,6,8,2,7
311 8,11,6,9,4
312 6,6,7,8,2
313 6,7,3,11,4
314 5,6,3,0,5
315 10,10,11,15,6
316 5,4,7,6,8
317 5,4,4,1,3
318 6,9,8,1,6
319 10,11,10,15,8
320 7,10,4,11,7
321 9,12,8,6,3
322 10,10,11,15,2
323 10,9,9,15,3
324 6,6,8,5,1
325 5,7,7,0,3
326 9,8,10,6,8
327 9,8,11,11,4
328 8,10,7,3,4
329 7,8,7,3,3
330 8,9,10,13,8
331 end data.
332
333 CORRELATION
334         /VARIABLES =  var1 var2 var3 WITH var4 var5
335         /PRINT = TWOTAIL NOSIG.
336
337 CORRELATION
338         /VARIABLES =  var3 var4 var5 WITH var1 var2
339         /PRINT = TWOTAIL NOSIG.
340
341 ])
342
343 AT_CHECK([pspp -o pspp.csv -o pspp.txt correlations.sps])
344 AT_CHECK([cat pspp.csv], [0],
345 [[Table: Correlations
346 ,,var4,var5
347 var1,Pearson Correlation,.5693[a],-.0519
348 ,Sig. (2-tailed),.000,.623
349 ,N,93,92
350 var2,Pearson Correlation,.3792[a],-.0407
351 ,Sig. (2-tailed),.000,.698
352 ,N,95,93
353 var3,Pearson Correlation,.3699[a],-.0543
354 ,Sig. (2-tailed),.000,.603
355 ,N,95,94
356 Footnote: a. Significant at .05 level
357
358 Table: Correlations
359 ,,var1,var2
360 var3,Pearson Correlation,.6964[a],.5615[a]
361 ,Sig. (2-tailed),.000,.000
362 ,N,96,97
363 var4,Pearson Correlation,.5693[a],.3792[a]
364 ,Sig. (2-tailed),.000,.000
365 ,N,93,95
366 var5,Pearson Correlation,-.0519,-.0407
367 ,Sig. (2-tailed),.623,.698
368 ,N,92,93
369 Footnote: a. Significant at .05 level
370 ]])
371
372 AT_CLEANUP
373
374
375 dnl Crash found by zzuf
376 AT_SETUP([CORRELATIONS -- empty dataset])
377
378 AT_DATA([correlations.sps], [dnl
379 data list list /a b c q g *.
380 CORRELATIONS 'VARIABLES = a b.]
381 )
382
383 AT_CHECK([pspp -o pspp.csv correlations.sps], [1], [ignore])
384
385 AT_CLEANUP
386
387 dnl Another Crash found by zzuf
388 AT_SETUP([CORRELATIONS -- empty dataset 2])
389
390 AT_DATA([correlations.sps], [dnl
391 data list notable list /foo * bar * wiz bang *.
392 begin data.
393  1     00      3           .
394  3     9     -50           .
395 98    78     104           .
396  .     4       4           .
397  5     3       0           .
398 end data.
399
400 correlations
401         variables = foo bar wiz bang
402         /missing = listwise
403         .
404 ])
405
406 AT_CHECK([pspp -O format=csv correlations.sps], [1], [dnl
407 correlations.sps:13: error: CORRELATIONS: The data for the chosen variables are all missing or empty.
408 ])
409
410 AT_CLEANUP
411
412 AT_SETUP([CORRELATIONS -- syntax errors])
413 AT_DATA([correlations.sps], [dnl
414 DATA LIST LIST NOTABLE /x y z.
415 CORRELATIONS MISSING=**.
416 CORRELATIONS PRINT=**.
417 CORRELATIONS STATISTICS=**.
418 CORRELATIONS **.
419 CORRELATIONS x y z WITH **.
420 CORRELATIONS.
421 ])
422 AT_CHECK([pspp -O format=csv correlations.sps], [1], [dnl
423 "correlations.sps:2.22-2.23: error: CORRELATIONS: Syntax error expecting PAIRWISE, LISTWISE, INCLUDE, or EXCLUDE.
424     2 | CORRELATIONS MISSING=**.
425       |                      ^~"
426
427 "correlations.sps:3.20-3.21: error: CORRELATIONS: Syntax error expecting TWOTAIL, ONETAIL, SIG, or NOSIG.
428     3 | CORRELATIONS PRINT=**.
429       |                    ^~"
430
431 "correlations.sps:4.25-4.26: error: CORRELATIONS: Syntax error expecting DESCRIPTIVES, XPROD, or ALL.
432     4 | CORRELATIONS STATISTICS=**.
433       |                         ^~"
434
435 "correlations.sps:5.14-5.15: error: CORRELATIONS: Syntax error expecting variable name.
436     5 | CORRELATIONS **.
437       |              ^~"
438
439 "correlations.sps:6.25-6.26: error: CORRELATIONS: Syntax error expecting variable name.
440     6 | CORRELATIONS x y z WITH **.
441       |                         ^~"
442
443 "correlations.sps:7.1-7.12: error: CORRELATIONS: No variables specified.
444     7 | CORRELATIONS.
445       | ^~~~~~~~~~~~"
446 ])
447 AT_CLEANUP