FREQUENCIES: Use the smallest mode if there are multiple.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 14 Aug 2022 23:42:56 +0000 (16:42 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 28 Aug 2022 17:39:54 +0000 (10:39 -0700)
This matches the documentation.

src/language/stats/frequencies.c

index 3f7afaa361801e468879dd5e246ce4a6d6bb9c80..96d903c5b7238cf1bbd514f8c0527a24803ef7c7 100644 (file)
@@ -1488,21 +1488,14 @@ calc_stats (const struct frq_proc *frq, const struct var_freqs *vf,
   int most_often = -1;
   double X_mode = SYSMIS;
 
-  /* Calculate the mode. */
+  /* Calculate the mode.  If there is more than one mode, we take the
+     smallest. */
   for (f = ft->valid; f < ft->missing; f++)
-    {
-      if (most_often < f->count)
-        {
-          most_often = f->count;
-          X_mode = f->values[0].f;
-        }
-      else if (most_often == f->count)
-        {
-          /* A duplicate mode is undefined.
-             FIXME: keep track of *all* the modes. */
-          X_mode = SYSMIS;
-        }
-    }
+    if (most_often < f->count)
+      {
+        most_often = f->count;
+        X_mode = f->values[0].f;
+      }
 
   /* Calculate moments. */
   m = moments_create (MOMENT_KURTOSIS);