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