stat

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package stat provides statistical transformations for the Grammar of Graphics. Stats compute derived data (bins, counts, densities, smooths) from raw data, producing new datasets that are then rendered by geometries.

Each stat implements the Stat interface and is registered with a typed Name for lookup during pipeline compilation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(s Stat)

Register adds a stat to the global registry.

Types

type Name

type Name string

Name identifies a statistical transformation.

const (
	Identity Name = "identity"
	Bin      Name = "bin"
	Count    Name = "count"
	Density  Name = "density"
	Smooth   Name = "smooth"
	Summary  Name = "summary"
	Boxplot  Name = "boxplot"
)

type Options

type Options struct {
	Bins      int     // number of bins (histogram/bin stat); 0 = auto
	BinMethod string  // binning strategy: "sturges" (default), "scott", "fd", "sqrt"
	Method    string  // smoothing method: "lm", "loess"
	Points    int     // number of output grid points
	Bandwidth float64 // KDE bandwidth; 0 = Silverman auto-select
	Whisker   string  // boxplot whisker rule: "tukey" (default 1.5×IQR), "range" (min-max)
	Notch     bool    // boxplot: compute notch confidence interval around median
}

Options holds typed parameters for stat computations, replacing magic string keys like "__bins".

type Stat

type Stat interface {
	// Name returns the stat's typed identifier.
	Name() Name

	// RequiredAes returns the aesthetic channels this stat needs.
	RequiredAes() []string

	// OutputSchema returns the column names this stat produces.
	OutputSchema() []string

	// OutputMapping returns the aesthetic-to-column mapping for the stat's
	// output. The renderer uses this to know which output column maps to
	// which aesthetic channel (e.g., {"x": "x", "y": "count"} for stat_bin).
	// Returns nil for identity stats (no rewriting needed).
	// This replaces hardcoded per-stat switches in the rendering pipeline.
	OutputMapping() map[string]string

	// Compute performs the transformation.
	Compute(ctx context.Context, ds dataset.Dataset, mapping map[string]string, opts Options) (dataset.Dataset, error)
}

Stat computes a statistical transformation on a dataset, producing a new (possibly differently shaped) dataset. The transformed dataset's columns depend on the stat type.

func Lookup

func Lookup(name Name) (Stat, error)

Lookup returns a stat by name. Returns an error for unknown names.

Jump to

Keyboard shortcuts

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