From: John Darrington Date: Wed, 14 Nov 2012 10:47:09 +0000 (+0100) Subject: Logistic Regression: Fix crash if categorical variable has no distinct values X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=927c175dee018252a43dc3562c658c47b9436e82;p=pspp Logistic Regression: Fix crash if categorical variable has no distinct values --- diff --git a/src/language/stats/logistic.c b/src/language/stats/logistic.c index 91a16488bd..f85b6ec39e 100644 --- a/src/language/stats/logistic.c +++ b/src/language/stats/logistic.c @@ -560,6 +560,23 @@ run_lr (const struct lr_spec *cmd, struct casereader *input, if (NULL == beta_hat) return false; + + for (i = 0; i < cmd->n_cat_predictors; ++i) + { + if (1 >= categoricals_n_count (work.cats, i)) + { + struct string str; + ds_init_empty (&str); + + interaction_to_string (cmd->cat_predictors[i], &str); + + msg (ME, _("Category %s does not have at least two distinct values. Logistic regression will not be run."), + ds_cstr(&str)); + ds_destroy (&str); + return false; + } + } + output_depvarmap (cmd, &work); case_processing_summary (&work); diff --git a/tests/language/stats/logistic.at b/tests/language/stats/logistic.at index 7db121338b..b4d9eef458 100644 --- a/tests/language/stats/logistic.at +++ b/tests/language/stats/logistic.at @@ -1,4 +1,3 @@ - AT_BANNER([LOGISTIC REGRESSION]) dnl These examples are adapted from @@ -1009,3 +1008,23 @@ Step 1,read,.098,.025,15.199,1,.000,1.103 ]) AT_CLEANUP + + +dnl Check that it doesn't crash if a categorical variable +dnl has only one distinct value +AT_SETUP([LOGISTIC REGRESSION identical categories]) + +AT_DATA([crash.sps], [dnl +data list notable list /y x1 x2*. +begin data +0 1 1 +1 2 1 +end data. + +logistic regression y with x1 x2 + /categorical = x2. +]) + +AT_CHECK([pspp -O format=csv crash.sps], [1], [ignore]) + +AT_CLEANUP