Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / math / histogram.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <math.h>
19 #include <gsl/gsl_histogram.h>
20 #include <assert.h>
21 #include "histogram.h"
22 #include "chart-geometry.h"
23
24
25 gsl_histogram *
26 histogram_create(double bins, double x_min, double x_max)
27 {
28   int n;
29   double bin_width ;
30   double bin_width_2 ;
31   double upper_limit, lower_limit;
32
33   gsl_histogram *hist = gsl_histogram_alloc(bins);
34
35   bin_width = chart_rounded_tick((x_max - x_min)/ bins);
36   bin_width_2 = bin_width / 2.0;
37
38   n =  ceil( x_max / (bin_width_2) ) ;
39   if ( ! (n % 2 ) ) n++;
40   upper_limit = n * bin_width_2;
41
42   n =  floor( x_min / (bin_width_2) ) ;
43   if ( ! (n % 2 ) ) n--;
44   lower_limit = n * bin_width_2;
45
46   gsl_histogram_set_ranges_uniform(hist, lower_limit, upper_limit);
47
48   return hist;
49 }
50