HISTOGRAMS: Fix bin width problems on large numbers of bins 20120510030503/pspp 20120511030508/pspp 20120512030503/pspp 20120513030508/pspp 20120514030504/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 9 May 2012 19:21:01 +0000 (21:21 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 9 May 2012 19:21:01 +0000 (21:21 +0200)
src/language/stats/examine.c
src/language/stats/frequencies.q
src/math/histogram.c
src/math/histogram.h

index 9bc287e510fcd36677a62defb77b0dde2ba167d7..3288f5bd119f7441acefda3a5fc2c1e0be83d953 100644 (file)
@@ -1605,8 +1605,6 @@ calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data)
             / (1 + log2 (es[v].cc))
             ;
 
-          bin_width = chart_rounded_tick (bin_width);
-
           es[v].histogram =
             histogram_create (bin_width, es[v].minimum, es[v].maximum);
         }
index b9da4677d18b8599d97a6449343e5e5e22c37031..b5ad8c47793eef15064a887023eead28732c8845 100644 (file)
@@ -1142,7 +1142,6 @@ freq_tab_to_hist (const struct frq_proc *frq, const struct freq_tab *ft,
   /* Freedman-Diaconis' choice of bin width. */
   iqr = calculate_iqr (frq);
   bin_width = 2 * iqr / pow (valid_freq, 1.0 / 3.0);
-  bin_width = chart_rounded_tick (bin_width);
 
   histogram = histogram_create (bin_width, x_min, x_max);
 
index 7fc2d08e3de341a49455e0395d7283e204384f79..afc40013e02865f46f82549599f4f9cb84812706 100644 (file)
@@ -222,12 +222,14 @@ histogram_create (double bin_width, double min, double max)
 
   assert (bin_width > 0);
 
+  bin_width = chart_rounded_tick (bin_width);
   bins = adjust_bin_ranges (bin_width, min, max, &adjusted_min, &adjusted_max);
 
   /* Force the number of bins to lie in a sensible range. */
   if (bins > MAX_BINS) 
     {
-      bins = adjust_bin_ranges ((max - min) / (double) (MAX_BINS - 1),
+      bin_width = chart_rounded_tick ((max - min) / (double) (MAX_BINS - 1));
+      bins = adjust_bin_ranges (bin_width,
                                 min, max, &adjusted_min, &adjusted_max);
     }
 
index f03e767c5eec3cdc72e0d284b805689e4885eb5d..3f8fc3e7e75abdba3fb0fbbfb72ac769939c43b2 100644 (file)
@@ -30,7 +30,13 @@ struct histogram
   gsl_histogram *gsl_hist;
 };
 
-struct histogram * histogram_create (double bin_width, double max, double min);
+/* 
+   Prepare a histogram for data which lies in the range [min, max)
+   bin_width is a nominal figure only.  It is a hint about what might be
+   an good approximate bin width, but the implementation will adjust it
+   as it thinks fit.
+ */
+struct histogram * histogram_create (double bin_width, double min, double max);
 
 void histogram_add (struct histogram *h, double y, double c);