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