public class Histogram
extends java.lang.Object
There is no "best" number of bins, and different bin sizes can reveal different features of the data. Depending on the actual data distribution and the goals of the analysis, different bin widths may be appropriate, so experimentation is usually needed to determine an appropriate width.
Note that this class provides only tools to choose the bin width or the number of bins and frequency counting. It does NOT providing plotting services.
| Modifier and Type | Method and Description |
|---|---|
static int |
bins(double[] x,
double h)
Returns the number of bins for a data based on a suggested bin width h.
|
static int |
bins(int n)
Returns the number of bins by square-root rule, which takes the square
root of the number of data points in the sample (used by Excel histograms
and many others).
|
static double[] |
breaks(double[] x,
double h)
Returns the breakpoints between histogram cells for a dataset based on a
suggested bin width h.
|
static double[] |
breaks(double[] x,
int k)
Returns the breakpoints between histogram cells for a dataset.
|
static double[] |
breaks(double min,
double max,
double h)
Returns the breakpoints between histogram cells for a given range based
on a suggested bin width h.
|
static double[] |
breaks(double min,
double max,
int k)
Returns the breakpoints between histogram cells for a given range.
|
static double[][] |
histogram(double[] data)
Generate the histogram of given data.
|
static double[][] |
histogram(double[] data,
double[] breaks)
Generate the histogram of n bins.
|
static double[][] |
histogram(double[] data,
int k)
Generate the histogram of n bins.
|
static double[][] |
histogram(float[] data)
Generate the histogram of given data.
|
static double[][] |
histogram(float[] data,
float[] breaks)
Generate the histogram of n bins.
|
static double[][] |
histogram(float[] data,
int k)
Generate the histogram of n bins.
|
static double[][] |
histogram(int[] data)
Generate the histogram of given data.
|
static double[][] |
histogram(int[] data,
double[] breaks)
Generate the histogram of n bins.
|
static double[][] |
histogram(int[] data,
int k)
Generate the histogram of k bins.
|
static int |
scott(double[] x)
Returns the number of bins by Scott's rule h = 3.5 * σ / (n1/3).
|
static int |
sturges(int n)
Returns the number of bins by Sturges' rule k = ceil(log2(n) + 1).
|
public static double[][] histogram(int[] data)
data - the data points.public static double[][] histogram(float[] data)
data - the data points.public static double[][] histogram(double[] data)
data - the data points.public static double[][] histogram(int[] data,
int k)
data - the data points.k - the number of bins.public static double[][] histogram(int[] data,
double[] breaks)
data - the data points.breaks - an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public static double[][] histogram(float[] data,
int k)
data - the data points.k - the number of bins.public static double[][] histogram(float[] data,
float[] breaks)
data - the data points.breaks - an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public static double[][] histogram(double[] data,
int k)
data - the data points.k - the number of bins.public static double[][] histogram(double[] data,
double[] breaks)
data - the data points.breaks - an array of size k+1 giving the breakpoints between
histogram cells. Must be in ascending order.public static double[] breaks(double[] x,
double h)
x - the data set.h - the bin width.public static double[] breaks(double min,
double max,
double h)
min - the lower bound of bins.max - the upper bound of bins.h - the bin width.public static double[] breaks(double[] x,
int k)
x - the data set.k - the number of bins.public static double[] breaks(double min,
double max,
int k)
min - the lower bound of bins.max - the upper bound of bins.k - the number of bins.public static int bins(double[] x,
double h)
x - the data set.h - the bin width.public static int bins(int n)
n - the number of data points.public static int sturges(int n)
n - the number of data points.public static int scott(double[] x)
x - the data set.