Oneway: Remove group_values struct from show_contrast_coeffs
[pspp] / src / language / stats / oneway.c
index 6756882d33fb28a7fd8559a31c76a6cfe86bb799..2423215f3ac228c5d866801fec53194d2cf94dde 100644 (file)
@@ -86,8 +86,6 @@ struct oneway_spec
   size_t n_vars;
   const struct variable **vars;
 
-  const struct dictionary *dict;
-
   const struct variable *indep_var;
 
   enum statistics stats;
@@ -97,6 +95,9 @@ struct oneway_spec
 
   /* List of contrasts */
   struct ll_list contrast_list;
+
+  /* The weight variable */
+  const struct variable *wv;
 };
 
 
@@ -129,7 +130,7 @@ struct oneway_workspace
 
 /* Routines to show the output tables */
 static void show_anova_table (const struct oneway_spec *, const struct oneway_workspace *);
-static void show_descriptives (const struct oneway_spec *, const struct dictionary *dict);
+static void show_descriptives (const struct oneway_spec *);
 static void show_homogeneity (const struct oneway_spec *);
 
 static void output_oneway (const struct oneway_spec *, struct oneway_workspace *ws);
@@ -138,6 +139,7 @@ static void run_oneway (const struct oneway_spec *cmd, struct casereader *input,
 int
 cmd_oneway (struct lexer *lexer, struct dataset *ds)
 {
+  const struct dictionary *dict = dataset_dict (ds);  
   struct oneway_spec oneway ;
   oneway.n_vars = 0;
   oneway.vars = NULL;
@@ -145,7 +147,7 @@ cmd_oneway (struct lexer *lexer, struct dataset *ds)
   oneway.stats = 0;
   oneway.missing_type = MISS_ANALYSIS;
   oneway.exclude = MV_ANY;
-  oneway.dict = dataset_dict (ds);  
+  oneway.wv = dict_get_weight (dict);
 
   ll_init (&oneway.contrast_list);
 
@@ -159,14 +161,14 @@ cmd_oneway (struct lexer *lexer, struct dataset *ds)
       lex_match (lexer, '=');
     }
 
-  if (!parse_variables_const (lexer, oneway.dict,
+  if (!parse_variables_const (lexer, dict,
                              &oneway.vars, &oneway.n_vars,
                              PV_NO_DUPLICATE | PV_NUMERIC))
     goto error;
 
   lex_force_match (lexer, T_BY);
 
-  oneway.indep_var = parse_variable_const (lexer, oneway.dict);
+  oneway.indep_var = parse_variable_const (lexer, dict);
 
   while (lex_token (lexer) != '.')
     {
@@ -261,7 +263,9 @@ cmd_oneway (struct lexer *lexer, struct dataset *ds)
     struct casereader *group;
     bool ok;
 
-    grouper = casegrouper_create_splits (proc_open (ds), oneway.dict);
+
+
+    grouper = casegrouper_create_splits (proc_open (ds), dict);
     while (casegrouper_get_next_group (grouper, &group))
       run_oneway (&oneway, group, ds);
     ok = casegrouper_destroy (grouper);
@@ -315,17 +319,21 @@ run_oneway (const struct oneway_spec *cmd,
   struct dictionary *dict = dataset_dict (ds);
   struct casereader *reader;
   struct ccase *c;
-  const struct variable *wv = dict_get_weight (dict);
+
 
   struct oneway_workspace ws;
 
   ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws));
 
+
   for (v = 0; v < cmd->n_vars; ++v)
     {
+      struct categoricals *cats = categoricals_create (&cmd->indep_var, 1,
+                                                  cmd->wv, cmd->exclude);
+
       ws.vws[v].cov = covariance_2pass_create (1, &cmd->vars[v],
-                                              1, &cmd->indep_var,
-                                              wv, cmd->exclude);
+                                              cats, 
+                                              cmd->wv, cmd->exclude);
       ws.vws[v].cc = 0;
     }
 
@@ -582,7 +590,7 @@ output_oneway (const struct oneway_spec *cmd, struct oneway_workspace *ws)
     }
 
   if (cmd->stats & STATS_DESCRIPTIVES)
-    show_descriptives (cmd, cmd->dict);
+    show_descriptives (cmd);
 
   if (cmd->stats & STATS_HOMOGENEITY)
     show_homogeneity (cmd);
@@ -692,7 +700,7 @@ show_anova_table (const struct oneway_spec *cmd, const struct oneway_workspace *
 
 /* Show the descriptives table */
 static void
-show_descriptives (const struct oneway_spec *cmd, const struct dictionary *dict)
+show_descriptives (const struct oneway_spec *cmd)
 {
   size_t v;
   int n_cols = 10;
@@ -702,8 +710,7 @@ show_descriptives (const struct oneway_spec *cmd, const struct dictionary *dict)
   const double confidence = 0.95;
   const double q = (1.0 - confidence) / 2.0;
 
-  const struct variable *wv = dict_get_weight (dict);
-  const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
+  const struct fmt_spec *wfmt = cmd->wv ? var_get_print_format (cmd->wv) : & F_8_0;
 
   int n_rows = 2;
 
@@ -916,10 +923,10 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws
   int n_cols = 2 + ws->actual_number_of_groups;
   int n_rows = 2 + n_contrasts;
 
-  void *const *group_values;
-
   struct tab_table *t;
 
+  const struct covariance *cov = ws->vws[0].cov ;
+
   t = tab_create (n_cols, n_rows);
   tab_headers (t, 2, 0, 2, 0);
 
@@ -955,31 +962,27 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws
   tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
                  var_to_string (cmd->indep_var));
 
-  group_values = hsh_sort (ws->group_hash);
-
   for ( cli = ll_head (&cmd->contrast_list);
        cli != ll_null (&cmd->contrast_list);
        cli = ll_next (cli))
     {
       int count = 0;
       struct contrasts_node *cn = ll_data (cli, struct contrasts_node, ll);
-      struct ll *coeffi = ll_head (&cn->coefficient_list);
+      struct ll *coeffi ;
 
       tab_text_format (t, 1, c_num + 2, TAB_CENTER, "%d", c_num + 1);
 
-      for (count = 0;
-          count < hsh_count (ws->group_hash) && coeffi != ll_null (&cn->coefficient_list);
-          ++count)
+      for (coeffi = ll_head (&cn->coefficient_list);
+          coeffi != ll_null (&cn->coefficient_list);
+          ++count, coeffi = ll_next (coeffi))
        {
-         double *group_value_p;
-         union value group_value;
+         const struct categoricals *cats = covariance_get_categoricals (cov);
+         const union value *val = categoricals_get_value_by_subscript (cats, count);
          struct string vstr;
 
          ds_init_empty (&vstr);
 
-         group_value_p = group_values[count];
-         group_value.f = *group_value_p;
-         var_append_value_name (cmd->indep_var, &group_value, &vstr);
+         var_append_value_name (cmd->indep_var, val, &vstr);
 
          tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE, ds_cstr (&vstr));
 
@@ -993,8 +996,6 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws
 
              tab_text_format (t, count + 2, c_num + 2, TAB_RIGHT, "%g", coeffn->coeff);
            }
-
-         coeffi = ll_next (coeffi);
        }
       ++c_num;
     }