Popup YouTube Video
Sheerpower Logo

Cluster Statistics


The Sheerpower Cluster Statistics Package

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.


Statistics over a Collection

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:

collect cluster sales include sales->region$ = 'east' end collect print 'east rows: '; _extracted print 'east total: '; stats$sum(sales->amount, true) print 'east mean: '; stats$mean(sales->amount, true) print 'east median: '; stats$median(sales->amount, true) print 'all total: '; stats$sum(sales->amount)

The output (from a five-row cluster where three rows are 'east'):

east rows: 3 east total: 4500 east mean: 1500 east median: 1500 all total: 5250

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:

  • The flag comes after any existing optional arguments: stats$stddev(c->v, population, true).
  • Using the flag before any collect/extract has been done raises the same catchable NEVER_EXTRACTED exception a for each would.
  • Two-field functions (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).
  • For 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.

Statistical Functions Overview

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)
(Show/Hide Scenarios)

Summary: The Sheerpower Statistics Package

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.

Key Features:

  • Comprehensive Analysis: From basic stats (stats$mean, stats$median) to advanced metrics (stats$kurtosis, stats$spearman).
  • Decision Support: Practical examples and decision points for real-world applications.
  • Performance: Optimized for large datasets, leveraging Sheerpower's cluster efficiency.

The Sheerpower Statistics Package empowers users to turn raw data into actionable insights with ease and precision.

(Show/Hide Sheerpower Cluster Statistics Takeaways)
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.