Forum Discussion
pett2008
Aug 25, 2022Copper Contributor
Using Data Analysis tool pak to create histograms
Hello I am trying to create a histogram for the data on acorn size in mm for two collection sites. Site 1 is titled Creek, and site 2 is titled River. RIVER Site data is: 5.8 5.2 5.7 4.2 4...
Patrick2788
Aug 21, 2026Silver Contributor
I can't speak to the analysis tool pak solution as I haven't used it in ages. I will offer a generalized Lambda solution - Histogramλ. This function will take care of the binning for you by inspecting the data and applying the binning rule which makes the most sense. You can also override this by supplying the bin_width (optional).
/* [GR13] -------------------------------------------------------------------------
Function: Histogramλ
Category: Grid Analytics (Statistics)
Author: Patrick H.
Version: 1.1
Description:
Generates a histogram using automatic binning rules (Sturges, Rice,
Scott, Freedman) depending on sample size and skewness. Supports an
optional fixed bin width and an optional Pareto (cumulative %) column.
Parameters:
array - Numeric array (1D or 2D).
[bin_width] - Optional fixed bin width (0 < width ≤ 1000).
[include_Pareto] - TRUE → include cumulative % column.
Notes:
• Returns #VALUE! if fewer than 2 values are supplied.
• Caps total bins at 100.
• If bin_width is supplied, automatic rules are bypassed.
------------------------------------------------------------------------------*/
Histogramλ =
LAMBDA(
array,
[bin_width],
[include_Pareto],
IF(COUNT(array) <= 1,#VALUE!,
IF(AND(NOT(ISOMITTED(bin_width)),OR(bin_width < 0, bin_width > 1000)),"#BIN-WIDTH!",
LET(
// Sample characteristics
n, COUNT(array),
SmallData?, n < 200,
Add_Pareto?, NOT(ISOMITTED(include_Pareto)),
min, MIN(array),
max, MAX(array),
range, max - min,
iqr, QUARTILE(array, 3) - QUARTILE(array, 1),
s, SKEW(array),
IsSkewed?, IF(SmallData?, FALSE, ABS(s) > 0.2),
// Optional fixed bin width
IsFixed?, NOT(ISOMITTED(bin_width)),
// Automatic binning rules
Sturge, CEILING(LOG(n, 2) + 1, 1),
SRR, CEILING(SQRT(n), 1),
Rice, CEILING(2 * n^(1/3), 1),
Scott, CEILING(3.5 * STDEV.P(array) / n^(1/3), 1),
Freedman, CEILING(2 * iqr / n^(1/3), 1),
fixed, CEILING(range / bin_width, 1 / bin_width),
// Bin count selection
k, IF(IsFixed?,fixed,
IF(n <= 30,MAX(Sturge, Rice),
IF(IsSkewed?,MIN(Freedman, 15),
MIN(Scott, 15)))),
// Avoid single-bin output; cap at 100
k_, MIN(IF(k = 1, 5, k), 100),
// Bin interval
interval, IF(range = 0, 1, MAX(range / k_, 0.1)),
bin_upper, CEILING(max, interval),
bin_lower, FLOOR(min, interval),
bin_arr, SEQUENCE(1 + (bin_upper - bin_lower) / interval,,bin_lower,interval),
// Bin labels
bin_start, DROP(bin_arr, -1),
bin_end, DROP(bin_arr, 1),
bin_header, {"Start", "End", "Total"},
bin_labels, HSTACK(VSTACK("<", bin_start),
VSTACK(TAKE(bin_start, 1), bin_end)),
// Frequencies and Pareto
freq, DROP(FREQUENCY(array, bin_arr), -1),
Pareto, BYROW(freq, LAMBDA(v, PERCENTOF(v, freq))),
// Final assembly
stack, VSTACK(bin_header, HSTACK(bin_labels, freq)),
deliver, IF(Add_Pareto?,SORT(HSTACK(stack,VSTACK("Cumulative %", Pareto)),3,-1),
stack),
deliver
))));
- cadtriAug 21, 2026Copper Contributor
https://www.cadtri.com/helps contractors, developers, architects, and property owners keep projects moving with permit-ready construction drawings, coordinated documentation, and reliable drafting support services.