Fixed misleading results in the Kruskal-Wallis test
authorJohn Darrington <jdarrington@dornier.com>
Sat, 1 Jan 2022 08:56:21 +0000 (09:56 +0100)
committerJohn Darrington <jdarrington@dornier.com>
Sat, 1 Jan 2022 09:00:01 +0000 (10:00 +0100)
Fixed misleading results if the lower bound was in fact higher
than the upper bound.

NEWS
doc/statistics.texi
src/language/stats/kruskal-wallis.c
src/language/stats/kruskal-wallis.h
tests/language/stats/npar.at

diff --git a/NEWS b/NEWS
index 791b9c1ac3321b34dd0614cc9be2206af8a91d78..fba936463adefccf78400160f962943af1540ebe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,16 @@
 PSPP NEWS -- history of user-visible changes.
-Copyright (C) 1996-2000, 2008-2016, 2017, 2019, 2020, 2021 Free Software Foundation, Inc.
+Copyright (C) 1996-2000, 2008-2016, 2017, 2019, 2020, 2021,
+          2022  Free Software Foundation, Inc.
 See the end for copying conditions.
 
 Please send PSPP bug reports to bug-gnu-pspp@gnu.org.
 
 Changes from 1.4.1 to 1.5.3:
 
+ * In the Kruskal-Wallis test, a misleading result could occur
+   if the lower bound specified by the user was in fact higher
+   than the upper bound specified.  This has been fixed.
+
  * The DEFINE, MATRIX, MCONVERT, and MATRIX DATA commands are now
    implemented.
 
index 2f74f883fd1e7dda67622f7a9634abcf78d8677f..01976e27c950fa4ef21087dc40e0fadbd668a3ee 100644 (file)
@@ -1634,9 +1634,10 @@ arbitrary number of populations.  It does not assume normality.
 The data to be compared are specified by @var{var_list}.
 The categorical variable determining the groups to which the
 data belongs is given by @var{var}. The limits @var{lower} and
-@var{upper} specify the valid range of @var{var}. Any cases for
-which @var{var} falls outside [@var{lower}, @var{upper}] are
-ignored.
+@var{upper} specify the valid range of @var{var}.
+If @var{upper} is smaller than @var{lower}, the PSPP will assume their values
+to be reversed. Any cases for which @var{var} falls outside
+[@var{lower}, @var{upper}] are ignored.
 
 The mean rank of each group as well as the chi-squared value and
 significance of the test are printed.
index 62c49e48482cd05b5b0d09d7e0f5f231b4a6a4c8..6d54bae78208d74b98db28007cf831d3cbc37c94 100644 (file)
@@ -1,5 +1,5 @@
 /* Pspp - a program for statistical analysis.
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2011, 2022 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
 #define N_(msgid) msgid
 #define _(msgid) gettext (msgid)
 
-/* Returns true iff the independent variable lies in the range [nst->val1, nst->val2] */
+/* Returns true iff the independent variable lies between nst->val1 and  nst->val2 */
 static bool
 include_func (const struct ccase *c, void *aux)
 {
   const struct n_sample_test *nst = aux;
 
-  if (0 < value_compare_3way (&nst->val1, case_data (c, nst->indep_var), var_get_width (nst->indep_var)))
+  const union value *smaller = 0;
+  const union value *larger = 0;
+  int x = value_compare_3way (&nst->val1, &nst->val2, var_get_width (nst->indep_var));
+   if (x < 0)
+    {
+      smaller = &nst->val1;
+      larger = &nst->val2;
+    }
+  else
+    {
+      smaller = &nst->val2;
+      larger = &nst->val1;
+    }
+
+  if (0 < value_compare_3way (smaller, case_data (c, nst->indep_var),
+                              var_get_width (nst->indep_var)))
     return false;
 
-  if (0 > value_compare_3way (&nst->val2, case_data (c, nst->indep_var), var_get_width (nst->indep_var)))
+  if (0 > value_compare_3way (larger, case_data (c, nst->indep_var),
+                              var_get_width (nst->indep_var)))
     return false;
 
   return true;
index 1e16007f376f1a30a74eb31342c41003c66a6478..7adc3129961e3b965ad0acaa15a10dc76638fd4c 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2011, 2022 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
@@ -24,7 +24,7 @@
 
 struct kruskal_wallis_test
 {
-  struct two_sample_test parent;
+  struct n_sample_test parent;
 };
 
 struct casereader;
index be770ab1b17c74305b41c6c0928186b794c30e99..93624925aee4764addf974ab76023156721b00e3 100644 (file)
@@ -1,5 +1,5 @@
 dnl PSPP - a program for statistical analysis.
-dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl Copyright (C) 2017, 2022 Free Software Foundation, Inc.
 dnl
 dnl This program is free software: you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -759,6 +759,44 @@ AT_CHECK([pspp -o pspp2.csv kw-missing-group.sps])
 dnl The result should be the same as before
 AT_CHECK([diff pspp.csv pspp2.csv], [0])
 
+dnl Reverse the order of the group values
+AT_DATA([kw-reverse-group.sps], [dnl
+set format = F9.3.
+
+data list notable list /gv * xscore *.
+begin data
+1 96
+1 128
+1 83
+1 61
+1 101
+2 82
+2 124
+2 132
+2 135
+2 109
+3 115
+3 149
+3 166
+3 147
+end data.
+
+value label /gv
+       1 "timed out"
+       2 "hit wicket"
+       3 "handled the ball".
+
+npar tests
+       /kruskal-wallis xscore by gv (3, 1)
+       /missing=exclude
+       .
+])
+
+AT_CHECK([pspp -o pspp2.csv kw-reverse-group.sps])
+
+dnl The result should be the same as before
+AT_CHECK([diff pspp.csv pspp2.csv], [0])
+
 AT_CLEANUP