Merge remote-tracking branch 'origin/master' into sheet
[pspp] / tests / language / stats / 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
21 dnl This example comes from :
22 dnl  http://ssnds.uwo.ca/statsexamples/spssanova/latinsquareresults.html
23 AT_DATA([latin.sps], [dnl
24 set format = F20.3.
25 data list notable  fixed /a 1 b 3 c 5 y 7-10(2).
26 begin data.
27 1 1 6  3.5
28 1 2 2  8.9
29 1 3 3  9.6
30 1 4 4 10.5
31 1 5 5  3.1
32 1 6 1  5.9
33 2 1 2  4.2
34 2 2 6  1.9
35 2 3 5  3.7
36 2 4 3 10.2
37 2 5 1  7.2
38 2 6 4  7.6
39 3 1 1  6.7
40 3 2 4  5.8
41 3 3 6 -2.7
42 3 4 2  4.6
43 3 5 3  4.0
44 3 6 5 -0.7
45 4 1 4  6.6
46 4 2 1  4.5
47 4 3 2  3.7
48 4 4 5  3.7
49 4 5 6 -3.3
50 4 6 3  3.0
51 5 1 3  4.1
52 5 2 5  2.4
53 5 3 4  6.0
54 5 4 1  5.1
55 5 5 2  3.5
56 5 6 6  4.0
57 6 1 5  3.8
58 6 2 3  5.8
59 6 3 1  7.0
60 6 4 6  3.8
61 6 5 4  5.0
62 6 6 2  8.6
63 end data.
64
65 variable labels a 'Factor A' b 'Factor B' c 'Factor C' y 'Criterion'.
66
67 glm y by   b a c
68   /intercept=include
69   /criteria=alpha(.05)
70   /design = a b c
71   .
72 ])
73
74 AT_CHECK([pspp -O format=csv latin.sps | sed 's/329.62[[678]]/329.62/'], [0],
75   [dnl
76 Table: Tests of Between-Subjects Effects
77 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
78 Corrected Model,263.064,15,17.538,5.269,.000
79 Intercept,815.103,1,815.103,244.910,.000
80 Factor A,78.869,5,15.774,4.739,.005
81 Factor B,28.599,5,5.720,1.719,.176
82 Factor C,155.596,5,31.119,9.350,.000
83 Error,66.563,20,3.328,,
84 Total,1144.730,36,,,
85 Corrected Total,329.62,35,,,
86 ])
87
88 AT_CLEANUP
89
90 AT_SETUP([GLM 2 by 2 factorial design])
91
92 AT_DATA([2by2.sps], [dnl
93 set format = F20.3.
94 data list notable  list /Factor0 * Factor1 * points (F10).
95 begin data.
96 1       4       332
97 1       4       380
98 1       4       371
99 1       4       366
100 1       4       354
101 1       0       259.5
102 1       0       302.5
103 1       0       296
104 1       0       349
105 1       0       309
106 2       4       354.67
107 2       4       353.5
108 2       4       304
109 2       4       365
110 2       4       339
111 2       0       306
112 2       0       339
113 2       0       353
114 2       0       351
115 2       0       333
116 end data.
117
118 glm points by Factor0 Factor1
119   /intercept=include
120   /criteria=alpha(.05)
121   .
122 ])
123
124
125 AT_CHECK([pspp -O format=csv 2by2.sps ], [0],
126   [dnl
127 Table: Tests of Between-Subjects Effects
128 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
129 Corrected Model,8667.053,3,2889.018,5.043,.012
130 Intercept,2256018.640,1,2256018.640,3937.693,.000
131 Factor0,313.394,1,313.394,.547,.470
132 Factor1,5157.508,1,5157.508,9.002,.008
133 Factor0 * Factor1,3196.150,1,3196.150,5.579,.031
134 Error,9166.865,16,572.929,,
135 Total,2273852.559,20,,,
136 Corrected Total,17833.918,19,,,
137 ])
138
139 AT_CLEANUP
140
141
142 AT_SETUP([GLM Type I and II Sums of Squares])
143
144 dnl  The following example comes from 
145 dnl  http://www.uvm.edu/~dhowell/StatPages/More_Stuff/Type1-3.pdf
146 AT_DATA([data-inc.sps], [dnl
147 set decimal = dot.
148 set format=F20.3.
149 data list notable list /dv * Agrp * B0 * B1 * B2 * i0 * i1 * i2 * sss *.
150 begin data.
151 5   1  1  0  0  1  0  0 1.00
152 7   1  1  0  0  1  0  0 1.00
153 9   1  1  0  0  1  0  0 1.00
154 8   1  1  0  0  1  0  0 1.00
155 2   1  0  1  0  0  1  0 1.00
156 5   1  0  1  0  0  1  0 1.00
157 7   1  0  1  0  0  1  0 1.00
158 3   1  0  1  0  0  1  0 1.00
159 9   1  0  1  0  0  1  0 1.00
160 8   1  0  0  1  0  0  1 1.00
161 11  1  0  0  1  0  0  1 1.00
162 12  1  0  0  1  0  0  1 1.00
163 14  1  0  0  1  0  0  1 1.00
164 11  1 -1 -1 -1 -1 -1 -1 1.00
165 15  1 -1 -1 -1 -1 -1 -1 1.00
166 16  1 -1 -1 -1 -1 -1 -1 1.00
167 10  1 -1 -1 -1 -1 -1 -1 1.00
168 9   1 -1 -1 -1 -1 -1 -1 1.00
169 7  -1  1  0  0 -1  0  0 2.00
170 9  -1  1  0  0 -1  0  0 2.00
171 10 -1  1  0  0 -1  0  0 2.00
172 9  -1  1  0  0 -1  0  0 2.00
173 3  -1  0  1  0  0 -1  0 2.00
174 8  -1  0  1  0  0 -1  0 2.00
175 9  -1  0  1  0  0 -1  0 2.00
176 11 -1  0  1  0  0 -1  0 2.00
177 9  -1  0  0  1  0  0 -1 2.00
178 12 -1  0  0  1  0  0 -1 2.00
179 14 -1  0  0  1  0  0 -1 2.00
180 8  -1  0  0  1  0  0 -1 2.00
181 7  -1  0  0  1  0  0 -1 2.00
182 11 -1 -1 -1 -1  1  1  1 2.00
183 14 -1 -1 -1 -1  1  1  1 2.00
184 10 -1 -1 -1 -1  1  1  1 2.00
185 12 -1 -1 -1 -1  1  1  1 2.00
186 13 -1 -1 -1 -1  1  1  1 2.00
187 11 -1 -1 -1 -1  1  1  1 2.00
188 12 -1 -1 -1 -1  1  1  1 2.00
189 end data.
190
191 do if B0 = -1 AND B1 = -1 AND B2 = -1.
192 compute Bgrp = 4.
193 end if.
194
195 do if B0 = 0 AND B1 = 0 AND B2 = 1.
196 compute Bgrp = 3.
197 end if.
198
199 do if B0 = 0 AND B1 = 1 AND B2 = 0.
200 compute Bgrp = 2.
201 end if.
202
203 do if B0 = 1 AND B1 = 0 AND B2 = 0.
204 compute Bgrp = 1.
205 end if.
206 ])
207
208 AT_DATA([type1.sps], [dnl
209 include 'data-inc.sps'.
210
211 glm dv by Agrp Bgrp
212         /method = sstype (1)
213         .
214
215 glm dv by Agrp Bgrp
216         /method = sstype (1)
217         /design Bgrp Agrp Bgrp * Agrp
218         .
219 ])
220
221
222 AT_CHECK([pspp -O format=csv type1.sps], [0],
223   [dnl
224 Table: Tests of Between-Subjects Effects
225 Source,Type I Sum of Squares,df,Mean Square,F,Sig.
226 Corrected Model,216.017,7,30.860,5.046,.001
227 Intercept,,,,,
228 Agrp,9.579,1,9.579,1.566,.220
229 Bgrp,186.225,3,62.075,10.151,.000
230 Agrp * Bgrp,20.212,3,6.737,1.102,.364
231 Error,183.457,30,6.115,,
232 Total,3810.000,38,,,
233 Corrected Total,399.474,37,,,
234
235 Table: Tests of Between-Subjects Effects
236 Source,Type I Sum of Squares,df,Mean Square,F,Sig.
237 Corrected Model,216.017,7,30.860,5.046,.001
238 Intercept,,,,,
239 Bgrp,193.251,3,64.417,10.534,.000
240 Agrp,2.553,1,2.553,.418,.523
241 Bgrp * Agrp,20.212,3,6.737,1.102,.364
242 Error,183.457,30,6.115,,
243 Total,3810.000,38,,,
244 Corrected Total,399.474,37,,,
245 ])
246
247
248 AT_DATA([type2.sps], [dnl
249 include 'data-inc.sps'.
250
251 glm dv by Agrp Bgrp
252         /method = sstype (2)
253         .
254 ])
255
256
257 AT_CHECK([pspp -O format=csv type2.sps], [0],
258   [dnl
259 Table: Tests of Between-Subjects Effects
260 Source,Type II Sum of Squares,df,Mean Square,F,Sig.
261 Corrected Model,216.017,7,30.860,5.046,.001
262 Intercept,,,,,
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
277 dnl  The following example comes from 
278 dnl
279 dnl Rudolf N. Cardinal
280 dnl Graduate-level statistics for psychology and neuroscience
281 dnl ANOVA in practice, and complex ANOVA designs
282 dnl Version of 2 May 2004
283 dnl
284 dnl Downloaded from: http://egret.psychol.cam.ac.uk/psychology/graduate/Guide_to_ANOVA.pdf
285
286 AT_DATA([intercept-exclude.sps], [dnl
287 set format = F20.3.
288
289 data list notable list /depvar * A *.
290 begin data.
291 10     1
292 14     1
293 8      1
294 7      1
295 2      1
296 10     1
297 1      1
298 3      1
299 2      1
300 8.5    1
301 14.29  2
302 18.49  2
303 12.46  2
304 11.63  2
305 6.66   2
306 14.02  2
307 5.66   2
308 7.06   2
309 6.37   2
310 13.26  2
311 end data.
312
313 GLM depvar by A
314    /intercept = exclude
315   .
316
317
318 GLM depvar by A
319    /intercept = include
320   .
321
322 ])
323
324 AT_CHECK([pspp -O format=csv intercept-exclude.sps], [0],
325   [dnl
326 Table: Tests of Between-Subjects Effects
327 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
328 Model,1636.826,2,818.413,43.556,.000
329 A,1636.826,2,818.413,43.556,.000
330 Error,338.216,18,18.790,,
331 Total,1975.042,20,,,
332
333 Table: Tests of Between-Subjects Effects
334 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
335 Corrected Model,98.568,1,98.568,5.246,.034
336 Intercept,1538.258,1,1538.258,81.867,.000
337 A,98.568,1,98.568,5.246,.034
338 Error,338.216,18,18.790,,
339 Total,1975.042,20,,,
340 Corrected Total,436.784,19,,,
341 ])
342
343 AT_CLEANUP
344
345
346 AT_SETUP([GLM missing values])
347
348 AT_DATA([glm.data], [dnl
349 1 1 6  3.5
350 1 2 2  8.9
351 1 3 3  9.6
352 1 4 4 10.5
353 1 5 5  3.1
354 1 6 1  5.9
355 2 1 2  4.2
356 2 2 6  1.9
357 2 3 5  3.7
358 2 4 3 10.2
359 2 5 1  7.2
360 2 6 4  7.6
361 3 1 1  6.7
362 3 2 4  5.8
363 3 3 6 -2.7
364 3 4 2  4.6
365 3 5 3  4.0
366 3 6 5 -0.7
367 4 1 4  6.6
368 4 2 1  4.5
369 4 3 2  3.7
370 4 4 5  3.7
371 4 5 6 -3.3
372 4 6 3  3.0
373 5 1 3  4.1
374 5 2 5  2.4
375 5 3 4  6.0
376 5 4 1  5.1
377 5 5 2  3.5
378 5 6 6  4.0
379 6 1 5  3.8
380 6 2 3  5.8
381 6 3 1  7.0
382 6 4 6  3.8
383 6 5 4  5.0
384 6 6 2  8.6
385 ])
386
387 AT_DATA([glm-miss.sps], [dnl
388 set format = F20.3.
389 data list file='glm.data' notable  fixed /a 1 b 3 c 5 y 7-10(2).
390
391 do if a=6.
392 recode y (else=SYSMIS).
393 end if.
394
395 glm y by   b a c
396   /criteria=alpha(.05)
397   /design = a b c
398   .
399 ])
400
401 AT_CHECK([pspp -O format=csv glm-miss.sps], [0],  [dnl
402 Table: Tests of Between-Subjects Effects
403 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
404 Corrected Model,251.621,14,17.973,4.969,.002
405 Intercept,628.376,1,628.376,173.737,.000
406 a,72.929,4,18.232,5.041,.009
407 b,20.703,5,4.141,1.145,.380
408 c,135.179,5,27.036,7.475,.001
409 Error,54.253,15,3.617,,
410 Total,934.250,30,,,
411 Corrected Total,305.874,29,,,
412 ])
413
414
415
416 AT_DATA([glm-miss2.sps], [dnl
417 set format = F20.3.
418 data list file='glm.data' notable  fixed /a 1 b 3 c 5 y 7-10(2).
419
420 select if a <> 6.
421
422 glm y by   b a c
423   /criteria=alpha(.05)
424   /design = a b c
425   .
426 ])
427
428 AT_CHECK([pspp -O format=csv glm-miss2.sps], [0],  [dnl
429 Table: Tests of Between-Subjects Effects
430 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
431 Corrected Model,251.621,14,17.973,4.969,.002
432 Intercept,628.376,1,628.376,173.737,.000
433 a,72.929,4,18.232,5.041,.009
434 b,20.703,5,4.141,1.145,.380
435 c,135.179,5,27.036,7.475,.001
436 Error,54.253,15,3.617,,
437 Total,934.250,30,,,
438 Corrected Total,305.874,29,,,
439 ])
440
441
442 dnl Now for some missing values in the factor variables.
443
444 AT_DATA([glm-miss3.sps], [dnl
445 set format = F20.3.
446 data list file=glm.data notable  fixed /a 1 b 3 c 5 y 7-10(2).
447
448 do if a=6.
449 recode a (else=SYSMIS).
450 end if.
451
452 glm y by   b a c
453   /criteria=alpha(.05)
454   /design = a b c
455   .
456 ])
457
458 AT_CHECK([pspp -O format=csv glm-miss3.sps], [0],  [dnl
459 Table: Tests of Between-Subjects Effects
460 Source,Type III Sum of Squares,df,Mean Square,F,Sig.
461 Corrected Model,251.621,14,17.973,4.969,.002
462 Intercept,628.376,1,628.376,173.737,.000
463 a,72.929,4,18.232,5.041,.009
464 b,20.703,5,4.141,1.145,.380
465 c,135.179,5,27.036,7.475,.001
466 Error,54.253,15,3.617,,
467 Total,934.250,30,,,
468 Corrected Total,305.874,29,,,
469 ])
470
471 AT_CLEANUP
472