cheatah
Module

stats

cheatah-plot v0.1.0-alpha — Biome Standard 0.6.3-alpha

Classes

Functions

fn Hist histogram(::cheatah::ndarray::basic_ndarray< double > &data, builtins::Value auto &&bins) #

Uniform-bin histogram of data over its widened range (plot.scale.data_range, so flat or empty data still bins sanely).

NaN values are skipped; values at or beyond the top edge land in the last bin (the conventional right-inclusive tail).

Parameters
data

the samples.

bins

the bin count (clamped up to at least 1).

Returns

the Hist with edges, centers, and counts.

Complexity

O(n + bins).

Allocation

the three returned arrays.

System testsystests/test_stats.purr
Example
import plot.stats as stats
import ndarray
let data = ndarray.array([0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0])
let h = stats.histogram(data, 4)   # -> h.centers/h.counts are bar-ready arrays
fn inline ::cheatah::ndarray::basic_ndarray< double > fit(::cheatah::ndarray::basic_ndarray< double > &x, ::cheatah::ndarray::basic_ndarray< double > &y) #

The least-squares LINE through (x, y), evaluated at each x — pass it straight to a line mark to overlay the trend (figure.line(x, stats.fit(x, y))).

The solve is linalg.lstsq on the [x, 1] design matrix; this function only assembles operands and evaluates the result.

Parameters
x

the x positions.

y

the y values (same length).

Returns

the fitted line's y at each x (fewer than 2 points: y unchanged — no line to fit).

Complexity

O(n) assembly + the lstsq solve.

Allocation

the design/rhs operands and the returned array.

System testsystests/test_stats.purr
Example
import plot.figure as figure
import plot.stats as stats
import ndarray
let x = ndarray.array([0.0, 1.0, 2.0, 3.0])
let y = ndarray.array([1.1, 2.9, 5.2, 6.8])
let trend = stats.fit(x, y)
let f = figure.new_figure()
f = figure.line(f, x, trend)   # -> the least-squares trend over the data
fn double sem(::cheatah::ndarray::basic_ndarray< double > &data) #

The standard error of the mean — the honest default magnitude for symmetric error bars (statistics.stdev under the hood; this function only supplies the √n).

Parameters
data

the samples.

Returns

stdev(data) / √n (0 when fewer than 2 samples — no spread to estimate).

Complexity

O(n).

Allocation

one transient list copy (statistics consumes lists).

System testsystests/test_stats.purr
Example
import plot.stats as stats
import ndarray
let data = ndarray.array([1.0, 2.0, 3.0, 4.0])
let e = stats.sem(data)   # -> 0.645...: stdev / sqrt(4), an errorbar magnitude
fn const char * module_abi() noexcept #

ABI/identity marker for the stats cheatah module: returns the module name.

Auto-emitted by purrc's library emitter. It is the concrete symbol that anchors the module's signed static archive in opaque (source-hidden) builds.

Returns

the module name ("stats").