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