Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / glm.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([GLM procedure])
18
19 AT_SETUP([GLM latin square design])
20 AT_KEYWORDS([categorical categoricals])
21
22 dnl This example comes from :
23 dnl  http://ssnds.uwo.ca/statsexamples/spssanova/latinsquareresults.html
24 AT_DATA([latin.sps], [dnl
25 set format = F20.3.
26 data list notable  fixed /a 1 b 3 c 5 y 7-10(2).
27 begin data.
28 1 1 6  3.5
29 1 2 2  8.9
30 1 3 3  9.6
31 1 4 4 10.5
32 1 5 5  3.1
33 1 6 1  5.9
34 2 1 2  4.2
35 2 2 6  1.9
36 2 3 5  3.7
37 2 4 3 10.2
38 2 5 1  7.2
39 2 6 4  7.6
40 3 1 1  6.7
41 3 2 4  5.8
42 3 3 6 -2.7
43 3 4 2  4.6
44 3 5 3  4.0
45 3 6 5 -0.7
46 4 1 4  6.6
47 4 2 1  4.5
48 4 3 2  3.7
49 4 4 5  3.7
50 4 5 6 -3.3
51 4 6 3  3.0
52 5 1 3  4.1
53 5 2 5  2.4
54 5 3 4  6.0
55 5 4 1  5.1
56 5 5 2  3.5
57 5 6 6  4.0
58 6 1 5  3.8
59 6 2 3  5.8
60 6 3 1  7.0
61 6 4 6  3.8
62 6 5 4  5.0
63 6 6 2  8.6
64 end data.
65
66 variable labels a 'Factor A' b 'Factor B' c 'Factor C' y 'Criterion'.
67
68 glm y by   b a c
69   /intercept=include
70   /criteria=alpha(.05)
71   /design = a b c
72   .
73 ])
74
75 AT_CHECK([pspp -O format=csv latin.sps | sed 's/329.62[[678]]/329.62/'], [0],
76   [dnl
77 Table: Tests of Between-Subjects Effects
78 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
79 Corrected Model,263.064,15,17.538,5.269,.000
80 Intercept,815.103,1,815.103,244.910,.000
81 Factor A,78.869,5,15.774,4.739,.005
82 Factor B,28.599,5,5.720,1.719,.176
83 Factor C,155.596,5,31.119,9.350,.000
84 Error,66.563,20,3.328,,
85 Total,1144.730,36,,,
86 Corrected Total,329.62,35,,,
87 ])
88
89 AT_CLEANUP
90
91 AT_SETUP([GLM 2 by 2 factorial design])
92 AT_KEYWORDS([categorical categoricals])
93
94 AT_DATA([2by2.sps], [dnl
95 set format = F20.3.
96 data list notable  list /Factor0 * Factor1 * points (F10).
97 begin data.
98 1       4       332
99 1       4       380
100 1       4       371
101 1       4       366
102 1       4       354
103 1       0       259.5
104 1       0       302.5
105 1       0       296
106 1       0       349
107 1       0       309
108 2       4       354.67
109 2       4       353.5
110 2       4       304
111 2       4       365
112 2       4       339
113 2       0       306
114 2       0       339
115 2       0       353
116 2       0       351
117 2       0       333
118 end data.
119
120 glm points by Factor0 Factor1
121   /intercept=include
122   /criteria=alpha(.05)
123   .
124 ])
125
126
127 AT_CHECK([pspp -O format=csv 2by2.sps ], [0],
128   [dnl
129 Table: Tests of Between-Subjects Effects
130 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
131 Corrected Model,8667.053,3,2889.018,5.043,.012
132 Intercept,2256018.640,1,2256018.640,3937.693,.000
133 Factor0,313.394,1,313.394,.547,.470
134 Factor1,5157.508,1,5157.508,9.002,.008
135 Factor0 × Factor1,3196.150,1,3196.150,5.579,.031
136 Error,9166.865,16,572.929,,
137 Total,2273852.559,20,,,
138 Corrected Total,17833.918,19,,,
139 ])
140
141 AT_CLEANUP
142
143
144 AT_SETUP([GLM Type I and II Sums of Squares])
145 AT_KEYWORDS([categorical categoricals])
146
147 dnl  The following example comes from
148 dnl  http://www.uvm.edu/~dhowell/StatPages/More_Stuff/Type1-3.pdf
149 AT_DATA([data-inc.sps], [dnl
150 set decimal = dot.
151 set format=F20.3.
152 data list notable list /dv * Agrp * B0 * B1 * B2 * i0 * i1 * i2 * sss *.
153 begin data.
154 5   1  1  0  0  1  0  0 1.00
155 7   1  1  0  0  1  0  0 1.00
156 9   1  1  0  0  1  0  0 1.00
157 8   1  1  0  0  1  0  0 1.00
158 2   1  0  1  0  0  1  0 1.00
159 5   1  0  1  0  0  1  0 1.00
160 7   1  0  1  0  0  1  0 1.00
161 3   1  0  1  0  0  1  0 1.00
162 9   1  0  1  0  0  1  0 1.00
163 8   1  0  0  1  0  0  1 1.00
164 11  1  0  0  1  0  0  1 1.00
165 12  1  0  0  1  0  0  1 1.00
166 14  1  0  0  1  0  0  1 1.00
167 11  1 -1 -1 -1 -1 -1 -1 1.00
168 15  1 -1 -1 -1 -1 -1 -1 1.00
169 16  1 -1 -1 -1 -1 -1 -1 1.00
170 10  1 -1 -1 -1 -1 -1 -1 1.00
171 9   1 -1 -1 -1 -1 -1 -1 1.00
172 7  -1  1  0  0 -1  0  0 2.00
173 9  -1  1  0  0 -1  0  0 2.00
174 10 -1  1  0  0 -1  0  0 2.00
175 9  -1  1  0  0 -1  0  0 2.00
176 3  -1  0  1  0  0 -1  0 2.00
177 8  -1  0  1  0  0 -1  0 2.00
178 9  -1  0  1  0  0 -1  0 2.00
179 11 -1  0  1  0  0 -1  0 2.00
180 9  -1  0  0  1  0  0 -1 2.00
181 12 -1  0  0  1  0  0 -1 2.00
182 14 -1  0  0  1  0  0 -1 2.00
183 8  -1  0  0  1  0  0 -1 2.00
184 7  -1  0  0  1  0  0 -1 2.00
185 11 -1 -1 -1 -1  1  1  1 2.00
186 14 -1 -1 -1 -1  1  1  1 2.00
187 10 -1 -1 -1 -1  1  1  1 2.00
188 12 -1 -1 -1 -1  1  1  1 2.00
189 13 -1 -1 -1 -1  1  1  1 2.00
190 11 -1 -1 -1 -1  1  1  1 2.00
191 12 -1 -1 -1 -1  1  1  1 2.00
192 end data.
193
194 do if B0 = -1 AND B1 = -1 AND B2 = -1.
195 compute Bgrp = 4.
196 end if.
197
198 do if B0 = 0 AND B1 = 0 AND B2 = 1.
199 compute Bgrp = 3.
200 end if.
201
202 do if B0 = 0 AND B1 = 1 AND B2 = 0.
203 compute Bgrp = 2.
204 end if.
205
206 do if B0 = 1 AND B1 = 0 AND B2 = 0.
207 compute Bgrp = 1.
208 end if.
209 ])
210
211 AT_DATA([type1.sps], [dnl
212 include 'data-inc.sps'.
213
214 glm dv by Agrp Bgrp
215         /method = sstype (1)
216         .
217
218 glm dv by Agrp Bgrp
219         /method = sstype (1)
220         /design Bgrp Agrp Bgrp * Agrp
221         .
222 ])
223
224
225 AT_CHECK([pspp -O format=csv type1.sps], [0],
226   [dnl
227 Table: Tests of Between-Subjects Effects
228 ,Type I Sum Of Squares,df,Mean Square,F,Sig.
229 Corrected Model,216.017,7,30.860,5.046,.001
230 Agrp,9.579,1,9.579,1.566,.220
231 Bgrp,186.225,3,62.075,10.151,.000
232 Agrp × Bgrp,20.212,3,6.737,1.102,.364
233 Error,183.457,30,6.115,,
234 Total,3810.000,38,,,
235 Corrected Total,399.474,37,,,
236
237 Table: Tests of Between-Subjects Effects
238 ,Type I Sum Of Squares,df,Mean Square,F,Sig.
239 Corrected Model,216.017,7,30.860,5.046,.001
240 Bgrp,193.251,3,64.417,10.534,.000
241 Agrp,2.553,1,2.553,.418,.523
242 Bgrp × Agrp,20.212,3,6.737,1.102,.364
243 Error,183.457,30,6.115,,
244 Total,3810.000,38,,,
245 Corrected Total,399.474,37,,,
246 ])
247
248
249 AT_DATA([type2.sps], [dnl
250 include 'data-inc.sps'.
251
252 glm dv by Agrp Bgrp
253         /method = sstype (2)
254         .
255 ])
256
257
258 AT_CHECK([pspp -O format=csv type2.sps], [0],
259   [dnl
260 Table: Tests of Between-Subjects Effects
261 ,Type II Sum Of Squares,df,Mean Square,F,Sig.
262 Corrected Model,216.017,7,30.860,5.046,.001
263 Agrp,2.553,1,2.553,.418,.523
264 Bgrp,186.225,3,62.075,10.151,.000
265 Agrp × Bgrp,20.212,3,6.737,1.102,.364
266 Error,183.457,30,6.115,,
267 Total,3810.000,38,,,
268 Corrected Total,399.474,37,,,
269 ])
270
271 AT_CLEANUP
272
273
274
275 AT_SETUP([GLM excluded intercept])
276 AT_KEYWORDS([categorical categoricals])
277
278 dnl  The following example comes from
279 dnl
280 dnl Rudolf N. Cardinal
281 dnl Graduate-level statistics for psychology and neuroscience
282 dnl ANOVA in practice, and complex ANOVA designs
283 dnl Version of 2 May 2004
284 dnl
285 dnl Downloaded from: http://egret.psychol.cam.ac.uk/psychology/graduate/Guide_to_ANOVA.pdf
286
287 AT_DATA([intercept-exclude.sps], [dnl
288 set format = F20.3.
289
290 data list notable list /depvar * A *.
291 begin data.
292 10     1
293 14     1
294 8      1
295 7      1
296 2      1
297 10     1
298 1      1
299 3      1
300 2      1
301 8.5    1
302 14.29  2
303 18.49  2
304 12.46  2
305 11.63  2
306 6.66   2
307 14.02  2
308 5.66   2
309 7.06   2
310 6.37   2
311 13.26  2
312 end data.
313
314 GLM depvar by A
315    /intercept = exclude
316   .
317
318
319 GLM depvar by A
320    /intercept = include
321   .
322
323 ])
324
325 AT_CHECK([pspp -O format=csv intercept-exclude.sps], [0],
326   [dnl
327 Table: Tests of Between-Subjects Effects
328 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
329 Model,1636.826,2,818.413,43.556,.000
330 A,1636.826,2,818.413,43.556,.000
331 Error,338.216,18,18.790,,
332 Total,1975.042,20,,,
333
334 Table: Tests of Between-Subjects Effects
335 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
336 Corrected Model,98.568,1,98.568,5.246,.034
337 Intercept,1538.258,1,1538.258,81.867,.000
338 A,98.568,1,98.568,5.246,.034
339 Error,338.216,18,18.790,,
340 Total,1975.042,20,,,
341 Corrected Total,436.784,19,,,
342 ])
343
344 AT_CLEANUP
345
346
347 AT_SETUP([GLM missing values])
348 AT_KEYWORDS([categorical categoricals])
349
350 AT_DATA([glm.data], [dnl
351 1 1 6  3.5
352 1 2 2  8.9
353 1 3 3  9.6
354 1 4 4 10.5
355 1 5 5  3.1
356 1 6 1  5.9
357 2 1 2  4.2
358 2 2 6  1.9
359 2 3 5  3.7
360 2 4 3 10.2
361 2 5 1  7.2
362 2 6 4  7.6
363 3 1 1  6.7
364 3 2 4  5.8
365 3 3 6 -2.7
366 3 4 2  4.6
367 3 5 3  4.0
368 3 6 5 -0.7
369 4 1 4  6.6
370 4 2 1  4.5
371 4 3 2  3.7
372 4 4 5  3.7
373 4 5 6 -3.3
374 4 6 3  3.0
375 5 1 3  4.1
376 5 2 5  2.4
377 5 3 4  6.0
378 5 4 1  5.1
379 5 5 2  3.5
380 5 6 6  4.0
381 6 1 5  3.8
382 6 2 3  5.8
383 6 3 1  7.0
384 6 4 6  3.8
385 6 5 4  5.0
386 6 6 2  8.6
387 ])
388
389 AT_DATA([glm-miss.sps], [dnl
390 set format = F20.3.
391 data list file='glm.data' notable  fixed /a 1 b 3 c 5 y 7-10(2).
392
393 do if a=6.
394 recode y (else=SYSMIS).
395 end if.
396
397 glm y by   b a c
398   /criteria=alpha(.05)
399   /design = a b c
400   .
401 ])
402
403 AT_CHECK([pspp -O format=csv glm-miss.sps], [0],  [dnl
404 Table: Tests of Between-Subjects Effects
405 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
406 Corrected Model,251.621,14,17.973,4.969,.002
407 Intercept,628.376,1,628.376,173.737,.000
408 a,72.929,4,18.232,5.041,.009
409 b,20.703,5,4.141,1.145,.380
410 c,135.179,5,27.036,7.475,.001
411 Error,54.253,15,3.617,,
412 Total,934.250,30,,,
413 Corrected Total,305.874,29,,,
414 ])
415
416
417
418 AT_DATA([glm-miss2.sps], [dnl
419 set format = F20.3.
420 data list file='glm.data' notable  fixed /a 1 b 3 c 5 y 7-10(2).
421
422 select if a <> 6.
423
424 glm y by   b a c
425   /criteria=alpha(.05)
426   /design = a b c
427   .
428 ])
429
430 AT_CHECK([pspp -O format=csv glm-miss2.sps], [0],  [dnl
431 Table: Tests of Between-Subjects Effects
432 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
433 Corrected Model,251.621,14,17.973,4.969,.002
434 Intercept,628.376,1,628.376,173.737,.000
435 a,72.929,4,18.232,5.041,.009
436 b,20.703,5,4.141,1.145,.380
437 c,135.179,5,27.036,7.475,.001
438 Error,54.253,15,3.617,,
439 Total,934.250,30,,,
440 Corrected Total,305.874,29,,,
441 ])
442
443
444 dnl Now for some missing values in the factor variables.
445
446 AT_DATA([glm-miss3.sps], [dnl
447 set format = F20.3.
448 data list file=glm.data notable  fixed /a 1 b 3 c 5 y 7-10(2).
449
450 do if a=6.
451 recode a (else=SYSMIS).
452 end if.
453
454 glm y by   b a c
455   /criteria=alpha(.05)
456   /design = a b c
457   .
458 ])
459
460 AT_CHECK([pspp -O format=csv glm-miss3.sps], [0],  [dnl
461 Table: Tests of Between-Subjects Effects
462 ,Type III Sum Of Squares,df,Mean Square,F,Sig.
463 Corrected Model,251.621,14,17.973,4.969,.002
464 Intercept,628.376,1,628.376,173.737,.000
465 a,72.929,4,18.232,5.041,.009
466 b,20.703,5,4.141,1.145,.380
467 c,135.179,5,27.036,7.475,.001
468 Error,54.253,15,3.617,,
469 Total,934.250,30,,,
470 Corrected Total,305.874,29,,,
471 ])
472
473 AT_CLEANUP
474
475 AT_SETUP([GLM syntax errors])
476 AT_DATA([glm.sps], [dnl
477 DATA LIST LIST NOTABLE /x y z.
478 GLM **.
479 GLM x **.
480 GLM x BY **.
481 GLM x BY y.
482 GLM x y BY z.
483 GLM x BY y/MISSING=**.
484 GLM x BY y/INTERCEPT=**.
485 GLM x BY y/CRITERIA=**.
486 GLM x BY y/CRITERIA=ALPHA **.
487 GLM x BY y/CRITERIA=ALPHA(**).
488 GLM x BY y/CRITERIA=ALPHA(123 **).
489 GLM x BY y/METHOD=**.
490 GLM x BY y/METHOD=SSTYPE **.
491 GLM x BY y/METHOD=SSTYPE(4).
492 GLM x BY y/METHOD=SSTYPE(2 **).
493 GLM x BY y/DESIGN=**.
494 GLM x BY y/DESIGN=x(y).
495 GLM x BY y/DESIGN=x WITHIN y.
496 ])
497 AT_CHECK([pspp -O format=csv glm.sps], [1], [dnl
498 "glm.sps:2.5-2.6: error: GLM: Syntax error expecting variable name.
499     2 | GLM **.
500       |     ^~"
501
502 "glm.sps:3.7-3.8: error: GLM: Syntax error expecting `BY'.
503     3 | GLM x **.
504       |       ^~"
505
506 "glm.sps:4.10-4.11: error: GLM: Syntax error expecting variable name.
507     4 | GLM x BY **.
508       |          ^~"
509
510 "glm.sps:6.1-6.3: error: GLM: Syntax error expecting `BEGIN DATA'.
511     6 | GLM x y BY z.
512       | ^~~"
513
514 "glm.sps:6.1-6.3: error: GLM: Syntax error expecting end of command.
515     6 | GLM x y BY z.
516       | ^~~"
517
518 "glm.sps:7.20-7.21: error: GLM: Syntax error expecting INCLUDE or EXCLUDE.
519     7 | GLM x BY y/MISSING=**.
520       |                    ^~"
521
522 "glm.sps:8.22-8.23: error: GLM: Syntax error expecting INCLUDE or EXCLUDE.
523     8 | GLM x BY y/INTERCEPT=**.
524       |                      ^~"
525
526 "glm.sps:9.21-9.22: error: GLM: Syntax error expecting `ALPHA@{:@'.
527     9 | GLM x BY y/CRITERIA=**.
528       |                     ^~"
529
530 "glm.sps:10.21-10.28: error: GLM: Syntax error expecting `ALPHA@{:@'.
531    10 | GLM x BY y/CRITERIA=ALPHA **.
532       |                     ^~~~~~~~"
533
534 "glm.sps:11.27-11.28: error: GLM: Syntax error expecting number.
535    11 | GLM x BY y/CRITERIA=ALPHA(**).
536       |                           ^~"
537
538 "glm.sps:12.31-12.32: error: GLM: Syntax error expecting `@:}@'.
539    12 | GLM x BY y/CRITERIA=ALPHA(123 **).
540       |                               ^~"
541
542 "glm.sps:13.19-13.20: error: GLM: Syntax error expecting `SSTYPE@{:@'.
543    13 | GLM x BY y/METHOD=**.
544       |                   ^~"
545
546 "glm.sps:14.19-14.27: error: GLM: Syntax error expecting `SSTYPE@{:@'.
547    14 | GLM x BY y/METHOD=SSTYPE **.
548       |                   ^~~~~~~~~"
549
550 "glm.sps:15.26: error: GLM: Syntax error expecting integer between 1 and 3 for SSTYPE.
551    15 | GLM x BY y/METHOD=SSTYPE(4).
552       |                          ^"
553
554 "glm.sps:16.28-16.29: error: GLM: Syntax error expecting `@:}@'.
555    16 | GLM x BY y/METHOD=SSTYPE(2 **).
556       |                            ^~"
557
558 "glm.sps:17.19-17.20: error: GLM: Syntax error expecting variable name.
559    17 | GLM x BY y/DESIGN=**.
560       |                   ^~"
561
562 "glm.sps:18.20: error: GLM: Nested variables are not yet implemented.
563    18 | GLM x BY y/DESIGN=x(y).
564       |                    ^"
565
566 "glm.sps:19.21-19.26: error: GLM: Nested variables are not yet implemented.
567    19 | GLM x BY y/DESIGN=x WITHIN y.
568       |                     ^~~~~~"
569 ])
570 AT_CLEANUP