Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / language / stats / mann-whitney.c
index b837177b57a557580860a08d0069257d697f7cac..4db82f8e904be5d7bf2a18460b319bc1b37717a1 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 <config.h>
 
-#include "mann-whitney.h"
+#include "language/stats/mann-whitney.h"
 
 #include <gsl/gsl_cdf.h>
 
-#include <libpspp/cast.h>
-#include <libpspp/misc.h>
-
-#include <math/sort.h>
-#include <data/case.h>
-#include <data/dictionary.h>
-#include <data/procedure.h>
-#include <data/casereader.h>
-#include <data/format.h>
-#include <data/variable.h>
+#include "data/case.h"
+#include "data/casereader.h"
+#include "data/dictionary.h"
+#include "data/format.h"
+#include "data/procedure.h"
+#include "data/variable.h"
+#include "libpspp/cast.h"
+#include "libpspp/misc.h"
+#include "math/sort.h"
+#include "output/tab.h"
 
 /* Calculates the adjustment necessary for tie compensation */
 static void
@@ -45,7 +45,6 @@ struct mw
   double rank_sum[2];
   double n[2];
 
-
   double u;  /* The Mann-Whitney U statistic */
   double w;  /* The Wilcoxon Rank Sum W statistic */
   double z;  
@@ -61,7 +60,7 @@ mann_whitney_execute (const struct dataset *ds,
                      enum mv_class exclude,
                      const struct npar_test *test,
                      bool exact,
-                     double timer)
+                     double timer UNUSED)
 {
   int i;
   const struct dictionary *dict = dataset_dict (ds);
@@ -121,11 +120,11 @@ mann_whitney_execute (const struct dataset *ds,
        mwv->u += mwv->n[0] * (mwv->n[0] + 1) / 2.0;
        mwv->u -= mwv->rank_sum[0];
 
-       mwv->w = mwv->rank_sum[0];
+       mwv->w = mwv->rank_sum[1];
        if ( mwv->u > mwv->n[0] * mwv->n[1] / 2.0)
          {
            mwv->u =  mwv->n[0] * mwv->n[1] - mwv->u;
-           mwv->w = mwv->rank_sum[1];
+           mwv->w = mwv->rank_sum[0];
          }
        mwv->z = mwv->u - mwv->n[0] * mwv->n[1] / 2.0;
        n = mwv->n[0] + mwv->n[1];
@@ -148,7 +147,6 @@ mann_whitney_execute (const struct dataset *ds,
 
 \f
 
-#include <output/tab.h>
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
@@ -161,6 +159,13 @@ show_ranks_box (const struct n_sample_test *nst, const struct mw *mwv)
   struct tab_table *table =
     tab_create (row_headers + 7, column_headers + nst->n_vars);
 
+  struct string g1str, g2str;;
+  ds_init_empty (&g1str);
+  var_append_value_name (nst->indep_var, &nst->val1, &g1str);
+
+  ds_init_empty (&g2str);
+  var_append_value_name (nst->indep_var, &nst->val2, &g2str);
+
   tab_headers (table, row_headers, 0, column_headers, 0);
 
   tab_title (table, _("Ranks"));
@@ -178,24 +183,27 @@ show_ranks_box (const struct n_sample_test *nst, const struct mw *mwv)
 
   tab_hline (table, TAL_1, row_headers, tab_nc (table) -1, 1);
 
-  tab_text (table, 1, 1, TAT_TITLE | TAB_CENTER, _("group1"));
-  tab_text (table, 2, 1, TAT_TITLE | TAB_CENTER, _("group2"));
+  tab_text (table, 1, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g1str));
+  tab_text (table, 2, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g2str));
   tab_text (table, 3, 1, TAT_TITLE | TAB_CENTER, _("Total"));
   tab_joint_text (table, 1, 0, 3, 0,
                  TAT_TITLE | TAB_CENTER, _("N"));
   tab_vline (table, TAL_2, 4, 0, tab_nr (table) - 1);
 
-  tab_text (table, 4, 1, TAT_TITLE | TAB_CENTER, _("group1"));
-  tab_text (table, 5, 1, TAT_TITLE | TAB_CENTER, _("group2"));
+  tab_text (table, 4, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g1str));
+  tab_text (table, 5, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g2str));
   tab_joint_text (table, 4, 0, 5, 0,
                  TAT_TITLE | TAB_CENTER, _("Mean Rank"));
   tab_vline (table, TAL_2, 6, 0, tab_nr (table) - 1);
 
-  tab_text (table, 6, 1, TAT_TITLE | TAB_CENTER, _("group1"));
-  tab_text (table, 7, 1, TAT_TITLE | TAB_CENTER, _("group2"));
+  tab_text (table, 6, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g1str));
+  tab_text (table, 7, 1, TAT_TITLE | TAB_CENTER, ds_cstr (&g2str));
   tab_joint_text (table, 6, 0, 7, 0,
                  TAT_TITLE | TAB_CENTER, _("Sum of Ranks"));
 
+  ds_destroy (&g1str);
+  ds_destroy (&g2str);
+
   for (i = 0 ; i < nst->n_vars ; ++i)
     {
       const struct mw *mw = &mwv[i];