Rename procedure.[ch] to dataset.[ch].
[pspp-builds.git] / src / language / stats / kruskal-wallis.c
index 63ede78a34377c0a9d5bdcf460922a736af5379a..ecab0348d1ae16986f85e905ed19e0bd43fe4d50 100644 (file)
@@ -1,5 +1,5 @@
 /* Pspp - a program for statistical analysis.
-   Copyright (C) 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <gsl/gsl_cdf.h>
 #include <math.h>
 
-#include <data/casereader.h>
-#include <data/casewriter.h>
-#include <data/dictionary.h>
-#include <data/format.h>
-#include <data/procedure.h>
-#include <data/subcase.h>
-#include <data/variable.h>
-
-#include <libpspp/assertion.h>
-#include <libpspp/message.h>
-#include <libpspp/misc.h>
-#include <libpspp/hmap.h>
-#include <math/sort.h>
-
-
-#include "minmax.h"
-#include "xalloc.h"
-
-
+#include "data/casereader.h"
+#include "data/casewriter.h"
+#include "data/dataset.h"
+#include "data/dictionary.h"
+#include "data/format.h"
+#include "data/subcase.h"
+#include "data/variable.h"
+#include "libpspp/assertion.h"
+#include "libpspp/hmap.h"
+#include "libpspp/message.h"
+#include "libpspp/misc.h"
+#include "math/sort.h"
+#include "output/tab.h"
+
+#include "gl/minmax.h"
+#include "gl/xalloc.h"
+
+
+/* Returns true iff the independent variable lies in the range [nst->val1, nst->val2] */
 static bool
 include_func (const struct ccase *c, void *aux)
 {
@@ -65,6 +65,7 @@ struct rank_entry
   double n;
 };
 
+/* Return the entry with the key GROUP or null if there is no such entry */
 static struct rank_entry *
 find_rank_entry (const struct hmap *map, const union value *group, size_t width)
 {
@@ -80,6 +81,7 @@ find_rank_entry (const struct hmap *map, const union value *group, size_t width)
   return re;
 }
 
+/* Calculates the adjustment necessary for tie compensation */
 static void
 distinct_callback (double v UNUSED, casenumber t, double w UNUSED, void *aux)
 {
@@ -127,7 +129,8 @@ kruskal_wallis_execute (const struct dataset *ds,
   input = casereader_create_filter_weight (input, dict, &warn, NULL);
 
   /* Remove all those cases which are outside the range (val1, val2) */
-  input = casereader_create_filter_func (input, include_func, NULL, nst, NULL);
+  input = casereader_create_filter_func (input, include_func, NULL, 
+       CONST_CAST (struct n_sample_test *, nst), NULL);
 
   proto = casereader_get_proto (input);
   rank_idx = caseproto_get_n_widths (proto);
@@ -180,6 +183,7 @@ kruskal_wallis_execute (const struct dataset *ds,
 
       casereader_destroy (rr);
 
+      /* Calculate the value of h */
       {
        struct rank_entry *mre;
        double n = 0.0;
@@ -203,6 +207,7 @@ kruskal_wallis_execute (const struct dataset *ds,
   show_ranks_box (nst, kw, total_n_groups);
   show_sig_box (nst, kw);
 
+  /* Cleanup allocated memory */
   for (i = 0 ; i < nst->n_vars; ++i)
     {
       struct rank_entry *mre, *next;
@@ -218,7 +223,6 @@ kruskal_wallis_execute (const struct dataset *ds,
 }
 
 \f
-#include <output/tab.h>
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
@@ -226,6 +230,7 @@ kruskal_wallis_execute (const struct dataset *ds,
 static void
 show_ranks_box (const struct n_sample_test *nst, const struct kw *kw, int n_groups)
 {
+  int row;
   int i;
   const int row_headers = 2;
   const int column_headers = 1;
@@ -255,16 +260,16 @@ show_ranks_box (const struct n_sample_test *nst, const struct kw *kw, int n_grou
   tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1);
 
 
-  int x = column_headers;
+  row = column_headers;
   for (i = 0 ; i < nst->n_vars ; ++i)
     {
       int tot = 0;
       const struct rank_entry *re;
 
       if (i > 0)
-       tab_hline (table, TAL_1, 0, tab_nc (table) -1, x);
+       tab_hline (table, TAL_1, 0, tab_nc (table) -1, row);
       
-      tab_text (table,  0, x,
+      tab_text (table,  0, row,
                TAT_TITLE, var_to_string (nst->vars[i]));
 
       HMAP_FOR_EACH (re, const struct rank_entry, node, &kw[i].map)
@@ -274,17 +279,17 @@ show_ranks_box (const struct n_sample_test *nst, const struct kw *kw, int n_grou
 
          var_append_value_name (nst->indep_var, &re->group, &str);
 
-         tab_text   (table, 1, x, TAB_LEFT, ds_cstr (&str));
-         tab_double (table, 2, x, TAB_LEFT, re->n, &F_8_0);
-         tab_double (table, 3, x, TAB_LEFT, re->sum_of_ranks / re->n, 0);
+         tab_text   (table, 1, row, TAB_LEFT, ds_cstr (&str));
+         tab_double (table, 2, row, TAB_LEFT, re->n, &F_8_0);
+         tab_double (table, 3, row, TAB_LEFT, re->sum_of_ranks / re->n, 0);
 
          tot += re->n;
-         x++;
+         row++;
          ds_destroy (&str);
        }
-      tab_double (table, 2, x, TAB_LEFT,
+      tab_double (table, 2, row, TAB_LEFT,
                  tot, &F_8_0);
-      tab_text (table, 1, x++, TAB_LEFT, _("Total"));
+      tab_text (table, 1, row++, TAB_LEFT, _("Total"));
     }
 
   tab_submit (table);