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