oneway.c: Use the categoricals struct to calculate number of groups
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 15 Aug 2010 15:50:14 +0000 (17:50 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 24 Aug 2010 14:37:15 +0000 (16:37 +0200)
src/language/stats/oneway.c

index f481c69dc13c765cfd55cbc346ca2089a15df7f2..e88a9542ecd33855f4370c6b10cd76a8ef86ffc0 100644 (file)
@@ -400,17 +400,13 @@ run_oneway (const struct oneway_spec *cmd,
   struct ccase *c;
 
   struct oneway_workspace ws;
-  
-  {
-    ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws));
 
-    ws.dd_total = xmalloc (sizeof (struct descriptive_data) * cmd->n_vars);
+  ws.actual_number_of_groups = 0;
+  ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws));
+  ws.dd_total = xmalloc (sizeof (struct descriptive_data) * cmd->n_vars);
 
-    for (v = 0 ; v < cmd->n_vars; ++v)
-      {
-       ws.dd_total[v] = dd_create (cmd->vars[v]);
-      }
-  }
+  for (v = 0 ; v < cmd->n_vars; ++v)
+    ws.dd_total[v] = dd_create (cmd->vars[v]);
 
   for (v = 0; v < cmd->n_vars; ++v)
     {
@@ -565,11 +561,15 @@ run_oneway (const struct oneway_spec *cmd,
 
   postcalc (cmd);
 
+  
   for (v = 0; v < cmd->n_vars; ++v)
     {
       struct categoricals *cats = covariance_get_categoricals (ws.vws[v].cov);
 
       categoricals_done (cats);
+      
+      if (categoricals_total (cats) > ws.actual_number_of_groups)
+       ws.actual_number_of_groups = categoricals_total (cats);
     }
 
   if ( cmd->stats & STATS_HOMOGENEITY )
@@ -578,8 +578,6 @@ run_oneway (const struct oneway_spec *cmd,
 
   casereader_destroy (input);
 
-  ws.actual_number_of_groups = hsh_count (ws.group_hash);
-
   if (!taint_has_tainted_successor (taint))
     output_oneway (cmd, &ws);