From: John Darrington Date: Mon, 4 Jan 2016 18:32:34 +0000 (+0100) Subject: Logistical Regression Dialog: Automatically mark appropriate variables as categorical X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=c2d972816fce591524db963390a97ff32d55117c Logistical Regression Dialog: Automatically mark appropriate variables as categorical In the syntax generator ordinal, nominal or string variables are now marked as /CATEGORICAL Closes bug #46749 --- diff --git a/NEWS b/NEWS index ad18b3f1ca..0318b285c7 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,11 @@ Changes from 0.8.5 to 0.9.0: - The status of dialog box widgets are now preserved between calls to the same dialog box for the same dataset. + - The dialog box for the Logistic Regression command will now + infer that string variables or any varible with a "measure" + of Nominal or Ordinal are to be treated as categorical variables + and will generate syntax accordingly. + * The pspp-convert utility can now decrypt encrypted syntax files. The encrypted syntax file format is unacceptably insecure, so to discourage its use PSPP and PSPPIRE do not directly read or write diff --git a/src/ui/gui/psppire-dialog-action-logistic.c b/src/ui/gui/psppire-dialog-action-logistic.c index 8640beef9b..0c4dc19cdc 100644 --- a/src/ui/gui/psppire-dialog-action-logistic.c +++ b/src/ui/gui/psppire-dialog-action-logistic.c @@ -163,10 +163,42 @@ generate_syntax (PsppireDialogAction *a) g_string_append (strx, dep); - g_string_append (strx, " WITH "); + g_string_append (strx, " WITH"); - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->indep_vars), 0, strx); + GSList *vars = psppire_var_view_list_names (PSPPIRE_VAR_VIEW (rd->indep_vars), 0); + GSList *node = vars; + GString *var_names = g_string_new (""); + while (node) + { + g_string_prepend (var_names, var_get_name (node->data)); + g_string_prepend (var_names, " "); + node = node->next; + } + + g_string_append (strx, var_names->str); + g_string_free (var_names, TRUE); + + + GString *categoricals = g_string_new (""); + for (node = vars; node; node = node->next) + { + const struct variable *v = node->data; + enum measure m = var_get_measure (v); + + if (m == MEASURE_NOMINAL || m == MEASURE_ORDINAL || var_is_alpha (v)) + { + g_string_prepend (categoricals, var_get_name (v)); + g_string_prepend (categoricals, " "); + } + } + if (0 != strcmp (categoricals->str, "")) + g_string_prepend (categoricals, "\n\t/CATEGORICAL ="); + + g_string_append (strx, categoricals->str); + g_string_free (categoricals, TRUE); + g_slist_free (vars); + g_string_append (strx, "\n\t/CRITERIA ="); g_string_append_printf (strx, " CUT(%g)", rd->cut_point); diff --git a/src/ui/gui/psppire-var-view.c b/src/ui/gui/psppire-var-view.c index f8625d5bd7..0e72cb3717 100644 --- a/src/ui/gui/psppire-var-view.c +++ b/src/ui/gui/psppire-var-view.c @@ -371,6 +371,31 @@ psppire_var_view_append_names (PsppireVarView *vv, gint column, GString *string) return n_vars; } +/* Return a linked list of struct variables which are + contained in VV. + The caller is responsible for freeing the returned list. + The variables however are owned by their dictionary + and should not be freed. + */ +GSList * +psppire_var_view_list_names (PsppireVarView *vv, gint column) +{ + GtkTreeIter iter; + GSList *list = NULL; + + if ( psppire_var_view_get_iter_first (vv, &iter) ) + { + do + { + const struct variable *var = psppire_var_view_get_variable (vv, column, &iter); + list = g_slist_prepend (list, var); + } + while (psppire_var_view_get_iter_next (vv, &iter)); + } + + return list; +} + /* Append the names of selected variables to STR diff --git a/src/ui/gui/psppire-var-view.h b/src/ui/gui/psppire-var-view.h index 430265d4fd..c53ac6e1d7 100644 --- a/src/ui/gui/psppire-var-view.h +++ b/src/ui/gui/psppire-var-view.h @@ -66,6 +66,9 @@ gboolean psppire_var_view_get_iter_first (PsppireVarView *vv, GtkTreeIter *iter) gboolean psppire_var_view_get_iter_next (PsppireVarView *vv, GtkTreeIter *iter); +GSList *psppire_var_view_list_names (PsppireVarView *vv, gint column); + + const struct variable * psppire_var_view_get_variable (PsppireVarView *vv, gint column, GtkTreeIter *iter); const struct variable * psppire_var_view_get_var_from_model (GtkTreeModel *, gint column, GtkTreeIter *iter);