Fix some typos (found by codespell)
[pspp] / src / language / stats / mann-whitney.c
index 81fe033af52ac9bb4cb8b995db7d6ddc03efae27..e117cc366cbfd24aefacd5631eca45a1a81c2e0c 100644 (file)
@@ -47,13 +47,33 @@ struct mw
 
   double u;  /* The Mann-Whitney U statistic */
   double w;  /* The Wilcoxon Rank Sum W statistic */
-  double z;  
+  double z;
 };
 
 static void show_ranks_box (const struct n_sample_test *nst, const struct mw *mw);
 static void show_statistics_box (const struct n_sample_test *nst, const struct mw *mw, bool exact);
 
 
+
+static bool
+belongs_to_test (const struct ccase *c, void *aux)
+{
+  const struct n_sample_test *nst = aux;
+
+  const union value *group = case_data (c, nst->indep_var);
+  const size_t group_var_width = var_get_width (nst->indep_var);
+
+  if ( value_equal (group, &nst->val1, group_var_width))
+    return true;
+
+  if ( value_equal (group, &nst->val2, group_var_width))
+    return true;
+
+  return false;
+}
+
+
+
 void
 mann_whitney_execute (const struct dataset *ds,
                      struct casereader *input,
@@ -79,9 +99,19 @@ mann_whitney_execute (const struct dataset *ds,
       struct casereader *rr;
       struct ccase *c;
       const struct variable *var = nst->vars[i];
-      
+
       struct casereader *reader =
-       sort_execute_1var (casereader_clone (input), var);
+       casereader_create_filter_func (casereader_clone (input),
+                                      belongs_to_test,
+                                      NULL,
+                                      CONST_CAST (struct n_sample_test *, nst),
+                                      NULL);
+
+      reader = casereader_create_filter_missing (reader, &var, 1,
+                                                exclude,
+                                                NULL, NULL);
+
+      reader = sort_execute_1var (reader, var);
 
       rr = casereader_create_append_rank (reader, var,
                                          dict_get_weight (dict),
@@ -90,14 +120,10 @@ mann_whitney_execute (const struct dataset *ds,
 
       for (; (c = casereader_read (rr)); case_unref (c))
        {
-         const union value *val = case_data (c, var);
          const union value *group = case_data (c, nst->indep_var);
          const size_t group_var_width = var_get_width (nst->indep_var);
          const double rank = case_data_idx (c, rank_idx)->f;
 
-         if ( var_is_value_missing (var, val, exclude))
-           continue;
-
          if ( value_equal (group, &nst->val1, group_var_width))
            {
              mw[i].rank_sum[0] += rank;
@@ -133,7 +159,7 @@ mann_whitney_execute (const struct dataset *ds,
        denominator -= tiebreaker;
        denominator *= mwv->n[0] * mwv->n[1];
        denominator /= n * (n - 1);
-      
+
        mwv->z /= sqrt (denominator);
       }
     }
@@ -266,7 +292,7 @@ show_statistics_box (const struct n_sample_test *nst, const struct mw *mwv, bool
   tab_text (table, 3, 0, TAT_TITLE | TAB_CENTER, _("Z"));
   tab_text (table, 4, 0, TAT_TITLE | TAB_CENTER, _("Asymp. Sig. (2-tailed)"));
 
-  if (exact) 
+  if (exact)
     {
       tab_text (table, 5, 0, TAT_TITLE | TAB_CENTER, _("Exact Sig. (2-tailed)"));
       tab_text (table, 6, 0, TAT_TITLE | TAB_CENTER, _("Point Probability"));