Merge 'master' into 'psppsheet'.
[pspp] / tests / language / stats / logistic.at
1
2 AT_BANNER([LOGISTIC REGRESSION])
3
4 dnl These examples are adapted from
5 dnl http://www.uvm.edu/~dhowell/gradstat/psych341/lectures/Logistic%20Regression/LogisticReg1.html
6
7
8
9 m4_define([LOGIT_TEST_DATA],
10   [AT_DATA([lr-data.txt], dnl
11  105.00    1.00    33.00    3.00     2.00   .35  17.00  20.00  .50110  -2.00440 1
12  106.00    1.00    50.00    2.00     3.00   .38   7.00  15.00  .20168  -1.25264 1
13  107.00    1.00    91.00    3.00     2.00   .28  15.00   7.00  .00897  -1.00905 1
14  108.00    1.00    90.00    3.00     2.00   .20   2.00   2.00  .00972  -1.00982 1
15  109.00    1.00    70.00    3.00     3.00   .38  23.00  27.00  .04745  -1.04981 1
16  111.00    2.00    31.00    2.00     2.00   .00  19.00  10.00  .54159   1.84640 1
17  112.00    1.00    91.00    2.00     3.00   .18   6.00  16.00  .00897  -1.00905 1
18  113.00    1.00    81.00    3.00     2.00   .00   3.00   9.00  .01998  -1.02039 1
19  114.00    2.00    15.00    1.00     2.00   .13  19.00  13.00  .81241   1.23090 1
20  116.00    2.00     1.00    1.00     2.00   .88  15.00   7.00  .93102   1.07410 1
21  117.00    1.00    93.00    3.00     2.00   .18   9.00  15.00  .00764  -1.00770 1
22  118.00    2.00    14.00    1.00     3.00   .15  23.00  18.00  .82447   1.21289 1
23  120.00    1.00    91.00    2.00     2.00   .43  17.00  14.00  .00897  -1.00905 1
24  121.00    1.00    55.00    3.00     2.00   .69  20.00  14.00  .14409  -1.16834 1
25  122.00    1.00    70.00    2.00     3.00   .03    .00   6.00  .04745  -1.04981 1
26  123.00    1.00    25.00    2.00     2.00   .45   4.00  10.00  .65789  -2.92301 1
27  125.00    1.00    91.00    2.00     2.00   .13    .00   3.00  .00897  -1.00905 1
28  126.00    1.00    91.00    3.00     3.00   .23   4.00   6.00  .00897  -1.00905 1
29  127.00    1.00    91.00    3.00     2.00   .00   8.00   8.00  .00897  -1.00905 1
30  128.00    2.00    13.00    2.00     2.00   .65  16.00  14.00  .83592   1.19629 1
31  129.00    1.00    50.00    2.00     2.00   .25  20.00  23.00  .20168  -1.25264 1
32  135.00    1.00    90.00    3.00     3.00   .03   5.00  12.00  .00972  -1.00982 1
33  138.00    1.00    70.00    3.00     3.00   .10   1.00   6.00  .04745  -1.04981 1
34  139.00    2.00    19.00    3.00     3.00   .10  11.00  12.00  .75787   1.31949 1
35  149.00    2.00    50.00    3.00     2.00   .03    .00    .00  .20168   4.95826 1
36  204.00    1.00    50.00    3.00     1.00   .13    .00   1.00  .20168  -1.25264 1
37  205.00    1.00    91.00    3.00     3.00   .72  16.00  18.00  .00897  -1.00905 1
38  206.00    2.00    24.00    1.00     1.00   .10   5.00  21.00  .67592   1.47947 1
39  207.00    1.00    80.00    3.00     3.00   .13   6.00   7.00  .02164  -1.02212 1
40  208.00    1.00    87.00    2.00     2.00   .18   9.00  20.00  .01237  -1.01253 1
41  209.00    1.00    70.00    2.00     2.00   .53  15.00  12.00  .04745  -1.04981 1
42  211.00    1.00    55.00    2.00     1.00   .33   8.00   5.00  .14409  -1.16834 1
43  212.00    1.00    56.00    3.00     1.00   .30   6.00  20.00  .13436  -1.15522 1
44  214.00    1.00    54.00    2.00     2.00   .15    .00  16.00  .15439  -1.18258 1
45  215.00    1.00    71.00    3.00     3.00   .35  12.00  12.00  .04391  -1.04592 1
46  217.00    2.00    36.00    1.00     1.00   .10  12.00   8.00  .44049   2.27020 1
47  218.00    1.00    91.00    2.00     2.00   .05  11.00  25.00  .00897  -1.00905 1
48  219.00    1.00    91.00    2.00     2.00  1.23  11.00  24.00  .00897  -1.00905 1
49  220.00    1.00    91.00    2.00     3.00   .08   8.00  11.00  .00897  -1.00905 1
50  221.00    1.00    91.00    2.00     2.00   .33   5.00  11.00  .00897  -1.00905 1
51  222.00    2.00    36.00    2.00     1.00   .18   5.00   3.00  .44049   2.27020 1
52  223.00    1.00    70.00    2.00     3.00   .18  14.00   3.00  .04745  -1.04981 1
53  224.00    1.00    91.00    2.00     2.00   .43   2.00  10.00  .00897  -1.00905 1
54  225.00    1.00    55.00    2.00     1.00   .18   6.00  11.00  .14409  -1.16834 1
55  229.00    2.00    75.00    2.00     2.00   .40  30.00  25.00  .03212  31.12941 1
56  232.00    1.00    91.00    3.00     2.00   .15   6.00   3.00  .00897  -1.00905 1
57  233.00    1.00    70.00    2.00     1.00   .00  11.00   8.00  .04745  -1.04981 1
58  234.00    1.00    54.00    3.00     2.00   .10    .00    .00  .15439  -1.18258 1
59  237.00    1.00    70.00    3.00     2.00   .18   5.00  25.00  .04745  -1.04981 1
60  241.00    1.00    19.00    2.00     3.00   .33  13.00   9.00  .75787  -4.12995 1
61  304.00    2.00    18.00    2.00     2.00   .26  25.00   6.00  .77245   1.29458 1
62  305.00    1.00    88.00    3.00     2.00  1.35  17.00  29.00  .01142  -1.01155 1
63  306.00    1.00    70.00    2.00     3.00   .63  14.00  33.00  .04745  -1.04981 1
64  307.00    1.00    85.00    2.00     2.00  2.65  18.00  14.00  .01452  -1.01474 1
65  308.00    1.00    13.00    2.00     2.00   .23   5.00   5.00  .83592  -6.09442 1
66  309.00    2.00    13.00    2.00     2.00   .23   7.00  17.00  .83592   1.19629 1
67  311.00    2.00     1.00    2.00     2.00   .50  20.00  14.00  .93102   1.07410 1
68  315.00    1.00    19.00    2.00     3.00   .18   1.00  11.00  .75787  -4.12995 1
69  316.00    1.00    88.00    2.00     2.00   .38  12.00  11.00  .01142  -1.01155 2
70  318.00    1.00    88.00    3.00     2.00   .03   5.00   5.00  .01142  -1.01155 3
71  319.00    2.00    18.00    2.00     3.00   .30  15.00  16.00  .77245   1.29458 1
72  321.00    2.00    15.00    2.00     2.00   .63  15.00  18.00  .81241   1.23090 1
73  322.00    1.00    88.00    3.00     2.00   .40  18.00  15.00  .01142  -1.01155 1
74  325.00    2.00    18.00    2.00     3.00  1.00  28.00  18.00  .77245   1.29458 1
75  329.00    1.00    88.00    3.00     2.00   .03   7.00  11.00  .01142  -1.01155 4
76  332.00    2.00     2.00    2.00     2.00   .05   8.00   9.00  .92562   1.08036 1
77 )])
78
79 dnl  Note: In the above data cases 305, 316 318 and 329 have identical values
80 dnl of the 2nd and 3rd variables.  We use this for weight testing.
81
82 AT_SETUP([LOGISTIC REGRESSION basic test])
83
84 LOGIT_TEST_DATA
85
86 AT_DATA([lr-data.sps], [dnl
87 set format = F12.3.
88 set decimal dot.
89 data list notable file='lr-data.txt'
90  list /id outcome survrate prognos amttreat   gsi  avoid intrus   pre_1     lre_1  w *.
91
92 logistic regression
93           variables = outcome with survrate
94         .
95 ])
96
97 AT_CHECK([pspp -O format=csv lr-data.sps], [0],
98   [dnl
99 Table: Dependent Variable Encoding
100 Original Value,Internal Value
101 1.000,0
102 2.000,1
103
104 Table: Case Processing Summary
105 Unweighted Cases,N,Percent
106 Included in Analysis,66,100.000
107 Missing Cases,0,.000
108 Total,66,100.000
109
110 note: Estimation terminated at iteration number 6 because parameter estimates changed by less than 0.001
111
112 Table: Model Summary
113 Step 1,-2 Log likelihood,Cox & Snell R Square,Nagelkerke R Square
114 ,37.323,.455,.659
115
116 Table: Variables in the Equation
117 ,,B,S.E.,Wald,df,Sig.,Exp(B)
118 Step 1,survrate,-.081,.019,17.756,1,.000,.922
119 ,Constant,2.684,.811,10.941,1,.001,14.639
120 ])
121
122
123 AT_CLEANUP
124
125 AT_SETUP([LOGISTIC REGRESSION missing values])
126
127 LOGIT_TEST_DATA
128
129 AT_DATA([lr-data.sps], [dnl
130 set format = F12.3.
131 set decimal dot.
132 data list notable file='lr-data.txt'
133  list /id outcome survrate prognos amttreat   gsi  avoid intrus   pre_1     lre_1  w *.
134
135 missing values survrate (999) avoid (44444).
136
137 logistic regression
138           variables = outcome with survrate avoid
139         .
140 ])
141
142 AT_CHECK([pspp -O format=csv lr-data.sps > run0], [0], [ignore])
143
144 cat >> lr-data.txt << HERE
145  105.00    1.00    999.00    3.00     2.00   .35  17.00  20.00  .50110  -2.00440 1
146  106.00    1.00    999.00    2.00     3.00   .38   7.00  15.00  .20168  -1.25264 1
147  107.00    1.00    5.00      3.00     2.00   .28  44444  34     .00897  -1.00905 1
148 HERE
149
150 AT_CHECK([pspp -O format=csv lr-data.sps > run1], [0], [ignore])
151
152 dnl Only the summary information should be different
153 AT_CHECK([diff run0 run1], [1], [dnl
154 8,10c8,10
155 < Included in Analysis,66,100.000
156 < Missing Cases,0,.000
157 < Total,66,100.000
158 ---
159 > Included in Analysis,66,95.652
160 > Missing Cases,3,4.348
161 > Total,69,100.000
162 ])
163
164 AT_CLEANUP
165
166
167
168 dnl Check that a weighted dataset is interpreted correctly
169 dnl To do this, the same data set is used, one weighted, one not.
170 dnl The weighted dataset omits certain cases which are identical
171 AT_SETUP([LOGISTIC REGRESSION weights])
172
173 LOGIT_TEST_DATA
174
175 AT_DATA([lr-data-unweighted.sps], [dnl
176 set format = F12.3.
177 set decimal dot.
178 data list notable file='lr-data.txt'
179  list /id outcome survrate prognos amttreat   gsi  avoid intrus   pre_1     lre_1  w *.
180
181 logistic regression
182           variables = outcome with survrate
183         .
184 ])
185
186 AT_DATA([lr-data-weighted.sps], [dnl
187 set format = F12.3.
188 set decimal dot.
189 data list notable file='lr-data.txt'
190  list /id outcome survrate prognos amttreat   gsi  avoid intrus   pre_1     lre_1  w *.
191
192 weight by w.
193
194 * Omit duplicate cases.
195 select if id <> 305 and id <> 316 and id <> 318.
196
197 logistic regression
198           variables = outcome with survrate
199         .
200 ])
201
202
203 AT_CHECK([pspp -O format=csv lr-data-unweighted.sps > unweighted-result], [0], [ignore])
204 AT_CHECK([pspp -O format=csv lr-data-weighted.sps > weighted-result], [0], [ignore])
205
206 dnl The only difference should be the summary information, since
207 dnl this displays the unweighted totals.
208 AT_CHECK([diff unweighted-result weighted-result], [1], [dnl
209 8c8
210 < Included in Analysis,66,100.000
211 ---
212 > Included in Analysis,63,100.000
213 10c10
214 < Total,66,100.000
215 ---
216 > Total,63,100.000
217 ])
218
219
220 AT_CLEANUP
221
222
223 dnl Check that the /NOCONST option works as intended.
224 dnl The results this produces are very similar to those
225 dnl at the example in http://www.ats.ucla.edu/stat/SPSS/faq/logregconst.htm
226 AT_SETUP([LOGISTIC REGRESSION without constant])
227
228 AT_DATA([non-const.sps], [dnl
229 set format=F20.3.
230
231 input program.
232  loop #i = 1 to 200.
233   compute female = (#i > 91).
234   end case.
235  end loop.
236 end file.
237 end input program.
238
239 compute constant = 1.
240
241 logistic regression female with constant /noconst.
242 ])
243
244 AT_CHECK([pspp -O format=csv non-const.sps], [0],
245  [dnl
246 Table: Dependent Variable Encoding
247 Original Value,Internal Value
248 .00,0
249 1.00,1
250
251 Table: Case Processing Summary
252 Unweighted Cases,N,Percent
253 Included in Analysis,200,100.000
254 Missing Cases,0,.000
255 Total,200,100.000
256
257 note: Estimation terminated at iteration number 2 because parameter estimates changed by less than 0.001
258
259 Table: Model Summary
260 Step 1,-2 Log likelihood,Cox & Snell R Square,Nagelkerke R Square
261 ,275.637,.008,.011
262
263 Table: Variables in the Equation
264 ,,B,S.E.,Wald,df,Sig.,Exp(B)
265 Step 1,constant,.180,.142,1.616,1,.204,1.198
266 ])
267
268 AT_CLEANUP
269
270
271
272 dnl Check that if somebody passes a dependent variable which is not dichtomous,
273 dnl then an error is raised.
274 AT_SETUP([LOGISTIC REGRESSION non-dichotomous dep var])
275
276 AT_DATA([non-dich.sps], [dnl
277 data list notable list /y x1 x2 x3 x4.
278 begin data.
279 1 2 3 4 5
280 0 2 3 4 8
281 2 3 4 5 6
282 end data.
283
284 logistic regression y with x1 x2 x3 x4.
285 ])
286
287 AT_CHECK([pspp -O format=csv non-dich.sps], [1],
288  [dnl
289 error: Dependent variable's values are not dichotomous.
290 ])
291
292 AT_CLEANUP
293
294
295
296 dnl An example to check the behaviour of LOGISTIC REGRESSION with a categorical
297 dnl variable.  This examṕle was inspired from that at:
298 dnl http://www.ats.ucla.edu/stat/spss/dae/logit.htm 
299 AT_SETUP([LOGISTIC REGRESSION with categorical])
300
301 AT_DATA([lr-cat.data], [dnl
302  620 3.07 2 4 
303  800 4.00 3 9 
304  580 3.40 2 4 
305  600 3.13 2 4 
306  540 2.70 2 4 
307  660 3.31 4 4 
308  480 3.58 1 9 
309  620 4.00 1 9 
310  680 3.98 2 9 
311  580 3.40 4 4 
312  760 3.35 3 4 
313  700 3.72 2 4 
314  460 3.64 1 9 
315  540 3.28 3 4 
316  680 3.48 3 4 
317  740 3.31 1 4 
318  460 3.77 3 4 
319  740 3.54 1 4 
320  600 3.63 3 4 
321  620 3.05 2 4 
322  560 3.04 3 4 
323  520 2.70 3 4 
324  640 3.35 3 4 
325  620 3.58 2 4 
326  660 3.70 4 9 
327  500 2.86 4 4 
328  640 3.50 2 4 
329  720 4.00 3 4 
330  720 3.94 3 4 
331  400 3.65 2 4 
332  800 2.90 2 4 
333  520 2.90 3 4 
334  440 3.24 4 4 
335  580 3.51 2 4 
336  500 3.31 3 4 
337  440 3.22 1 4 
338  540 3.17 1 9 
339  420 3.02 1 4 
340  780 3.22 2 9 
341  440 3.13 4 4 
342  800 3.66 1 9 
343  580 3.32 2 9 
344  480 2.67 2 9 
345  700 4.00 1 9 
346  740 2.97 2 9 
347  700 3.83 2 4 
348  640 3.93 2 4 
349  800 3.90 2 4 
350  400 3.38 2 4 
351  700 3.52 2 4 
352  680 3.00 4 9 
353  540 3.20 1 4 
354  580 4.00 2 4 
355  780 4.00 2 9 
356  220 2.83 3 4 
357  580 3.20 2 9 
358  580 3.50 2 4 
359  620 3.30 1 4 
360  520 3.65 4 9 
361  600 3.38 3 9 
362  660 3.77 3 4 
363  580 2.86 4 9 
364  580 3.46 2 9 
365  560 3.36 3 4 
366  740 4.00 3 9 
367  480 3.44 3 4 
368  640 3.19 4 9 
369  600 3.54 1 9 
370  540 3.38 4 4 
371  500 2.81 3 4 
372  360 2.56 3 4 
373  460 3.15 4 4 
374  460 2.63 2 4 
375  440 2.76 2 4 
376  740 3.62 4 4 
377  380 3.38 2 4 
378  640 3.63 1 9 
379  800 3.73 1 4 
380  660 3.67 2 4 
381  760 3.00 2 9 
382  420 2.96 1 4 
383  740 3.74 4 4 
384  800 3.75 2 4 
385  620 3.40 2 4 
386  660 3.67 3 9 
387  400 3.35 3 4 
388  680 3.14 2 4 
389  660 3.47 3 9 
390  660 3.63 2 9 
391  420 3.41 4 4 
392  660 4.00 1 4 
393  680 3.70 2 4 
394  620 3.23 3 9 
395  520 3.35 3 4 
396  500 4.00 3 4 
397  400 3.36 2 4 
398  700 3.56 1 9 
399  540 3.81 1 9 
400  520 2.68 3 9 
401  540 3.50 2 4 
402  700 4.00 2 4 
403  600 3.64 3 9 
404  800 3.31 3 4 
405  520 3.29 1 4 
406  580 3.69 1 4 
407  380 3.43 3 4 
408  560 3.19 3 4 
409  760 2.81 1 9 
410  540 3.13 2 4 
411  660 3.14 2 9 
412  520 3.81 1 9 
413  680 3.19 4 4 
414  540 3.78 4 4 
415  500 3.57 3 4 
416  660 3.49 2 4 
417  340 3.00 2 9 
418  400 3.15 2 9 
419  420 3.92 4 4 
420  760 3.35 2 9 
421  700 2.94 2 4 
422  540 3.04 1 4 
423  780 3.87 4 4 
424  560 3.78 2 4 
425  700 3.82 3 4 
426  400 2.93 3 4 
427  440 3.45 2 9 
428  800 3.47 3 4 
429  340 3.15 3 4 
430  520 4.00 1 9 
431  520 3.15 3 4 
432  600 2.98 2 9 
433  420 2.69 2 4 
434  460 3.44 2 4 
435  620 3.71 1 9 
436  480 3.13 2 4 
437  580 3.40 3 4 
438  540 3.39 3 9 
439  540 3.94 3 4 
440  440 2.98 3 4 
441  380 3.59 4 4 
442  500 2.97 4 4 
443  340 2.92 3 4 
444  440 3.15 2 4 
445  600 3.48 2 4 
446  420 2.67 3 4 
447  460 3.07 2 4 
448  460 3.45 3 9 
449  480 3.39 4 4 
450  480 2.78 3 4 
451  720 3.42 2 9 
452  680 3.67 2 9 
453  800 3.89 2 4 
454  360 3.00 3 4 
455  620 3.17 2 9 
456  700 3.52 4 9 
457  540 3.19 2 4 
458  580 3.30 2 4 
459  800 4.00 3 9 
460  660 3.33 2 4 
461  380 3.34 3 4 
462  720 3.84 3 4 
463  600 3.59 2 4 
464  500 3.03 3 4 
465  640 3.81 2 4 
466  540 3.49 1 9 
467  680 3.85 3 9 
468  540 3.84 2 9 
469  460 2.93 3 4 
470  380 2.94 3 4 
471  620 3.22 2 4 
472  740 3.37 4 4 
473  620 4.00 2 4 
474  800 3.74 1 9 
475  400 3.31 3 4 
476  540 3.46 4 4 
477  620 3.18 2 9 
478  480 2.91 1 9 
479  300 2.84 2 9 
480  440 2.48 4 4 
481  640 2.79 2 4 
482  400 3.23 4 9 
483  680 3.46 2 9 
484  620 3.37 1 9 
485  700 3.92 2 4 
486  620 3.37 2 9 
487  620 3.63 2 4 
488  620 3.95 3 9 
489  560 2.52 2 4 
490  520 2.62 2 4 
491  600 3.35 2 4 
492  700 4.00 1 4 
493  640 3.67 3 4 
494  640 4.00 3 4 
495  520 2.93 4 4 
496  620 3.21 4 4 
497  680 3.99 3 4 
498  660 3.34 3 4 
499  700 3.45 3 4 
500  560 3.36 1 9 
501  800 2.78 2 4 
502  500 3.88 4 4 
503  700 3.65 2 4 
504  680 3.76 3 9 
505  660 3.07 3 4 
506  580 3.46 4 4 
507  460 2.87 2 4 
508  600 3.31 4 4 
509  620 3.94 4 4 
510  400 3.05 2 4 
511  800 3.43 2 9 
512  600 3.58 1 9 
513  580 3.36 2 4 
514  540 3.16 3 4 
515  500 2.71 2 4 
516  600 3.28 3 4 
517  600 2.82 4 4 
518  460 3.58 2 4 
519  520 2.85 3 4 
520  740 3.52 4 9 
521  500 3.95 4 4 
522  560 3.61 3 4 
523  620 3.45 2 9 
524  640 3.51 2 4 
525  660 3.44 2 9 
526  660 2.91 3 9 
527  540 3.28 1 4 
528  560 2.98 1 9 
529  800 3.97 1 4 
530  720 3.77 3 4 
531  720 3.64 1 9 
532  480 3.71 4 9 
533  680 3.34 2 4 
534  680 3.11 2 4 
535  540 2.81 3 4 
536  620 3.75 2 9 
537  540 3.12 1 4 
538  560 3.48 2 9 
539  720 3.40 3 4 
540  680 3.90 1 4 
541  640 3.76 3 4 
542  560 3.16 1 4 
543  520 3.30 2 9 
544  640 3.12 3 4 
545  580 3.57 3 4 
546  540 3.55 4 9 
547  780 3.63 4 9 
548  600 3.89 1 9 
549  800 4.00 1 9 
550  580 3.29 4 4 
551  360 3.27 3 4 
552  800 4.00 2 9 
553  640 3.52 4 4 
554  720 3.45 4 4 
555  580 3.06 2 4 
556  580 3.02 2 4 
557  500 3.60 3 9 
558  580 3.12 3 9 
559  600 2.82 4 4 
560  620 3.99 3 4 
561  700 4.00 3 4 
562  480 4.00 2 4 
563  560 2.95 2 4 
564  560 4.00 3 4 
565  560 2.65 3 9 
566  400 3.08 2 4 
567  480 2.62 2 9 
568  640 3.86 3 4 
569  480 3.57 2 4 
570  540 3.51 2 4 
571  380 3.33 4 4 
572  680 3.64 3 4 
573  400 3.51 3 4 
574  340 2.90 1 4 
575  700 3.08 2 4 
576  480 3.02 1 9 
577  600 3.15 2 9 
578  780 3.80 3 9 
579  520 3.74 2 9 
580  520 3.51 2 4 
581  640 3.73 3 4 
582  560 3.32 4 4 
583  620 2.85 2 4 
584  700 3.28 1 4 
585  760 4.00 1 9 
586  800 3.60 2 4 
587  580 3.34 2 4 
588  540 3.77 2 9 
589  640 3.17 2 4 
590  540 3.02 4 4 
591  680 3.08 4 4 
592  680 3.31 2 4 
593  680 2.96 3 9 
594  700 2.88 2 4 
595  580 3.77 4 4 
596  540 3.49 2 9 
597  700 3.56 2 9 
598  600 3.56 2 9 
599  560 3.59 2 4 
600  640 2.94 2 9 
601  560 3.33 4 4 
602  620 3.69 3 4 
603  680 3.27 2 9 
604  460 3.14 3 4 
605  500 3.53 4 4 
606  620 3.33 3 4 
607  600 3.62 3 4 
608  500 3.01 4 4 
609  740 3.34 4 4 
610  560 3.69 3 9 
611  620 3.95 3 9 
612  740 3.86 2 9 
613  800 3.53 1 9 
614  620 3.78 3 4 
615  700 3.27 2 4 
616  540 3.78 2 9 
617  700 3.65 2 4 
618  800 3.22 1 9 
619  560 3.59 2 9 
620  800 3.15 4 4 
621  520 3.90 3 9 
622  520 3.74 4 9 
623  480 2.55 1 4 
624  800 4.00 4 4 
625  620 3.09 4 4 
626  560 3.49 4 4 
627  500 3.17 3 4 
628  480 3.40 2 4 
629  460 2.98 1 4 
630  580 3.58 1 9 
631  640 3.30 2 4 
632  480 3.45 2 4 
633  440 3.17 2 4 
634  660 3.32 1 4 
635  500 3.08 3 4 
636  660 3.94 2 4 
637  720 3.31 1 4 
638  460 3.64 3 9 
639  500 2.93 4 4 
640  800 3.54 3 4 
641  580 2.93 2 4 
642  620 3.61 1 9 
643  500 2.98 3 4 
644  660 4.00 2 9 
645  560 3.24 4 4 
646  560 2.42 2 4 
647  580 3.80 2 4 
648  500 3.23 4 4 
649  680 2.42 1 9 
650  580 3.46 3 4 
651  800 3.91 3 4 
652  700 2.90 4 4 
653  520 3.12 2 4 
654  300 2.92 4 4 
655  560 3.43 3 4 
656  620 3.63 3 4 
657  500 2.79 4 4 
658  360 3.14 1 4 
659  640 3.94 2 9 
660  460 3.99 3 9 
661  300 3.01 3 4 
662  520 2.73 2 4 
663  600 3.47 2 9 
664  580 3.25 1 4 
665  520 3.10 4 4 
666  620 3.43 3 4 
667  380 2.91 4 4 
668  660 3.59 3 4 
669  660 3.95 2 9 
670  540 3.33 3 4 
671  740 4.00 3 4 
672  640 3.38 3 4 
673  600 3.89 3 4 
674  720 3.88 3 4 
675  580 4.00 3 4 
676  420 2.26 4 4 
677  520 4.00 2 9 
678  800 3.70 1 9 
679  700 4.00 1 9 
680  480 3.43 2 4 
681  660 3.45 4 4 
682  520 3.25 3 4 
683  560 2.71 3 4 
684  600 3.32 2 4 
685  580 2.88 2 4 
686  660 3.88 2 9 
687  600 3.22 1 4 
688  580 4.00 1 4 
689  660 3.60 3 9 
690  500 3.35 2 4 
691  520 2.98 2 4 
692  660 3.49 2 9 
693  560 3.07 2 4 
694  500 3.13 2 9 
695  720 3.50 3 9 
696  440 3.39 2 9 
697  640 3.95 2 9 
698  380 3.61 3 4 
699  800 3.05 2 9 
700  520 3.19 3 9 
701  600 3.40 3 4 
702 ])
703
704 AT_DATA([lr-cat.sps], [dnl
705 set format=F20.3.
706
707 data list notable list file='lr-cat.data' /b1 b2 bcat y.
708
709 logistic regression
710           y with b1 b2 bcat
711            /categorical = bcat
712            .
713 ])
714
715 AT_CHECK([pspp -O format=csv lr-cat.sps], [0],
716  [dnl
717 Table: Dependent Variable Encoding
718 Original Value,Internal Value
719 4.000,0
720 9.000,1
721
722 Table: Case Processing Summary
723 Unweighted Cases,N,Percent
724 Included in Analysis,400,100.000
725 Missing Cases,0,.000
726 Total,400,100.000
727
728 note: Estimation terminated at iteration number 4 because parameter estimates changed by less than 0.001
729
730 Table: Model Summary
731 Step 1,-2 Log likelihood,Cox & Snell R Square,Nagelkerke R Square
732 ,458.517,.098,.138
733
734 Table: Categorical Variables' Codings
735 ,,,Parameter coding,,
736 ,,Frequency,(1),(2),(3)
737 bcat,1.000,61,1,0,0
738 ,2.000,151,0,1,0
739 ,3.000,121,0,0,1
740 ,4.000,67,0,0,0
741
742 Table: Variables in the Equation
743 ,,B,S.E.,Wald,df,Sig.,Exp(B)
744 Step 1,b1,.002,.001,4.284,1,.038,1.002
745 ,b2,.804,.332,5.872,1,.015,2.235
746 ,bcat,,,20.895,3,.000,
747 ,bcat(1),1.551,.418,13.788,1,.000,4.718
748 ,bcat(2),.876,.367,5.706,1,.017,2.401
749 ,bcat(3),.211,.393,.289,1,.591,1.235
750 ,Constant,-5.541,1.138,23.709,1,.000,.004
751 ])
752
753 AT_CLEANUP
754
755
756
757 dnl  This example is inspired by http://www.ats.ucla.edu/stat/spss/output/logistic.htm
758 AT_SETUP([LOGISTIC REGRESSION with cat var 2])
759
760 AT_DATA([lr-cat2.data], [dnl
761      60.00     1.00      8.00     50.00 
762      47.00      .00      9.00     42.00 
763      57.00     1.00      7.00     53.00 
764      60.00      .00      8.00     53.00 
765      68.00      .00      8.00     66.00 
766      63.00      .00      8.00     55.00 
767      65.00      .00      8.00     63.00 
768      52.00      .00      8.00     61.00 
769      34.00      .00      9.00     42.00 
770      37.00      .00      8.00     39.00 
771      68.00     1.00      9.00     69.00 
772      60.00      .00      9.00     61.00 
773      44.00      .00      9.00     58.00 
774      42.00      .00      8.00     47.00 
775      57.00     1.00      7.00     61.00 
776      55.00     1.00      8.00     50.00 
777      55.00      .00      9.00     58.00 
778      44.00      .00      8.00     63.00 
779      50.00     1.00      9.00     66.00 
780      44.00      .00      8.00     39.00 
781      55.00      .00      8.00     58.00 
782      44.00      .00      8.00     50.00 
783      47.00     1.00      7.00     34.00 
784      48.00      .00      8.00     44.00 
785      45.00      .00      7.00     31.00 
786      43.00      .00      8.00     50.00 
787      39.00      .00      8.00     42.00 
788      63.00      .00      9.00     50.00 
789      47.00      .00      8.00     58.00 
790      42.00      .00      7.00     50.00 
791      50.00      .00      9.00     36.00 
792      47.00      .00      7.00     33.00 
793      60.00      .00      9.00     61.00 
794      47.00      .00      7.00     42.00 
795      68.00     1.00      9.00     69.00 
796      52.00      .00      8.00     54.00 
797      63.00     1.00      9.00     61.00 
798      65.00     1.00      9.00     61.00 
799      63.00     1.00      9.00     53.00 
800      57.00      .00      8.00     51.00 
801      34.00      .00      8.00     36.00 
802      50.00      .00      8.00     39.00 
803      52.00     1.00      7.00     56.00 
804      45.00      .00      7.00     34.00 
805      47.00     1.00      7.00     53.00 
806      34.00      .00      7.00     39.00 
807      50.00     1.00      8.00     55.00 
808      60.00      .00      9.00     58.00 
809      63.00      .00      8.00     58.00 
810      35.00      .00      7.00     51.00 
811      50.00      .00      8.00     58.00 
812      68.00      .00      8.00     63.00 
813      41.00      .00      9.00     34.00 
814      47.00      .00      8.00     47.00 
815      76.00      .00      9.00     64.00 
816      44.00      .00      8.00     44.00 
817      36.00      .00      9.00     50.00 
818      68.00     1.00      9.00     55.00 
819      47.00     1.00      8.00     50.00 
820      50.00      .00      7.00     53.00 
821      68.00      .00      8.00     74.00 
822      39.00      .00      7.00     44.00 
823      50.00      .00      8.00     55.00 
824      52.00      .00      9.00     61.00 
825      47.00      .00      8.00     53.00 
826      39.00      .00      7.00     47.00 
827      55.00     1.00      9.00     49.00 
828      68.00     1.00      8.00     50.00 
829      52.00     1.00      9.00     63.00 
830      55.00      .00      8.00     58.00 
831      57.00      .00      8.00     55.00 
832      66.00     1.00      9.00     61.00 
833      65.00     1.00      7.00     58.00 
834      42.00      .00      7.00     42.00 
835      68.00     1.00      7.00     59.00 
836      60.00     1.00      9.00     61.00 
837      52.00      .00      8.00     55.00 
838      57.00     1.00      7.00     54.00 
839      42.00      .00      9.00     50.00 
840      42.00      .00      8.00     47.00 
841      57.00      .00      8.00     50.00 
842      47.00      .00      7.00     45.00 
843      44.00      .00      7.00     40.00 
844      43.00      .00      9.00     55.00 
845      31.00      .00      8.00     39.00 
846      37.00      .00      7.00     33.00 
847      63.00     1.00      7.00     63.00 
848      47.00      .00      8.00     39.00 
849      57.00     1.00      8.00     63.00 
850      52.00      .00      8.00     44.00 
851      44.00      .00      7.00     35.00 
852      52.00      .00      7.00     55.00 
853      55.00      .00      7.00     69.00 
854      52.00      .00      8.00     53.00 
855      55.00      .00      9.00     61.00 
856      65.00     1.00      9.00     63.00 
857      55.00      .00      8.00     44.00 
858      63.00      .00      7.00     65.00 
859      44.00      .00      7.00     39.00 
860      47.00      .00      7.00     36.00 
861      63.00     1.00      9.00     55.00 
862      68.00      .00      8.00     66.00 
863      34.00      .00      8.00     39.00 
864      47.00      .00      9.00     50.00 
865      50.00      .00      9.00     58.00 
866      63.00      .00      8.00     66.00 
867      44.00      .00      7.00     34.00 
868      44.00      .00      8.00     50.00 
869      50.00      .00      8.00     53.00 
870      47.00     1.00      9.00     69.00 
871      65.00      .00      9.00     58.00 
872      57.00      .00      8.00     47.00 
873      39.00      .00      8.00     39.00 
874      47.00      .00      8.00     53.00 
875      50.00     1.00      7.00     63.00 
876      50.00      .00      8.00     50.00 
877      63.00      .00      9.00     53.00 
878      73.00     1.00      9.00     61.00 
879      44.00      .00      7.00     47.00 
880      47.00      .00      8.00     42.00 
881      47.00      .00      8.00     58.00 
882      36.00      .00      7.00     61.00 
883      57.00     1.00      8.00     55.00 
884      53.00     1.00      8.00     57.00 
885      63.00      .00      7.00     66.00 
886      50.00      .00      8.00     34.00 
887      47.00      .00      9.00     48.00 
888      57.00     1.00      8.00     58.00 
889      39.00      .00      8.00     53.00 
890      42.00      .00      8.00     42.00 
891      42.00      .00      9.00     31.00 
892      42.00      .00      8.00     72.00 
893      46.00      .00      8.00     44.00 
894      55.00      .00      8.00     42.00 
895      42.00      .00      8.00     47.00 
896      50.00      .00      8.00     44.00 
897      44.00      .00      9.00     39.00 
898      73.00     1.00      8.00     69.00 
899      71.00     1.00      9.00     58.00 
900      50.00      .00      9.00     49.00 
901      63.00     1.00      7.00     54.00 
902      42.00      .00      8.00     36.00 
903      47.00      .00      7.00     42.00 
904      39.00      .00      9.00     26.00 
905      63.00      .00      8.00     58.00 
906      50.00      .00      8.00     55.00 
907      65.00     1.00      8.00     55.00 
908      76.00     1.00      9.00     67.00 
909      71.00     1.00      8.00     66.00 
910      39.00      .00      9.00     47.00 
911      47.00     1.00      9.00     63.00 
912      60.00      .00      7.00     50.00 
913      63.00      .00      9.00     55.00 
914      54.00     1.00      9.00     55.00 
915      55.00     1.00      8.00     58.00 
916      57.00      .00      8.00     61.00 
917      55.00     1.00      9.00     63.00 
918      42.00      .00      7.00     50.00 
919      50.00      .00      8.00     44.00 
920      55.00      .00      8.00     42.00 
921      42.00      .00      7.00     50.00 
922      34.00      .00      8.00     39.00 
923      65.00      .00      9.00     46.00 
924      52.00      .00      7.00     58.00 
925      44.00      .00      8.00     39.00 
926      65.00     1.00      9.00     66.00 
927      47.00      .00      8.00     42.00 
928      41.00      .00      7.00     39.00 
929      68.00      .00      9.00     63.00 
930      63.00     1.00      8.00     72.00 
931      52.00      .00      8.00     53.00 
932      57.00      .00      8.00     50.00 
933      68.00      .00      8.00     55.00 
934      42.00      .00      8.00     56.00 
935      47.00      .00      8.00     48.00 
936      73.00     1.00      9.00     58.00 
937      39.00      .00      8.00     50.00 
938      63.00     1.00      9.00     69.00 
939      60.00      .00      8.00     55.00 
940      65.00     1.00      9.00     66.00 
941      73.00     1.00      8.00     63.00 
942      52.00      .00      8.00     55.00 
943      36.00      .00      8.00     42.00 
944      28.00      .00      7.00     44.00 
945      47.00      .00      8.00     44.00 
946      57.00      .00      7.00     47.00 
947      34.00      .00      7.00     29.00 
948      47.00      .00      9.00     66.00 
949      57.00      .00      8.00     58.00 
950      60.00     1.00      9.00     50.00 
951      50.00      .00      9.00     47.00 
952      73.00     1.00      9.00     55.00 
953      52.00     1.00      8.00     47.00 
954      55.00      .00      8.00     53.00 
955      47.00      .00      8.00     53.00 
956      50.00      .00      8.00     61.00 
957      61.00      .00      7.00     44.00 
958      52.00      .00      9.00     53.00 
959      47.00      .00      7.00     40.00 
960      47.00      .00      7.00     50.00 
961 ])
962
963 AT_DATA([stringcat.sps], [dnl
964 set format=F20.3.
965 data list notable file='lr-cat2.data' list /read honcomp wiz science *.
966
967 string ses(a1).
968 recode wiz (7 = "a") (8 = "b") (9 = "c") into ses.
969
970 logistic regression honcomp with read science ses
971          /categorical = ses.
972
973 ])
974
975 AT_CHECK([pspp -O format=csv stringcat.sps], [0],
976  [dnl
977 Table: Dependent Variable Encoding
978 Original Value,Internal Value
979 .000,0
980 1.000,1
981
982 Table: Case Processing Summary
983 Unweighted Cases,N,Percent
984 Included in Analysis,200,100.000
985 Missing Cases,0,.000
986 Total,200,100.000
987
988 note: Estimation terminated at iteration number 5 because parameter estimates changed by less than 0.001
989
990 Table: Model Summary
991 Step 1,-2 Log likelihood,Cox & Snell R Square,Nagelkerke R Square
992 ,165.701,.280,.408
993
994 Table: Categorical Variables' Codings
995 ,,,Parameter coding,
996 ,,Frequency,(1),(2)
997 ses,a,47,1,0
998 ,b,95,0,1
999 ,c,58,0,0
1000
1001 Table: Variables in the Equation
1002 ,,B,S.E.,Wald,df,Sig.,Exp(B)
1003 Step 1,read,.098,.025,15.199,1,.000,1.103
1004 ,science,.066,.027,5.867,1,.015,1.068
1005 ,ses,,,6.690,2,.035,
1006 ,ses(1),.058,.532,.012,1,.913,1.060
1007 ,ses(2),-1.013,.444,5.212,1,.022,.363
1008 ,Constant,-9.561,1.662,33.113,1,.000,.000
1009 ])
1010
1011 AT_CLEANUP