|
Cluster Statistics |
The Sheerpower Cluster Statistics Package provides a powerful set of statistical functions to analyze data stored in cluster arrays. These functions enable users to extract meaningful insights—such as trends, variability, and relationships—from large datasets, making them invaluable for applications in finance, manufacturing, science, and more.
This package works seamlessly with cluster arrays, allowing
you to perform calculations on columns of data (e.g.,
sample->value1) without manual iteration. Each
function returns a specific statistic, paired with practical
examples and decision-making guidance.
Note: The statistical function examples in
this tutorial use a cluster array named sample,
which contains two fields: value1 and
value2. The value1 field holds 100
rows with values increasing from 1 to 100, while
value2 holds values decreasing from 100 to 1.
These functions are optimized for high performance, leveraging
Sheerpower's high-speed in-memory processing capabilities.
With enough RAM, even billion row clusters are supported -- making the Sheerpower Statistics Package a very powerful tool.
Statistics on a subset: every statistical
function accepts an optional trailing true that
computes over the current collection — exactly the
rows a for each would visit — so a
collect with include filters is all it
takes to analyze a subset (see “Statistics over a
collection” below). For subsets that outlive the collection,
copying the rows into a separate cluster remains a fine approach
— Sheerpower copies millions of rows per second; see
Copy Cluster.
Error handling: a
statistics function that cannot produce an answer now
raises a catchable exception instead of returning 0.
The reason: 0 is an ordinary, legitimate statistic—a mean
of 0, a covariance of 0—so it could never reliably signal
failure. Code shaped
if stats$mean(c->v) = 0 then ! no data must become
a when exception block. Two exception types are
used:
exceptiontype("msg_nostatistic") (-4107)
— the data admits no answer: an empty cluster, too few
rows, zero variance where a variance is divided by, a zero
mean under stats$cv, or non-positive values under
stats$gmean/stats$hmean.exceptiontype("msg_num_outofrange") (-4106)
— an argument the function cannot use, such as a
percentile outside 0–100.Three deliberate cases still return 0 because there 0
is the answer: stats$cdf(0, df),
stats$fcdf(0, df1, df2), and
stats$gmean of a set that contains a 0.
Precision: 37 of the 48 functions compute
exactly on Sheerpower's 256-bit REAL arithmetic. The
eleven exceptions reach their answer through C doubles because
they need a transcendental: cagr (pow),
gmean (exp/log), cdf and
fcdf (lgamma), ncdf (erf),
tcdf (incomplete beta), ks_test (erf);
chi2, ftest, ttest, and
ttest_paired compute their statistic exactly and
use a double only for the p-value.
Every statistical function accepts an optional trailing
argument: pass true and the function computes
over the current collection — exactly the rows a
for each would visit — instead of every row in
the cluster. Filter with collect, then ask for the
statistics of what you kept:
The output (from a five-row cluster where three rows are
'east'):
Without the flag (or with false) the function
processes every row of the cluster, exactly as before. The flag
composes with everything a collection can express: an
include-filtered subset, the duplicate groups kept by
groupmin, or the survivors of a fuzzy scoring model
— if a for each would see it, the statistics see
it.
Rules worth knowing:
stats$stddev(c->v, population, true).collect/extract
has been done raises the same catchable
NEVER_EXTRACTED exception a for each
would.pcorr, cov,
ttest, ttest_paired,
chi2, linreg,
linreg_r2, spearman,
ftest,
weighted_mean) require both fields from the
same cluster when the flag is used —
two different collections have no coherent row pairing.
Mixing clusters raises a catchable
STATSTWOCLUSTERS exception (−4115).stats$zscore(field, row, true) and
stats$rank(field, row, true) the row
argument is still an ordinary cluster row — the
flag chooses the population the score or rank is
measured against.stats$max and stats$min with two
arguments are the scalar forms (stats$max(a, b)),
so their collection flag is the third argument:
stats$max(c->v, 0, true) (the middle argument is
ignored).stats$cdf, stats$fcdf,
stats$ncdf, and stats$tcdf operate on
plain values, not cluster rows, so they take no flag.Below is a detailed table of the statistical functions available in the Sheerpower Statistics Package, including when to use them, example scenarios, returned values, and actionable decisions based on the results.
(Show/Hide Functions Table)| Function | Purpose |
|---|---|
| Basic Descriptive Statistics | |
stats$max(cluster->var) |
Highest value in a column |
stats$min(cluster->var) |
Lowest value in a column |
stats$range(cluster->var) |
Difference between max and min |
stats$sum(cluster->var) |
Total of all values in a column |
stats$mean(cluster->var) |
Arithmetic mean of a column |
stats$median(cluster->var) |
Middle value of a column |
stats$mode(cluster->var) |
Most frequent value |
stats$midrange(cluster->var) |
Average of max and min values |
| Dispersion & Distribution Metrics | |
stats$stddev(cluster->var [, 1]) |
Standard deviation (sample; pass 1 as the 2nd argument for the population form) |
stats$var(cluster->var [, 1]) |
Variance (sample; pass 1 for population) |
stats$sem(cluster->var) |
Standard error of the mean (stddev / √n) |
stats$iqr(cluster->var) |
Interquartile range (Q3 - Q1) |
stats$cv(cluster->var) |
Coefficient of variation |
stats$mad(cluster->var) |
Median Absolute Deviation |
| Percentiles & Risk Measures | |
stats$percentile(cluster->var, 50) |
Specific quantile (fractional works too: 2.5, 97.5) |
stats$zscore(cluster->var, 50) |
Standardized score |
stats$drawdown(cluster->var) |
Peak-to-trough decline |
stats$vrisk(cluster->var, 0.95) |
Value at Risk at 95% |
stats$cvrisk(cluster->var, 0.95) |
Expected shortfall at 95% |
| Skewness & Kurtosis (Shape of Distribution) | |
stats$skew(cluster->var) |
Distribution symmetry |
stats$kurtosis(cluster->var) |
Tail heaviness of distribution |
stats$skew_sample(cluster->var) |
Fisher-Pearson sample skewness (alias: stats$fpskew_sample) |
stats$kurtosis_sample(cluster->var) |
Sample kurtosis |
| Alternative Measures of Central Tendency | |
stats$gmean(cluster->var) |
Geometric mean of a column |
stats$hmean(cluster->var) |
Harmonic mean of a column |
| Statistical Tests & Inference | |
stats$ttest(var1, var2) |
Compare means of two columns |
stats$ttest_paired(var1, var2) |
Paired t-test on row-by-row differences |
stats$chi2(var1, var2) |
Goodness-of-fit test |
stats$ftest(var1, var2) |
Variance comparison |
| Regression & Correlation | |
stats$linreg(var1, var2) |
Linear regression slope (intercept in _real) |
stats$linreg_r2(var1, var2) |
R-squared of the regression fit |
stats$pcorr(var1, var2) |
Pearson correlation |
stats$spearman(var1, var2) |
Rank correlation |
stats$cov(var1, var2 [, 1]) |
Covariance (sample; pass 1 for population) |
| Finance & Risk Analysis | |
stats$sharpe(cluster->var, 0) |
Risk-adjusted return |
stats$cagr(cluster->var, 2) |
Compound annual growth rate |
stats$rms(cluster->var) |
Root Mean Square |
| Additional Functions (August 2026) | |
stats$moment(cluster->var, n) |
Nth central moment |
stats$trimmed_mean(cluster->var [, pct]) |
Mean after trimming pct% from each end |
stats$weighted_mean(vals, weights) |
Weighted mean of one column by another |
stats$ema(cluster->var, alpha) |
Exponential moving average (final value) |
stats$autocorr(cluster->var [, lag]) |
Autocorrelation at the given lag (default 1) |
stats$rank(cluster->var, row) |
Rank of the value in the given row |
stats$cdf(x, df) |
Chi-square CDF at x (plain numbers, not a column) |
stats$fcdf(x, df1, df2) |
F-distribution CDF at x (plain numbers) |
stats$ncdf(x) |
Standard normal CDF at x (plain number) |
stats$tcdf(t, df) |
Student-t CDF at t (plain numbers) |
stats$ks_test(cluster->var) |
Kolmogorov–Smirnov D statistic vs. a normal
distribution fitted to the sample; p-value in
_real |
When to Use: Finding the peak value in a dataset, such as the highest daily stock price in a month.
sample->value1 to identify its maximum
value over 100 days.sample->value1).When to Use: Identifying the lowest point, such as the minimum temperature in a weather dataset.
sample->value1 to find the lowest
moisture level over a season.sample->value1).When to Use: Measuring the spread between highest and lowest values, such as temperature fluctuation.
sample->value1.sample->value1).When to Use: Aggregating totals, such as total sales revenue over a period.
sample->value1 across 100 stores.sample->value1).When to Use: Measuring central tendency, such as average customer wait time in a call center.
sample->value1.sample->value1).When to Use: Robust central tendency, such as median home prices.
sample->value1.sample->value1). With an EVEN number of
values, the exact average of the two middle values —
computed in exact REAL arithmetic, so it agrees with Excel, R,
and Python.When to Use: Most common value, such as popular product size.
sample->value1.sample->value1; when several values tie for most
frequent—as here, where every value occurs once—the
SMALLEST of them is returned).When to Use: Simple central estimate, like average of extremes in test scores.
sample->value1.sample->value1).When to Use: Assessing variability, such as consistency of product weights in manufacturing.
sample->value1.sample->value1). Pass 1 as a
2nd argument for the POPULATION form:
stats$stddev(sample->value1, 1) gives ~28.87.
The two answer different questions—know which one you
are asking.When to Use: Quantifying spread, such as volatility of investment returns.
sample->value1.sample->value1).When to Use: Reporting how precisely a mean is known — the ± on a measured average.
sample->value1.sample->value1). As a rule of thumb, the true mean
lies within ±2 SEM of the sample mean about 95% of the
time.When to Use: Measuring middle 50% spread, such as income variability.
sample->value1.sample->value1).When to Use: Relative variability, such as comparing consistency across datasets.
sample->value1.sample->value1; multiply by 100 yourself for a
percent). Computed on |mean|; a zero mean raises
msg_nostatistic.When to Use: Robust measure of spread, like variability in noisy data.
sample->value1.sample->value1). This is the RAW
MAD—no 1.4826 normal-consistency scaling is applied;
multiply yourself if you want a robust stddev estimate.When to Use: Finding a specific quantile, such as median income in a survey.
sample->value1.sample->value1), linearly interpolated.
The exact method: the position is
p/100 × (n−1) on the sorted values, with
linear interpolation between the two neighbors when it falls
between them — the same definition as Excel's
PERCENTILE.INC, NumPy's default, and R's type 7, so those
tools agree with Sheerpower to the digit (P25 of 1,2,3,4 is
1.75). The position arithmetic is exact, never a rounded
double. stats$iqr is P75 − P25
under this same method. The percentile argument may be
FRACTIONAL: stats$percentile(sample->value1, 2.5)
and 97.5 give the classic 95% band edges, under
the same exact interpolation. Out of range (below 0 or above
100) raises msg_num_outofrange.When to Use: Standardizing data, such as identifying outliers in test scores.
sample->value1 (100 results).sample->value1), always computed against the
SAMPLE standard deviation.When to Use: Measuring peak-to-trough decline, such as maximum loss in a trading account.
sample->value1 over 100 days.sample->value1 since it's
increasing.)When to Use: Risk assessment, such as Value at Risk for portfolio losses.
sample->value1.stats$percentile's interpolation on the same
data.When to Use: Expected shortfall, such as average loss beyond VaR in finance.
sample->value1.When to Use: Checking distribution symmetry, such as customer purchase amounts.
sample->value1.sample->value1, uniform). For the
sample (G1) estimator, use stats$fpskew_sample.When to Use: Evaluating tail heaviness, such as risk of extreme events in insurance claims.
sample->value1.sample->value1; flat distributions are
negative).When to Use: Measuring sample skewness, like asymmetry in production times.
sample->value1.sample->value1). Estimates the same quantity as
stats$skew with a small-sample correction.
(stats$fpskew_sample is the same function under
its original name — the “fp” stands for
Fisher-Pearson — and remains accepted.)When to Use: Assessing sample tail weight, like defect rates in quality control.
sample->value1.sample->value1).
Estimates the same quantity as stats$kurtosis
with a small-sample correction; both are near -1.2 for this
uniform ramp.When to Use: Growth rates, such as average investment return over time.
sample->value1.sample->value1).When to Use: Rates or averages with inverses, such as average speed over distances.
sample->value1.sample->value1).When to Use: Comparing means, such as A/B testing website conversion rates.
sample->value1 vs.
sample->value2, 100 clicks each).sample->value1 vs. sample->value2,
equal means). The two-sided P-VALUE is returned as a second
result in _real (Welch–Satterthwaite degrees
of freedom): read it right after the call._real, not by the size of t alone
— whether a given t is significant depends on the sample
sizes. If the p-value is below your significance level (e.g.,
< 0.05), the means genuinely differ; a p-value near 1 means
no detectable difference.When to Use: Before/after comparisons on the SAME subjects — each row pairs two measurements of one thing.
sample->value1) and after
(sample->value2) treatment._real: read it right after the call. Rows must
line up — both columns come from the same cluster with
equal counts.stats$ttest would on the
same data. A p-value below your significance level means the
treatment genuinely changed the measurement.When to Use: Goodness-of-fit, such as testing observed vs. expected frequencies.
sample->value1 vs.
expected in sample->value2._real: read it right after the call._real is below your significance level (e.g.,
< 0.05), reject the null hypothesis (data doesn't fit the
expected distribution).When to Use: Variance comparison, such as consistency of two machines.
sample->value1 vs.
sample->value2, 100 units each).sample->value1 vs. sample->value2,
identical spreads). The P-VALUE is returned in
_real._real is below your significance level, one
machine is less consistent—repair or replace.When to Use: Linear relationship, such as sales vs. ad spend.
sample->value1) and sales
(sample->value2).sample->value1 vs. sample->value2).
The INTERCEPT is returned as a second result in
_real (e.g., 101 here, since value2 = 101 -
value1): read it right after the call.When to Use: How well the regression line actually fits — the fraction of variation in y explained by x.
stats$linreg(spend, sales) gives the slope, ask
stats$linreg_r2(spend, sales) whether the line is
trustworthy._real after stats$linreg), and
R² together are the whole story of a simple
regression.When to Use: Normalized correlation, such as temperature vs. ice cream sales.
sample->value1 vs.
sample->value2).sample->value1 vs.
sample->value2).When to Use: Rank correlation, such as student test scores vs. study hours.
sample->value1 vs.
sample->value2.sample->value1 vs. sample->value2,
a perfect inverse ranking).When to Use: Relationship strength, such as stock price correlations.
sample->value1 vs.
sample->value2).sample->value1 vs.
sample->value2).When to Use: Risk-adjusted return, such as portfolio performance.
sample->value1.sample->value1). The exact
formula: (mean − risk_free) divided by
the SAMPLE standard deviation, with NO annualization —
the ratio is in whatever period your data is in (daily returns
give a daily Sharpe). You own the period conversion; daily,
monthly, and annual Sharpe ratios are not interchangeable.When to Use: Compound growth, such as investment growth rate.
sample->value1 (100
periods).value * (1 + cagr)).When to Use: Measuring magnitude, like volatility in financial time series.
sample->value1.sample->value1).Nine more functions became callable in August 2026. Values
shown are for the same sample cluster.
When to Use: Custom distribution analysis — the Nth central moment is the raw material skewness and kurtosis are built from.
stats$moment(sample->value1, 3).stats$skew/stats$kurtosis instead,
which normalize the moments for you.When to Use: An outlier-resistant average, such as judging scores or delivery times with occasional extremes.
stats$trimmed_mean(sample->value1, 10).stats$mean, outliers are driving the
plain average — investigate them before acting on
it.When to Use: An average where some rows matter more — portfolio returns weighted by position size, grades weighted by credits.
stats$weighted_mean(sample->value1,
sample->value2) — value1 weighted by value2.When to Use: A recency-weighted average, such as smoothing a price series or sensor feed where the latest readings matter most.
stats$ema(sample->value1, 0.1) (alpha 0.1 =
gentle smoothing; larger alpha reacts faster).When to Use: Detecting trend or seasonality — does the series remember its own past?
stats$autocorr(sample->value1) (lag 1; pass a
second argument for other lags, e.g. 7 for weekly
patterns).When to Use: Where one observation stands among all of them, such as a student's standing in a class.
stats$rank(sample->value1, 25).When to Use: Turning a CHI-SQUARE
statistic into a probability by hand — the distribution
function behind stats$chi2.
stats$cdf(1.5, 10).stats$chi2 itself,
just read _real instead.)When to Use: Turning an F statistic into a
probability by hand — the distribution function behind
stats$ftest.
stats$fcdf(2, 10, 20).stats$ftest itself, read _real
instead.)When to Use: Turning a z-score into a probability — the standard normal (bell curve) distribution function.
stats$ncdf(1.96).stats$zscore to turn a z-score into a
percentile.When to Use: Turning a t-statistic into a
probability by hand — the distribution function behind
stats$ttest and
stats$ttest_paired.
stats$tcdf(2.1, 10).stats$ncdf._real.)When to Use: A quick normality check before leaning on tools that assume a bell curve.
stats$ks_test(sample->value1)._real (~0.839 here): read it right after the
call. Because the reference normal is fitted from the sample
itself, this classical p-value reads a little HIGH
(conservative)—a strict normality test would use the
Lilliefors distribution.stats$median, stats$mad,
stats$trimmed_mean) over mean-and-stddev
reasoning.With sample->value1 and
sample->value2 as example data sources, the
Sheerpower Statistics Package analyzes trends, variability,
and relationships in contexts like finance, manufacturing,
and science. Decisions pivot on whether values meet targets
(e.g., stats$mean, stats$cagr),
indicate risk (stats$vrisk,
stats$sharpe), or suggest relationships
(stats$cov, stats$pcorr)—guiding
actions from resource allocation to strategic shifts.
stats$mean, stats$median) to
advanced metrics (stats$kurtosis,
stats$spearman).The Sheerpower Statistics Package empowers users to turn raw data into actionable insights with ease and precision.
stats$mean,
stats$median, stats$mode,
stats$sum, stats$range.stats$stddev,
stats$var, stats$cv, stats$mad,
stats$iqr, and stats$sem.stats$skew,
stats$kurtosis, and sample-based versions.stats$percentile,
stats$zscore, stats$vrisk,
stats$cvrisk, and stats$drawdown.stats$gmean
(geometric) and stats$hmean (harmonic).stats$ttest,
stats$ttest_paired, stats$chi2, and
stats$ftest support inference and comparison.stats$linreg, stats$pcorr,
stats$spearman, and stats$cov.stats$sharpe,
stats$cagr, and stats$rms guide risk
and return assessments.stats$moment,
stats$trimmed_mean, stats$weighted_mean,
stats$ema, stats$autocorr,
stats$rank, stats$cdf,
stats$fcdf, stats$ncdf,
stats$tcdf, and stats$ks_test
(August 2026).stats$stddev, stats$var, and
stats$cov are SAMPLE statistics by default; pass 1
as the final argument for the population form.stats$linreg also returns the intercept, and
stats$ttest/stats$ttest_paired/stats$chi2/stats$ftest/stats$ks_test
their p-values, as a second result in _real—read
it right after the call.|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |