(cross-validation-2d xs ys type)(cross-validation-2d xs ys type opts)Estimates a 2d histogram cell area for xs/ys by leave-one-out cross-validation (Rudemo 1982), for cells of the grid type (fastmath.grid).
For cells of area A, the estimated integrated squared error of the histogram is, up to a constant, (2 - (n+1) * sum(p_k^2)) / A, where p_k is the fraction of the points in the cell k. The cell size with the lowest cost is chosen, counting the points on the same grid as fastmath.stats/histogram2d (cell type type, offset :sv). Unlike the normal-reference rules (scott-2d, scott-correlated, freedman-diaconis-2d) it adapts to the shape of the data (smaller cells for multimodal or curved data), at the price of more variability and a pass over the data for every candidate.
Candidates are :candidates cell sizes, evenly spaced on the log scale between a twentieth and four times the size of the freedman-diaconis-2d area (the scott-2d area when that one is not usable). For discretized data (rounded values) the cost decreases without limit once the cells are smaller than the gaps between values, so the cell area is at least 4 * gap_x * gap_y (the smallest positive gaps along the axes). Ties go to the larger cell.
Parameters:
xs, ys (double arrays): the two coordinate axes of the data, same length.type (keyword): the cell type, one of fastmath.grid/cell-names.opts (map, optional):
:sv - the grid offset (translating vector), default: [0.0 0.0]:candidates - the number of candidate cell sizes, default: 200:shifts - the number of grid offsets the cost is averaged over (shifted along the diagonal by a fraction of the size, a smoother cost), default: 1 (no averaging)Points on a line parallel to an axis (one constant axis) leave no cells to compare: the area is then the square of the 1d scott bin width along the line, as in scott-correlated. Other lines, and data with a far outlier, are searched as any other data.
Throws ex-info when :candidates or :shifts is not an integer at least 1.
Returns the estimated cell area as a double, ##NaN for less than 2 points or two constant axes.
See also shimazaki-shinomoto-2d, cross-validation-bins.
Estimates a 2d histogram cell area for `xs`/`ys` by leave-one-out cross-validation (Rudemo 1982), for cells of the grid `type` (`fastmath.grid`). For cells of area `A`, the estimated integrated squared error of the histogram is, up to a constant, `(2 - (n+1) * sum(p_k^2)) / A`, where `p_k` is the fraction of the points in the cell `k`. The cell size with the lowest cost is chosen, counting the points on the same grid as `fastmath.stats/histogram2d` (cell type `type`, offset `:sv`). Unlike the normal-reference rules ([[scott-2d]], [[scott-correlated]], [[freedman-diaconis-2d]]) it adapts to the shape of the data (smaller cells for multimodal or curved data), at the price of more variability and a pass over the data for every candidate. Candidates are `:candidates` cell sizes, evenly spaced on the log scale between a twentieth and four times the size of the [[freedman-diaconis-2d]] area (the [[scott-2d]] area when that one is not usable). For discretized data (rounded values) the cost decreases without limit once the cells are smaller than the gaps between values, so the cell area is at least `4 * gap_x * gap_y` (the smallest positive gaps along the axes). Ties go to the larger cell. Parameters: - `xs`, `ys` (`double` arrays): the two coordinate axes of the data, same length. - `type` (keyword): the cell type, one of `fastmath.grid/cell-names`. - `opts` (map, optional): - `:sv` - the grid offset (translating vector), default: `[0.0 0.0]` - `:candidates` - the number of candidate cell sizes, default: `200` - `:shifts` - the number of grid offsets the cost is averaged over (shifted along the diagonal by a fraction of the size, a smoother cost), default: `1` (no averaging) Points on a line parallel to an axis (one constant axis) leave no cells to compare: the area is then the square of the 1d [[scott]] bin width along the line, as in [[scott-correlated]]. Other lines, and data with a far outlier, are searched as any other data. Throws `ex-info` when `:candidates` or `:shifts` is not an integer at least 1. Returns the estimated cell area as a `double`, `##NaN` for less than 2 points or two constant axes. See also [[shimazaki-shinomoto-2d]], [[cross-validation-bins]].
(cross-validation-bins avs)(cross-validation-bins avs opts)Estimates the number of histogram bins for avs by leave-one-out cross-validation (Rudemo 1982; stone in numpy).
For N equal bins over the range of the data (width h), the estimated integrated squared error of the histogram is, up to a constant, (2 - (n+1) * sum(p_k^2)) / h, where p_k is the fraction of the data in the bin k. The bin count with the lowest cost is returned. Unlike the normal-reference rules (scott, freedman-diaconis) it adapts to the shape of the data (more bins for multimodal data), at the price of more variability and a pass over the data for every candidate.
Candidates are about :candidates bin counts, evenly spaced on the log scale between a quarter and twenty times the freedman-diaconis count, and not more than n. For discretized data (rounded values) the cost decreases without limit once the bins are narrower than the gap between values, so the bin count is limited to the range divided by twice the smallest gap (as in the reference implementation of Shimazaki and Shinomoto). Ties go to the lower bin count.
Parameters:
avs (double array): the data.opts (map, optional):
:candidates - the number of candidate bin counts, default: 200:shifts - the number of bin origins the cost is averaged over (shifted by a fraction of the bin width, a smoother cost), default: 1 (no averaging)Returns the estimated number of bins as a positive long, 1 for less than 2 values or zero range. Throws ex-info when :candidates or :shifts is not an integer at least 1.
See also shimazaki-shinomoto-bins, cross-validation-2d, freedman-diaconis.
Estimates the number of histogram bins for `avs` by leave-one-out cross-validation (Rudemo 1982; `stone` in numpy). For `N` equal bins over the range of the data (width `h`), the estimated integrated squared error of the histogram is, up to a constant, `(2 - (n+1) * sum(p_k^2)) / h`, where `p_k` is the fraction of the data in the bin `k`. The bin count with the lowest cost is returned. Unlike the normal-reference rules ([[scott]], [[freedman-diaconis]]) it adapts to the shape of the data (more bins for multimodal data), at the price of more variability and a pass over the data for every candidate. Candidates are about `:candidates` bin counts, evenly spaced on the log scale between a quarter and twenty times the [[freedman-diaconis]] count, and not more than `n`. For discretized data (rounded values) the cost decreases without limit once the bins are narrower than the gap between values, so the bin count is limited to the range divided by twice the smallest gap (as in the reference implementation of Shimazaki and Shinomoto). Ties go to the lower bin count. Parameters: - `avs` (`double` array): the data. - `opts` (map, optional): - `:candidates` - the number of candidate bin counts, default: `200` - `:shifts` - the number of bin origins the cost is averaged over (shifted by a fraction of the bin width, a smoother cost), default: `1` (no averaging) Returns the estimated number of bins as a positive `long`, `1` for less than 2 values or zero range. Throws `ex-info` when `:candidates` or `:shifts` is not an integer at least 1. See also [[shimazaki-shinomoto-bins]], [[cross-validation-2d]], [[freedman-diaconis]].
(doane avs n)Estimates the number of histogram bins for avs using Doane's rule.
A refinement of sturges that accounts for the sample skewness, giving
better results than Sturges' rule for non-normal (skewed) data. avs must
be the same data n was counted from.
Formula: 1 + log2(n) + log2(1 + |g1|/sigma_g1), where g1 is the sample
skewness and sigma_g1 = sqrt(6*(n-2)/((n+1)*(n+3))) is its estimated
standard error.
Parameters:
avs (double array): The data.n (long): The sample size, (count avs).Returns the estimated number of bins as a positive long (at least 1;
always 1 when n < 3, since skewness is undefined below 3 points).
See also sturges, rice, scott, freedman-diaconis.
Estimates the number of histogram bins for `avs` using Doane's rule. A refinement of [[sturges]] that accounts for the sample skewness, giving better results than Sturges' rule for non-normal (skewed) data. `avs` must be the same data `n` was counted from. Formula: `1 + log2(n) + log2(1 + |g1|/sigma_g1)`, where `g1` is the sample skewness and `sigma_g1 = sqrt(6*(n-2)/((n+1)*(n+3)))` is its estimated standard error. Parameters: - `avs` (`double` array): The data. - `n` (`long`): The sample size, `(count avs)`. Returns the estimated number of bins as a positive `long` (at least `1`; always `1` when `n < 3`, since skewness is undefined below 3 points). See also [[sturges]], [[rice]], [[scott]], [[freedman-diaconis]].
(freedman-diaconis avs n)Estimates the number of histogram bins for avs using the Freedman-Diaconis rule.
Bin width: 2 * IQR / cbrt(n), then bin count is the data range divided by
that width, rounded up. Robust to outliers (uses the interquartile range
rather than standard deviation).
If the estimated bin width is (near) zero (e.g. avs has near-zero IQR),
falls back to a more robust width estimate -- see [[scott-fd-helper]] for
the exact fallback chain and its terminal case (returns 1 when even that
is degenerate).
Parameters:
avs (double array): The data.n (long): The sample size, (count avs). Must match (count avs);
avs must be non-empty when n >= 1.Returns the estimated number of bins as a positive long (at least 1,
including when n < 1, since there is then no data to derive a range from).
Estimates the number of histogram bins for `avs` using the Freedman-Diaconis rule. Bin width: `2 * IQR / cbrt(n)`, then bin count is the data range divided by that width, rounded up. Robust to outliers (uses the interquartile range rather than standard deviation). If the estimated bin width is (near) zero (e.g. `avs` has near-zero IQR), falls back to a more robust width estimate -- see [[scott-fd-helper]] for the exact fallback chain and its terminal case (returns `1` when even that is degenerate). Parameters: - `avs` (`double` array): The data. - `n` (`long`): The sample size, `(count avs)`. Must match `(count avs)`; `avs` must be non-empty when `n >= 1`. Returns the estimated number of bins as a positive `long` (at least `1`, including when `n < 1`, since there is then no data to derive a range from). See also [[sturges]], [[rice]], [[doane]], [[scott]].
(freedman-diaconis-2d xs ys)Estimates a 2d histogram bin area for xs/ys using the 2d Freedman-Diaconis rule: scott-2d with each standard deviation replaced by the robust estimate IQR / 1.349.
Robust to outliers and heavy tails, which inflate the standard deviation. For multimodal data the interquartile range overstates the spread of each mode, so the bins are coarser than with scott-2d.
When exactly one axis has zero IQR (points on a line parallel to an axis, or an axis dominated by one value), the area is the square of the 1d freedman-diaconis bin width of the other axis, (2 * IQR * n^(-1/3))^2.
Parameters:
xs, ys (double arrays): the two coordinate axes of the data, same length.Returns the estimated bin area as a double. Less than 2 points or zero IQR on both axes give 0.0 or ##NaN, left to the caller.
See also scott-2d, scott-correlated, freedman-diaconis.
Estimates a 2d histogram bin area for `xs`/`ys` using the 2d Freedman-Diaconis rule: [[scott-2d]] with each standard deviation replaced by the robust estimate `IQR / 1.349`. Robust to outliers and heavy tails, which inflate the standard deviation. For multimodal data the interquartile range overstates the spread of each mode, so the bins are coarser than with [[scott-2d]]. When exactly one axis has zero IQR (points on a line parallel to an axis, or an axis dominated by one value), the area is the square of the 1d [[freedman-diaconis]] bin width of the other axis, `(2 * IQR * n^(-1/3))^2`. Parameters: - `xs`, `ys` (`double` arrays): the two coordinate axes of the data, same length. Returns the estimated bin area as a `double`. Less than 2 points or zero IQR on both axes give `0.0` or `##NaN`, left to the caller. See also [[scott-2d]], [[scott-correlated]], [[freedman-diaconis]].
(rice n)Estimates the number of histogram bins for a sample of size n using the Rice rule.
Formula: ceil(2 * cbrt(n)). Depends only on sample size (no distributional
assumption), generally recommending more bins than sturges.
Parameters:
n (long): The sample size.Returns the estimated number of bins as a positive long (at least 1).
See also sturges, doane, scott, freedman-diaconis, sqrt,
terrell-scott.
Estimates the number of histogram bins for a sample of size `n` using the Rice rule. Formula: `ceil(2 * cbrt(n))`. Depends only on sample size (no distributional assumption), generally recommending more bins than [[sturges]]. Parameters: - `n` (`long`): The sample size. Returns the estimated number of bins as a positive `long` (at least `1`). See also [[sturges]], [[doane]], [[scott]], [[freedman-diaconis]], [[sqrt]], [[terrell-scott]].
(scott avs n)Estimates the number of histogram bins for avs using Scott's rule.
Bin width: 3.5 * stddev / cbrt(n), then bin count is the data range
divided by that width, rounded up. Assumes roughly normal data.
If the estimated bin width is (near) zero (e.g. avs has near-zero
variance), falls back to a more robust width estimate -- see
[[scott-fd-helper]] for the exact fallback chain and its terminal case
(returns 1 when even that is degenerate).
Parameters:
avs (double array): The data.n (long): The sample size, (count avs). Must match (count avs);
avs must be non-empty when n >= 1.Returns the estimated number of bins as a positive long (at least 1,
including when n < 1, since there is then no data to derive a range from).
See also sturges, rice, doane, freedman-diaconis.
Estimates the number of histogram bins for `avs` using Scott's rule. Bin width: `3.5 * stddev / cbrt(n)`, then bin count is the data range divided by that width, rounded up. Assumes roughly normal data. If the estimated bin width is (near) zero (e.g. `avs` has near-zero variance), falls back to a more robust width estimate -- see [[scott-fd-helper]] for the exact fallback chain and its terminal case (returns `1` when even that is degenerate). Parameters: - `avs` (`double` array): The data. - `n` (`long`): The sample size, `(count avs)`. Must match `(count avs)`; `avs` must be non-empty when `n >= 1`. Returns the estimated number of bins as a positive `long` (at least `1`, including when `n < 1`, since there is then no data to derive a range from). See also [[sturges]], [[rice]], [[doane]], [[freedman-diaconis]].
(scott-2d xs ys)Estimates a 2d histogram bin area for xs/ys using the multivariate normal-reference rule (Scott, D.W. Multivariate Density Estimation: Theory, Practice, and Visualization, 1992, p.82), the 2-dimensional generalization of scott.
Computed per axis: b_x = c * stddev(xs) * n^(-1/4), b_y = c * stddev(ys) * n^(-1/4), with c = (48*pi)^(1/4) (about 3.504, the exact constant for 2 dimensions, the 1d scott uses the rounded 3.5), then combined into the bin area b_x * b_y. This is the area of the best rectangular bin for bivariate normal data without correlation. Callers (e.g. fastmath.stats/estimate-grid-size) convert the returned area into a cell size for their grid (e.g. via fastmath.grid/area->size).
Points on a line parallel to an axis (exactly one axis with zero variance) have no 2d density: the area is then the square of the 1d scott bin width of the other axis, (3.5 * stddev * n^(-1/3))^2.
This is the histogram form of Scott's rule; it is unrelated to the Scott's/Silverman's rule (exponent -1/(d+4)) used for kernel density estimation bandwidth.
Parameters:
xs, ys (double arrays): the two coordinate axes of the data, same length.Returns the estimated bin area as a double. Less than 2 points or two constant axes give 0.0 or ##NaN rather than an exception; interpreting it (e.g. falling back to a usable default) is left to the caller.
See also scott, scott-correlated, freedman-diaconis-2d.
Estimates a 2d histogram bin area for `xs`/`ys` using the multivariate normal-reference rule (Scott, D.W. *Multivariate Density Estimation: Theory, Practice, and Visualization*, 1992, p.82), the 2-dimensional generalization of [[scott]]. Computed per axis: `b_x = c * stddev(xs) * n^(-1/4)`, `b_y = c * stddev(ys) * n^(-1/4)`, with `c = (48*pi)^(1/4)` (about `3.504`, the exact constant for 2 dimensions, the 1d [[scott]] uses the rounded `3.5`), then combined into the bin area `b_x * b_y`. This is the area of the best rectangular bin for bivariate normal data without correlation. Callers (e.g. `fastmath.stats/estimate-grid-size`) convert the returned area into a cell size for their grid (e.g. via `fastmath.grid/area->size`). Points on a line parallel to an axis (exactly one axis with zero variance) have no 2d density: the area is then the square of the 1d [[scott]] bin width of the other axis, `(3.5 * stddev * n^(-1/3))^2`. This is the histogram form of Scott's rule; it is unrelated to the Scott's/Silverman's rule (exponent `-1/(d+4)`) used for kernel density estimation bandwidth. Parameters: - `xs`, `ys` (`double` arrays): the two coordinate axes of the data, same length. Returns the estimated bin area as a `double`. Less than 2 points or two constant axes give `0.0` or `##NaN` rather than an exception; interpreting it (e.g. falling back to a usable default) is left to the caller. See also [[scott]], [[scott-correlated]], [[freedman-diaconis-2d]].
(scott-correlated xs ys)Estimates a 2d histogram bin area for xs/ys using the normal-reference rule for cells of one shape and size, taking the correlation of the axes into account.
For bivariate normal data with standard deviations sx, sy and correlation rho, the cell area minimizing the asymptotic mean integrated squared error is sqrt(12 / (n * (R_x + R_y))), where R_x = 1 / (8*pi * sx^3 * sy * (1-rho^2)^(3/2)) (and R_y alike) are the integrated squared partial derivatives of the density, so the area is sqrt(96*pi * sx * sy * (1-rho^2)^(3/2) / (n * (1/sx^2 + 1/sy^2))). Correlated data gets smaller cells than with scott-2d; for uncorrelated data with equal spreads both rules give the same area. Strongly correlated data gets very small cells: the area goes to zero as rho goes to ±1.
Grid cells (fastmath.grid) have one size and shape, so this rule (the best area for such cells) fits them better than scott-2d (the area of the best rectangle) when the spreads of the axes differ.
Points on a line (exactly one constant axis, or axes correlated up to rounding, 1 - rho^2 below about 1e-12) have no 2d density: the area is then the square of the 1d scott bin width along the line, (3.5 * s * n^(-1/3))^2, where s^2 = sx^2 + sy^2 is the variance along the line.
Parameters:
xs, ys (double arrays): the two coordinate axes of the data, same length.Returns the estimated bin area as a double, ##NaN for less than 2 points or two constant axes (left to the caller).
See also scott-2d, freedman-diaconis-2d.
Estimates a 2d histogram bin area for `xs`/`ys` using the normal-reference rule for cells of one shape and size, taking the correlation of the axes into account. For bivariate normal data with standard deviations `sx`, `sy` and correlation `rho`, the cell area minimizing the asymptotic mean integrated squared error is `sqrt(12 / (n * (R_x + R_y)))`, where `R_x = 1 / (8*pi * sx^3 * sy * (1-rho^2)^(3/2))` (and `R_y` alike) are the integrated squared partial derivatives of the density, so the area is `sqrt(96*pi * sx * sy * (1-rho^2)^(3/2) / (n * (1/sx^2 + 1/sy^2)))`. Correlated data gets smaller cells than with [[scott-2d]]; for uncorrelated data with equal spreads both rules give the same area. Strongly correlated data gets very small cells: the area goes to zero as `rho` goes to `±1`. Grid cells (`fastmath.grid`) have one size and shape, so this rule (the best area for such cells) fits them better than [[scott-2d]] (the area of the best rectangle) when the spreads of the axes differ. Points on a line (exactly one constant axis, or axes correlated up to rounding, `1 - rho^2` below about `1e-12`) have no 2d density: the area is then the square of the 1d [[scott]] bin width along the line, `(3.5 * s * n^(-1/3))^2`, where `s^2 = sx^2 + sy^2` is the variance along the line. Parameters: - `xs`, `ys` (`double` arrays): the two coordinate axes of the data, same length. Returns the estimated bin area as a `double`, `##NaN` for less than 2 points or two constant axes (left to the caller). See also [[scott-2d]], [[freedman-diaconis-2d]].
(shimazaki-shinomoto-2d xs ys type)(shimazaki-shinomoto-2d xs ys type opts)Estimates a 2d histogram cell area for xs/ys with the method of Shimazaki and Shinomoto (Neural Computation 19, 2007), for cells of the grid type (fastmath.grid).
For cells of area A, the cost (2 * mean - variance) / A^2 of the cell counts (the biased variance) estimates the integrated squared error of the histogram up to a constant. The counts include the empty cells in the index range of the occupied cells (all cells of the rows and columns of the grid that contain points). Like cross-validation-2d it adapts to the shape of the data; both usually agree.
Candidates, the limit for discretized data, points on a line parallel to an axis and the options are as in cross-validation-2d.
Parameters:
xs, ys (double arrays): the two coordinate axes of the data, same length.type (keyword): the cell type, one of fastmath.grid/cell-names.opts (map, optional): :sv, :candidates and :shifts, see cross-validation-2d.Returns the estimated cell area as a double, ##NaN for less than 2 points or two constant axes.
See also cross-validation-2d, shimazaki-shinomoto-bins.
Estimates a 2d histogram cell area for `xs`/`ys` with the method of Shimazaki and Shinomoto (Neural Computation 19, 2007), for cells of the grid `type` (`fastmath.grid`). For cells of area `A`, the cost `(2 * mean - variance) / A^2` of the cell counts (the biased variance) estimates the integrated squared error of the histogram up to a constant. The counts include the empty cells in the index range of the occupied cells (all cells of the rows and columns of the grid that contain points). Like [[cross-validation-2d]] it adapts to the shape of the data; both usually agree. Candidates, the limit for discretized data, points on a line parallel to an axis and the options are as in [[cross-validation-2d]]. Parameters: - `xs`, `ys` (`double` arrays): the two coordinate axes of the data, same length. - `type` (keyword): the cell type, one of `fastmath.grid/cell-names`. - `opts` (map, optional): `:sv`, `:candidates` and `:shifts`, see [[cross-validation-2d]]. Returns the estimated cell area as a `double`, `##NaN` for less than 2 points or two constant axes. See also [[cross-validation-2d]], [[shimazaki-shinomoto-bins]].
(shimazaki-shinomoto-bins avs)(shimazaki-shinomoto-bins avs opts)Estimates the number of histogram bins for avs with the method of Shimazaki and Shinomoto (Neural Computation 19, 2007).
For N equal bins over the range of the data (width h), the cost (2 * mean - variance) / h^2 of the bin counts (the biased variance, empty bins included) estimates the integrated squared error of the histogram up to a constant. The bin count with the lowest cost is returned. Like cross-validation-bins it adapts to the shape of the data; both usually agree.
Candidates, the limit for discretized data and the options are as in cross-validation-bins.
Parameters:
avs (double array): the data.opts (map, optional): :candidates (default 200) and :shifts (default 1), see cross-validation-bins.Returns the estimated number of bins as a positive long, 1 for less than 2 values or zero range.
See also cross-validation-bins, shimazaki-shinomoto-2d.
Estimates the number of histogram bins for `avs` with the method of Shimazaki and Shinomoto (Neural Computation 19, 2007). For `N` equal bins over the range of the data (width `h`), the cost `(2 * mean - variance) / h^2` of the bin counts (the biased variance, empty bins included) estimates the integrated squared error of the histogram up to a constant. The bin count with the lowest cost is returned. Like [[cross-validation-bins]] it adapts to the shape of the data; both usually agree. Candidates, the limit for discretized data and the options are as in [[cross-validation-bins]]. Parameters: - `avs` (`double` array): the data. - `opts` (map, optional): `:candidates` (default `200`) and `:shifts` (default `1`), see [[cross-validation-bins]]. Returns the estimated number of bins as a positive `long`, `1` for less than 2 values or zero range. See also [[cross-validation-bins]], [[shimazaki-shinomoto-2d]].
(sqrt n)Estimates the number of histogram bins for a sample of size n using the square-root choice.
Formula: ceil(sqrt(n)). Depends only on sample size; the simplest of the
bin-count estimators, used as the default by several spreadsheet and
plotting tools.
Parameters:
n (long): The sample size.Returns the estimated number of bins as a positive long (at least 1,
including when n < 1).
See also sturges, rice, terrell-scott, doane, scott,
freedman-diaconis.
Estimates the number of histogram bins for a sample of size `n` using the square-root choice. Formula: `ceil(sqrt(n))`. Depends only on sample size; the simplest of the bin-count estimators, used as the default by several spreadsheet and plotting tools. Parameters: - `n` (`long`): The sample size. Returns the estimated number of bins as a positive `long` (at least `1`, including when `n < 1`). See also [[sturges]], [[rice]], [[terrell-scott]], [[doane]], [[scott]], [[freedman-diaconis]].
(sturges n)Estimates the number of histogram bins for a sample of size n using Sturges' rule.
Formula: ceil(log2(n)) + 1. Assumes roughly normal data; tends to
under-smooth (recommend too few bins) for large or non-normal samples.
Parameters:
n (long): The sample size.Returns the estimated number of bins as a positive long (at least 1,
including when n < 1, since log2 of a non-positive n is not finite).
See also rice, doane, scott, freedman-diaconis.
Estimates the number of histogram bins for a sample of size `n` using Sturges' rule. Formula: `ceil(log2(n)) + 1`. Assumes roughly normal data; tends to under-smooth (recommend too few bins) for large or non-normal samples. Parameters: - `n` (`long`): The sample size. Returns the estimated number of bins as a positive `long` (at least `1`, including when `n < 1`, since `log2` of a non-positive `n` is not finite). See also [[rice]], [[doane]], [[scott]], [[freedman-diaconis]].
(terrell-scott n)Estimates the number of histogram bins for a sample of size n using the Terrell-Scott rule.
Formula: ceil(cbrt(2 * n)). Depends only on sample size; an
asymptotically minimal-risk rule (Terrell & Scott, 1985) related to
rice's formula but with the factor of 2 inside, rather than outside,
the cube root.
Parameters:
n (long): The sample size.Returns the estimated number of bins as a positive long (at least 1,
including when n < 1).
See also sturges, rice, sqrt, doane, scott,
freedman-diaconis.
Estimates the number of histogram bins for a sample of size `n` using the Terrell-Scott rule. Formula: `ceil(cbrt(2 * n))`. Depends only on sample size; an asymptotically minimal-risk rule (Terrell & Scott, 1985) related to [[rice]]'s formula but with the factor of `2` inside, rather than outside, the cube root. Parameters: - `n` (`long`): The sample size. Returns the estimated number of bins as a positive `long` (at least `1`, including when `n < 1`). See also [[sturges]], [[rice]], [[sqrt]], [[doane]], [[scott]], [[freedman-diaconis]].
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |