stats

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package stats provides statistical functions for CI performance analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampOutliers

func ClampOutliers(data []float64, multiplier float64) []float64

ClampOutliers replaces isolated extreme values with the nearest fence value. Uses the IQR method: values beyond Q3 + multiplier×IQR (or below Q1 - multiplier×IQR) are clamped to the fence. This prevents single extreme outliers from poisoning downstream analysis while preserving genuine level shifts (which move the IQR).

func IQR

func IQR(data []float64) (q1, q3, iqr float64)

IQR returns Q1, Q3, and the interquartile range.

func MannWhitneyU

func MannWhitneyU(sample1, sample2 []float64) (u, pValue float64)

MannWhitneyU performs a two-sided Mann-Whitney U test comparing two samples. Uses a fresh random source for the permutation path, so results are non-deterministic. For deterministic tests use MannWhitneyURand.

func MannWhitneyURand

func MannWhitneyURand(sample1, sample2 []float64, rng *rand.Rand) (u, pValue float64)

MannWhitneyURand performs a two-sided Mann-Whitney U test comparing two samples. Uses three strategies depending on sample size:

  • Exact enumeration when n1+n2 <= 20 (feasible combinatorics)
  • Monte Carlo permutation test when min(n1,n2) <= 20 (small sample, exact infeasible)
  • Normal approximation when both n1,n2 > 20

If rng is nil, a fresh random source is used. A small p-value (< 0.05) indicates the two samples likely come from different distributions.

func Mean

func Mean(data []float64) float64

Mean returns the arithmetic mean.

func Median

func Median(data []float64) float64

Median returns the median of a float64 slice. The input is not modified.

func Percentile

func Percentile(data []float64, p float64) float64

Percentile returns the p-th percentile (0-100) using linear interpolation. The input is not modified.

func Stddev

func Stddev(data []float64) float64

Stddev returns the sample standard deviation.

Types

type ChangePoint

type ChangePoint struct {
	Index      int     // position in the series where the change was detected
	BeforeMean float64 // mean of values before the change
	AfterMean  float64 // mean of values after the change
	PctChange  float64 // percentage change (positive = slowdown, negative = speedup)
	Direction  string  // "slowdown" or "speedup"
}

ChangePoint represents a detected shift in a time series.

func CUSUMDetect

func CUSUMDetect(data []float64, thresholdMultiplier float64, minSegment int) []ChangePoint

CUSUMDetect runs two-sided CUSUM (Cumulative Sum) change-point detection. It uses adaptive thresholds based on the local coefficient of variation:

  • slack (k) = 0.5 * stddev of baseline
  • threshold (h) = thresholdMultiplier * stddev of baseline

minSegment controls the minimum number of points between detected change points and at the start/end of the series.

type OutlierResult

type OutlierResult struct {
	Index      int
	Value      float64
	Percentile float64 // what percentile this value falls at (0-100)
	IsOutlier  bool
}

OutlierResult contains the result of outlier detection for a single data point.

func LogIQROutliers

func LogIQROutliers(data []float64, multiplier float64) (outliers []OutlierResult, upperFence float64)

LogIQROutliers detects abnormally slow values using the IQR method on log-transformed data. Only flags the upper tail — unusually fast runs are not interesting for CI analysis. The multiplier controls sensitivity (standard: 1.5, conservative: 3.0).

func MADOutliers

func MADOutliers(data []float64, threshold float64) (outliers []OutlierResult)

MADOutliers detects abnormally slow values using Median Absolute Deviation. Only flags the upper tail. The threshold is applied to the modified z-score (commonly 3.5).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL