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