Logistical Regression Dialog: Automatically mark appropriate variables as categorical
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 4 Jan 2016 18:32:34 +0000 (19:32 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 4 Jan 2016 18:43:18 +0000 (19:43 +0100)
In the syntax generator ordinal, nominal or string variables are now marked as /CATEGORICAL

Closes bug #46749

NEWS
src/ui/gui/psppire-dialog-action-logistic.c
src/ui/gui/psppire-var-view.c
src/ui/gui/psppire-var-view.h

diff --git a/NEWS b/NEWS
index ad18b3f1caf58d3a7b816a6944e05f276daf1bab..0318b285c77f6d0b5b121ef99fa8aeccceb8160b 100644 (file)
--- 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
index 8640beef9bb3e23f3d22565f6459eb3e0249a381..0c4dc19cdc27895565b6376c2a30071abf6d5a04 100644 (file)
@@ -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);
index f8625d5bd749ec2df021c924d0891793b6e28b69..0e72cb3717d784c1df0f7a0fba1d6561a72d0692 100644 (file)
@@ -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
index 430265d4fd8adafb2bf1aba9162eda5586171bfd..c53ac6e1d75b7aa3dacd9e262fb407cd5195cf32 100644 (file)
@@ -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);