Logistic Regression: Ignore cases with missing dependent variables. 20121123030503/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 23 Nov 2012 08:01:36 +0000 (09:01 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 23 Nov 2012 08:01:36 +0000 (09:01 +0100)
Prior to this change, cases with missing values in the predictor
variables were ignored, but cases with missing values only in the
dependent variable would provoke an error.  Subsequent to this change
such cases are also ignored.  This seems to be the behaviour of other
software, despite what their documentation may suggest.

src/language/stats/logistic.c
tests/language/stats/logistic.at

index 8e21b175e1d1630938d8aacb95353d45f99d2448..2c214516b711dc05d79e2bff025053871a1e1c0e 100644 (file)
@@ -478,6 +478,11 @@ initial_pass (const struct lr_spec *cmd, struct lr_result *res, struct casereade
       double weight = dict_get_case_weight (cmd->dict, c, &res->warn_bad_weight);
       const union value *depval = case_data (c, cmd->dep_var);
 
+      if (var_is_value_missing (cmd->dep_var, depval, cmd->exclude))
+       {
+         missing = true;
+       }
+      else 
       for (v = 0; v < cmd->n_indep_vars; ++v)
        {
          const union value *val = case_data (c, cmd->indep_vars[v]);
@@ -623,6 +628,12 @@ run_lr (const struct lr_spec *cmd, struct casereader *input,
                                            NULL,
                                            NULL);
 
+  input = casereader_create_filter_missing (input,
+                                           &cmd->dep_var,
+                                           1,
+                                           cmd->exclude,
+                                           NULL,
+                                           NULL);
 
   work.hessian = gsl_matrix_calloc (work.beta_hat->size, work.beta_hat->size);
 
index b175244bdb27cd123de22a7d045dcf1c1c588124..b7285e26d1e3f17ba28bc51d8c359cd24c8ccd2d 100644 (file)
@@ -140,7 +140,7 @@ set decimal dot.
 data list notable file='lr-data.txt'
  list /id outcome survrate prognos amttreat   gsi  avoid intrus   pre_1     lre_1  w *.
 
-missing values survrate (999) avoid (44444).
+missing values survrate (999) avoid (44444) outcome (99).
 
 logistic regression
          variables = outcome with survrate avoid
@@ -149,10 +149,12 @@ logistic regression
 
 AT_CHECK([pspp -O format=csv lr-data.sps > run0], [0], [ignore])
 
+dnl Append some cases with missing values into the data.
 cat >> lr-data.txt << HERE
  105.00    1.00    999.00    3.00     2.00   .35  17.00  20.00  .50110  -2.00440 1
  106.00    1.00    999.00    2.00     3.00   .38   7.00  15.00  .20168  -1.25264 1
  107.00    1.00    5.00      3.00     2.00   .28  44444  34     .00897  -1.00905 1
+ 108.00    99      5.00      3.00     2.00   .28  4      34     .00897  -1.00905 1
 HERE
 
 AT_CHECK([pspp -O format=csv lr-data.sps > run1], [0], [ignore])
@@ -164,9 +166,9 @@ AT_CHECK([diff run0 run1], [1], [dnl
 < Missing Cases,0,.000
 < Total,66,100.000
 ---
-> Included in Analysis,66,95.652
-> Missing Cases,3,4.348
-> Total,69,100.000
+> Included in Analysis,66,94.286
+> Missing Cases,4,5.714
+> Total,70,100.000
 ])
 
 AT_CLEANUP