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