### Install Pragmastat via Go Modules
Source: https://github.com/andreyakinshin/pragmastat/blob/main/go/README.md
Use the go get command to add the library to your project.
```bash
go get github.com/AndreyAkinshin/pragmastat/go/v14@v14.0.1
```
--------------------------------
### Install Pragmastat
Source: https://github.com/andreyakinshin/pragmastat/blob/main/py/README.md
Install the library using pip.
```bash
pip install pragmastat==14.0.1
```
--------------------------------
### Install Pragmastat via npm
Source: https://github.com/andreyakinshin/pragmastat/blob/main/ts/README.md
Use this command to install the library in your project.
```bash
npm i pragmastat@14.0.1
```
--------------------------------
### Install Pragmastat via Gradle
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/README.md
Add the implementation dependency to your build.gradle or build.gradle.kts file.
```java
implementation 'dev.pragmastat:pragmastat:14.0.1'
```
```kotlin
implementation("dev.pragmastat:pragmastat:14.0.1")
```
--------------------------------
### Demonstrate Pragmastat Statistical Features
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/README.md
A comprehensive example covering one-sample and two-sample statistics, confirmatory comparisons, custom unit registration, random number generation, and probability distributions.
```kotlin
package dev.pragmastat.demo
import dev.pragmastat.*
import dev.pragmastat.distributions.*
fun main() {
// --- One-Sample ---
val x = Sample.of((1..200).map { it.toDouble() })
println(center(x)) // 100.5
println(spread(x)) // 59.0
println(centerBounds(x, Probability(1e-3))) // Bounds(lower=86.0, upper=115.0, unit=...)
println(spreadBounds(x, Probability(1e-3), "demo")) // Bounds(lower=44.0, upper=87.0, unit=...)
// --- Two-Sample ---
val sx = Sample.of((1..200).map { it.toDouble() })
val sy = Sample.of((101..300).map { it.toDouble() })
println(shift(sx, sy)) // -100.0
println(shiftBounds(sx, sy, Probability(1e-3))) // Bounds(lower=-120.0, upper=-80.0, unit=...)
println(ratio(sx, sy)) // 0.5008354224706336
println(ratioBounds(sx, sy, Probability(1e-3))) // Bounds(lower=0.4066..., upper=0.5958..., unit=...)
println(disparity(sx, sy)) // -1.694915254237288
println(disparityBounds(sx, sy, Probability(1e-3), "demo")) // Bounds(lower=-3.1025..., upper=-0.8494..., unit=...)
// --- Confirmatory Comparison ---
println(compare1(sx, listOf(Threshold(Metric.Center, Measurement(50.0), Probability(1e-3))))[0].verdict.toId()) // greater
println(compare2(sx, sy, listOf(Threshold(Metric.Shift, Measurement(0.0), Probability(1e-3))))[0].verdict.toId()) // less
// --- Custom units ---
val ns = MeasurementUnit("ns", "Time", "ns", "Nanosecond", 1)
val us = MeasurementUnit("us", "Time", "us", "Microsecond", 1000)
val ms = MeasurementUnit("ms", "Time", "ms", "Millisecond", 1_000_000)
val registry = UnitRegistry.standard()
registry.register(ns)
registry.register(us)
registry.register(ms)
val timeSample = Sample.of(listOf(100.0, 200.0, 300.0, 400.0, 500.0), ns)
println(center(timeSample)) // 300 ns
println(center(timeSample.convertTo(us))) // 0.3 us
// --- Randomization ---
var rng = Rng("demo-uniform")
println(rng.uniformDouble()) // 0.2640554428629759
println(rng.uniformDouble()) // 0.9348534835582796
rng = Rng("demo-uniform-int")
println(rng.uniformInt(0, 100)) // 41
rng = Rng("demo-sample")
println(rng.sample(listOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), 3)) // [3.0, 8.0, 9.0]
rng = Rng("demo-resample")
println(rng.resample(listOf(1.0, 2.0, 3.0, 4.0, 5.0), 7)) // [3.0, 1.0, 3.0, 2.0, 4.0, 1.0, 2.0]
rng = Rng("demo-shuffle")
println(rng.shuffle(listOf(1.0, 2.0, 3.0, 4.0, 5.0))) // [4.0, 2.0, 3.0, 5.0, 1.0]
// --- Distributions ---
rng = Rng("demo-dist-additive")
println(Additive(0.0, 1.0).sample(rng)) // 0.17410448679568188
rng = Rng("demo-dist-multiplic")
println(Multiplic(0.0, 1.0).sample(rng)) // 1.1273244602673853
rng = Rng("demo-dist-exp")
println(Exp(1.0).sample(rng)) // 0.6589065267276553
rng = Rng("demo-dist-power")
println(Power(1.0, 2.0).sample(rng)) // 1.023677535537084
rng = Rng("demo-dist-uniform")
println(Uniform(0.0, 10.0).sample(rng)) // 6.54043657816832
}
```
--------------------------------
### Install Pragmastat via Cargo
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/pragmastat/README.md
Methods for adding the library to a Rust project.
```bash
cargo add pragmastat@14.0.1
```
```toml
[dependencies]
pragmastat = "14.0.1"
```
--------------------------------
### Install Pragmastat via .NET CLI
Source: https://github.com/andreyakinshin/pragmastat/blob/main/cs/README.md
Use this command to add the Pragmastat package to your project using the .NET CLI.
```bash
dotnet add package Pragmastat --version 14.0.1
```
--------------------------------
### Install Pragmastat from GitHub
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/README.md
Use the remotes package to install the specific version of the Pragmastat package from the GitHub repository.
```r
install.packages("remotes") # If 'remotes' is not installed
remotes::install_github("AndreyAkinshin/pragmastat",
subdir = "r/pragmastat", ref = "v14.0.1")
library(pragmastat)
```
--------------------------------
### Perform One-Sample Confirmatory Analysis
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/compare1.Rd
Example demonstrating how to define thresholds and execute the compare1 function on a numeric vector.
```R
thresholds <- list(
list(metric = "center", value = 20, misrate = 1e-3),
list(metric = "spread", value = 0.1, misrate = 1e-3)
)
result <- compare1(1:30, thresholds, seed = "demo")
result[[1]]$verdict
result[[2]]$verdict
```
--------------------------------
### Install Pragmastat via Package Manager Console
Source: https://github.com/andreyakinshin/pragmastat/blob/main/cs/README.md
Use this command to add the Pragmastat package to your project using the NuGet Package Manager Console.
```ps1
NuGet\Install-Package Pragmastat -Version 14.0.1
```
--------------------------------
### Define SpreadBounds test with seed
Source: https://github.com/andreyakinshin/pragmastat/blob/main/tests/README.md
Example for SpreadBounds, AvgSpreadBounds, or DisparityBounds using a seed for deterministic results.
```json
{
"input": { "x": [1, 2, 3, 4, 5], "misrate": 0.5, "seed": "spread-bounds-tests" },
"output": { "lower": 1.0, "upper": 3.0 }
}
```
--------------------------------
### Install Pragmastat via Maven
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/README.md
Add this dependency to your pom.xml file to include Pragmastat in your Apache Maven project.
```xml
dev.pragmastat
pragmastat
14.0.1
```
--------------------------------
### Calculate Disparity Between Samples
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/disparity.Rd
Examples demonstrating the disparity estimator across various scenarios including clear separation, overlap, identical samples, and outlier presence.
```R
# Basic usage
x <- c(1, 2, 3, 4, 5)
y <- c(6, 7, 8, 9, 10)
disparity(x, y) # Large disparity due to clear separation
# Overlapping samples
x <- c(1, 2, 3, 4, 5)
y <- c(3, 4, 5, 6, 7)
disparity(x, y) # Smaller disparity due to overlap
# Identical samples
x <- c(1, 2, 3, 4, 5)
y <- c(1, 2, 3, 4, 5)
disparity(x, y) # Should be close to 0
# With outliers
x <- c(1, 2, 3, 4, 500)
y <- c(6, 7, 8, 9, 10)
disparity(x, y) # Robust to outliers
```
--------------------------------
### Basic Sample Usage
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Sample.Rd
Demonstrates creating a Sample object and accessing its properties like values, sorted values, and size.
```R
# Basic usage
x <- Sample$new(c(5.6, 1.2, 3.4))
x$values # c(5.6, 1.2, 3.4) - original order
x$sorted_values # c(1.2, 3.4, 5.6) - lazy sorted copy
x$size # 3
```
--------------------------------
### Using UnitRegistry for unit management
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/UnitRegistry.Rd
Demonstrates creating a registry, registering a custom unit, and resolving it, as well as using the pre-populated standard registry.
```R
reg <- UnitRegistry$new()
ms <- MeasurementUnit$new("ms", "time", "ms", "milliseconds", 1)
reg$register(ms)
reg$resolve("ms")$full_name # "milliseconds"
# Or use the pre-populated factory
reg <- standard_registry()
reg$resolve("number")$full_name # "Number"
```
--------------------------------
### Project directory structure
Source: https://github.com/andreyakinshin/pragmastat/blob/main/go/AGENTS.md
Overview of the Go source files and test suite organization.
```text
go/
├── estimators.go # Public API: Center, Spread, Shift, etc.
├── assumptions.go # Input validation and error types
├── pairwise_margin.go # Margin calculation for shift bounds
├── sign_margin.go # Sign margin for binomial CDF inversion
├── signed_rank_margin.go # Signed-rank margin computation
├── min_misrate.go # Minimum achievable misrate calculation
├── additive_cumulative.go # Standard normal CDF (Chebyshev-fitted erf/erfc)
├── exp_function.go # Reproducible exp: range reduction plus fitted polynomial
├── rng.go # Deterministic xoshiro256++ PRNG
├── xoshiro256.go # PRNG core implementation
├── center_impl.go # O(n log n) Hodges-Lehmann algorithm
├── center_quantiles_impl.go # Center quantile binary search
├── spread_impl.go # O(n log n) Shamos algorithm
├── shift_impl.go # O((m+n) log L) shift quantiles
├── distribution.go # Distribution interface
├── uniform.go # Uniform distribution
├── additive.go # Additive (Normal/Gaussian) distribution
├── exp.go # Exponential distribution
├── power.go # Power distribution
├── multiplic.go # Multiplicative (Log-Normal) distribution
├── demo/
│ └── main.go # Demo application
├── assume_sorted_test.go # assume-sorted equivalence
├── properties_test.go # Unit propagation, misrate domain, n==2 symmetry
├── center_convergence_test.go # Center convergence-guard regression
├── compare_test.go # Compare framework
├── dualpath_test.go # Dual-path reference (raw + Sample)
├── invariance_test.go # Mathematical property tests
├── mutation_test.go # Raw-API input-mutation safety
├── performance_test.go # Performance smoke test
├── ratio_bounds_test.go # ratioBounds error priority
├── reference_test.go # JSON fixture validation
├── sample_race_test.go # Concurrent Sample access (race detector)
├── sample_test.go # Sample construction
├── spread_convergence_test.go # Spread convergence-guard regression
└── subject_test.go # Positional subject assignment
```
--------------------------------
### Handle Assumption Exceptions
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/AGENTS.md
Example of catching AssumptionException to inspect violation details.
```kotlin
try {
val result = center(x)
} catch (e: AssumptionException) {
// e.violation.id: VALIDITY, DOMAIN, POSITIVITY, SPARITY
// e.violation.subject: X, Y, MISRATE
}
```
--------------------------------
### Run Project Tests
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/AGENTS.md
Commands to execute the test suite using mise or Gradle.
```bash
mise run kt:test # All tests (preferred)
./gradlew test # All tests (raw)
./gradlew test --info # Verbose output
```
--------------------------------
### Define one-sample estimator test
Source: https://github.com/andreyakinshin/pragmastat/blob/main/tests/README.md
Example input and output for one-sample estimators like center or spread.
```json
{
"input": { "x": [1, 2, 3, 4, 5] },
"output": 3.0
}
```
--------------------------------
### Initialize and Access Measurement Objects
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Measurement.Rd
Demonstrates creating a Measurement object with default or custom units and accessing its properties.
```R
m <- Measurement$new(42.0)
m$value # 42.0
m$unit$id # "number"
as.numeric(m) # 42.0
ms <- MeasurementUnit$new("ms", "time", "ms", "milliseconds", 1)
m <- Measurement$new(3.14, ms)
m$unit$id # "ms"
```
--------------------------------
### Handle Assumption Errors
Source: https://github.com/andreyakinshin/pragmastat/blob/main/ts/AGENTS.md
Example of catching and inspecting AssumptionError instances to identify specific violation types.
```typescript
import { center, AssumptionError } from 'pragmastat';
try {
const result = center(x);
} catch (e) {
if (e instanceof AssumptionError) {
// e.violation.id: "validity", "domain", "positivity", "sparity"
// e.violation.subject: "x", "y", "misrate"
}
}
```
--------------------------------
### Execute tests via command line
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/AGENTS.md
Run the full test suite using the mise task runner.
```bash
mise run r:test # All tests (preferred)
```
--------------------------------
### Define two-sample estimator test
Source: https://github.com/andreyakinshin/pragmastat/blob/main/tests/README.md
Example input and output for two-sample estimators like shift, ratio, or disparity.
```json
{
"input": { "x": [1, 2, 3], "y": [4, 5, 6] },
"output": -3.0
}
```
--------------------------------
### Execute project tests
Source: https://github.com/andreyakinshin/pragmastat/blob/main/go/AGENTS.md
Commands for running tests, benchmarks, and verbose output.
```bash
mise run go:test # All tests (preferred)
go test ./... # All tests (raw)
go test -v ./... # Verbose output
go test -bench=. ./... # Run benchmarks
```
--------------------------------
### Sample Methods
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Sample.Rd
Methods available on Sample instances for data transformation.
```APIDOC
## convert_to(target)
### Description
Converts the sample values to a compatible target unit.
### Parameters
- **target** (MeasurementUnit) - Required - The target unit for conversion.
## log_transform()
### Description
Applies a log transformation to the sample values. All values must be positive. Returns a new Sample instance.
```
--------------------------------
### UnitRegistry$initialize()
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/UnitRegistry.Rd
Creates a new, empty instance of the UnitRegistry class.
```APIDOC
## UnitRegistry$initialize()
### Description
Creates a new empty UnitRegistry instance.
### Usage
`reg <- UnitRegistry$new()`
```
--------------------------------
### Initialize and sample from an exponential distribution
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/dist_exp.Rd
Demonstrates creating an exponential distribution with a rate of 1 and generating a sample using a random number generator.
```R
r <- rng("demo-dist-exp")
dist <- dist_exp(1) # rate=1, mean=1
dist$sample(r)
```
--------------------------------
### Constructing Statistical Samples
Source: https://github.com/andreyakinshin/pragmastat/blob/main/py/AGENTS.md
Initialize samples with optional units and weights. Construction validates that values are finite and weights are correctly sized and non-negative.
```python
from pragmastat import Sample, NUMBER_UNIT
x = Sample([1, 2, 3, 4, 5]) # unweighted, NUMBER_UNIT
x = Sample([1, 2, 3], unit=NUMBER_UNIT) # explicit unit
x = Sample([1, 2, 3], weights=[0.5, 0.3, 0.2]) # weighted
```
--------------------------------
### Sample$new(values, weights = NULL, unit = NULL)
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Sample.Rd
Constructor for creating a new validated numeric sample. Validates that input values are finite and non-empty.
```APIDOC
## Sample$new(values, weights = NULL, unit = NULL)
### Description
Creates a new instance of the Sample class. Validates input vectors for finiteness and ensures weights are non-negative.
### Parameters
- **values** (numeric vector) - Required - A non-empty vector of finite numeric values.
- **weights** (numeric vector) - Optional - A vector of non-negative weights, must match the length of values.
- **unit** (MeasurementUnit) - Optional - The measurement unit associated with the data, defaults to number_unit.
```
--------------------------------
### Typed Sample API Methods
Source: https://github.com/andreyakinshin/pragmastat/blob/main/go/AGENTS.md
Methods available on the *Sample struct for point and bounds estimation with unit propagation.
```go
// Point estimators (return Measurement with propagated unit)
func (s *Sample) Center() (Measurement, error)
func (s *Sample) Spread() (Measurement, error)
func (s *Sample) Shift(other *Sample) (Measurement, error)
func (s *Sample) Ratio(other *Sample) (Measurement, error)
func (s *Sample) Disparity(other *Sample) (Measurement, error)
// Bounds estimators
func (s *Sample) CenterBounds(misrate float64) (Bounds, error)
func (s *Sample) SpreadBounds(misrate float64) (Bounds, error)
func (s *Sample) SpreadBoundsWithSeed(misrate float64, seed string) (Bounds, error)
func (s *Sample) ShiftBounds(other *Sample, misrate float64) (Bounds, error)
func (s *Sample) RatioBounds(other *Sample, misrate float64) (Bounds, error)
func (s *Sample) DisparityBounds(other *Sample, misrate float64) (Bounds, error)
func (s *Sample) DisparityBoundsWithSeed(other *Sample, misrate float64, seed string) (Bounds, error)
```
--------------------------------
### Initialize and compare MeasurementUnits
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/MeasurementUnit.Rd
Create instances of MeasurementUnit and verify compatibility between units of the same family.
```R
ms <- MeasurementUnit$new("ms", "time", "ms", "milliseconds", 1)
sec <- MeasurementUnit$new("s", "time", "s", "seconds", 1000)
ms$is_compatible(sec) # TRUE
```
--------------------------------
### Execute Build Commands
Source: https://github.com/andreyakinshin/pragmastat/blob/main/kt/AGENTS.md
Use these commands via mise to manage the project build, test, and CI processes.
```bash
mise run kt:ci # Full CI: clean → restore → check → build → test
mise run kt:test # Run tests only
mise run kt:check # Run all checks (lint, format)
mise run kt:demo # Run demo application
mise run kt:build # Build with Gradle
mise run kt:pack # Create JAR package
```
--------------------------------
### Run Test Suite
Source: https://github.com/andreyakinshin/pragmastat/blob/main/ts/AGENTS.md
Commands to execute the project test suite and generate coverage reports.
```bash
mise run ts:test # All tests (preferred)
npm test # All tests (raw)
npm run test:coverage # With coverage report
```
--------------------------------
### Rust Build and Development Commands
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/AGENTS.md
Use these commands via mise to manage the project build, test, and linting processes.
```bash
mise run rs:ci # Full CI: clean → check → build → test
mise run rs:test # Run tests only
mise run rs:check # Lint (clippy) + format check
mise run rs:check:fix # Auto-format code
mise run rs:demo # Run demo example
mise run rs:bench # Run benchmarks
```
--------------------------------
### Build Commands for Python Project
Source: https://github.com/andreyakinshin/pragmastat/blob/main/py/AGENTS.md
Use these commands via mise to manage the development lifecycle, including testing, linting, and packaging.
```bash
mise run py:ci # Full CI: clean -> restore -> check -> test -> pack
mise run py:test # Run tests only
mise run py:check # Lint (ruff) + format check
mise run py:check:fix # Auto-fix lint issues and format
mise run py:demo # Run demo
mise run py:build # Build distribution package
mise run py:pack # Build and verify with twine
```
--------------------------------
### Run project tests
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/AGENTS.md
Commands to execute various test suites for the project using mise or cargo.
```bash
mise run rs:test # All tests (preferred)
cargo test # All tests (raw)
cargo test reference # Reference tests only
cargo test invariance # Invariance tests only
cargo test --test error_tests # Error handling tests
```
--------------------------------
### Build Commands for C# Project
Source: https://github.com/andreyakinshin/pragmastat/blob/main/cs/AGENTS.md
Use these mise commands to manage the build lifecycle, testing, and formatting of the C# project.
```bash
mise run cs:ci # Full CI: clean → restore → check → build → test
mise run cs:test # Run tests only
mise run cs:check # Format verification (dotnet format)
mise run cs:check:fix # Auto-format code
mise run cs:demo # Run demo application
mise run cs:build # Build (debug mode)
mise run cs:build:release # Build (release mode)
mise run cs:pack # Create NuGet package
mise run cs:gen # Generate reference test files
```
--------------------------------
### Pragmastat Usage Demo
Source: https://github.com/andreyakinshin/pragmastat/blob/main/go/README.md
Demonstrates one-sample and two-sample statistical analysis, confirmatory comparisons, randomization, and distribution sampling.
```go
package main
import (
"fmt"
"log"
pragmastat "github.com/AndreyAkinshin/pragmastat/go/v14"
)
func mustM(val pragmastat.Measurement, err error) pragmastat.Measurement {
if err != nil {
log.Fatal(err)
}
return val
}
func mustB(val pragmastat.Bounds, err error) pragmastat.Bounds {
if err != nil {
log.Fatal(err)
}
return val
}
func mustS(val *pragmastat.Sample, err error) *pragmastat.Sample {
if err != nil {
log.Fatal(err)
}
return val
}
func mustT(val *pragmastat.Threshold, err error) *pragmastat.Threshold {
if err != nil {
log.Fatal(err)
}
return val
}
func mustP(val []pragmastat.Projection, err error) []pragmastat.Projection {
if err != nil {
log.Fatal(err)
}
return val
}
func main() {
// --- One-Sample ---
xVals := make([]float64, 200)
for i := range xVals {
xVals[i] = float64(i + 1)
}
x := mustS(pragmastat.NewSample(xVals))
fmt.Println(mustM(x.Center()).Value) // 100.5
fmt.Println(mustB(x.CenterBounds(1e-3))) // [86;115]
fmt.Println(mustM(x.Spread()).Value) // 59
fmt.Println(mustB(x.SpreadBoundsWithSeed(1e-3, "demo"))) // [44;87]
// --- Two-Sample ---
sxVals := make([]float64, 200)
for i := range sxVals {
sxVals[i] = float64(i + 1)
}
syVals := make([]float64, 200)
for i := range syVals {
syVals[i] = float64(i + 101)
}
sx := mustS(pragmastat.NewSample(sxVals))
sy := mustS(pragmastat.NewSample(syVals))
fmt.Println(mustM(sx.Shift(sy)).Value) // -100
fmt.Println(mustB(sx.ShiftBounds(sy, 1e-3))) // [-120;-80]
fmt.Println(mustM(sx.Ratio(sy)).Value) // 0.5008354224706336
fmt.Println(mustB(sx.RatioBounds(sy, 1e-3))) // [0.4066666666666668;0.5958333333333332]
fmt.Println(mustM(sx.Disparity(sy)).Value) // -1.694915254237288
fmt.Println(mustB(sx.DisparityBoundsWithSeed(sy, 1e-3, "demo"))) // [-3.1025641025641026;-0.8494623655913979]
// --- Confirmatory Comparison ---
th1 := mustT(pragmastat.NewThreshold(pragmastat.MetricCenter, pragmastat.NewNumberMeasurement(50), 1e-3))
proj1 := mustP(pragmastat.Compare1(sx, []*pragmastat.Threshold{th1}))
fmt.Println(proj1[0].Verdict) // greater
th2 := mustT(pragmastat.NewThreshold(pragmastat.MetricShift, pragmastat.NewNumberMeasurement(0), 1e-3))
proj2 := mustP(pragmastat.Compare2(sx, sy, []*pragmastat.Threshold{th2}))
fmt.Println(proj2[0].Verdict) // less
// --- Randomization ---
rng := pragmastat.NewRngFromString("demo-uniform")
fmt.Println(rng.UniformFloat64()) // 0.2640554428629759
fmt.Println(rng.UniformFloat64()) // 0.9348534835582796
rng = pragmastat.NewRngFromString("demo-uniform-int")
fmt.Println(rng.UniformInt64(0, 100)) // 41
rng = pragmastat.NewRngFromString("demo-sample")
fmt.Println(pragmastat.RngSample(rng, []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 3)) // [3 8 9]
rng = pragmastat.NewRngFromString("demo-resample")
fmt.Println(pragmastat.RngResample(rng, []float64{1, 2, 3, 4, 5}, 7)) // [3 1 3 2 4 1 2]
rng = pragmastat.NewRngFromString("demo-shuffle")
fmt.Println(pragmastat.RngShuffle(rng, []float64{1, 2, 3, 4, 5})) // [4 2 3 5 1]
// --- Distributions ---
rng = pragmastat.NewRngFromString("demo-dist-additive")
fmt.Println(pragmastat.NewAdditive(0, 1).Sample(rng)) // 0.1741044867956819
rng = pragmastat.NewRngFromString("demo-dist-multiplic")
fmt.Println(pragmastat.NewMultiplic(0, 1).Sample(rng)) // 1.1273244602673853
rng = pragmastat.NewRngFromString("demo-dist-exp")
fmt.Println(pragmastat.NewExp(1).Sample(rng)) // 0.6589065267276553
rng = pragmastat.NewRngFromString("demo-dist-power")
fmt.Println(pragmastat.NewPower(1, 2).Sample(rng)) // 1.023677535537084
rng = pragmastat.NewRngFromString("demo-dist-uniform")
fmt.Println(pragmastat.NewUniform(0, 10).Sample(rng)) // 6.54043657816832
}
```
--------------------------------
### Initialize and sample from a Power distribution
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/dist_power.Rd
Creates a Pareto distribution object and generates a sample using a random number generator.
```R
r <- rng("demo-dist-power")
dist <- dist_power(1, 2)
dist$sample(r)
```
--------------------------------
### Execute tests via CLI
Source: https://github.com/andreyakinshin/pragmastat/blob/main/cs/AGENTS.md
Run the test suite using either the mise task runner or the standard dotnet CLI.
```bash
mise run cs:test # All tests (preferred)
dotnet test # All tests (raw)
```
--------------------------------
### Pragmastat Library Usage Demo
Source: https://github.com/andreyakinshin/pragmastat/blob/main/cs/README.md
Demonstrates core functionality including sample statistics, confirmatory comparisons, random number generation, and probability distributions.
```cs
using static System.Console;
using Pragmastat.Distributions;
using Pragmastat.Metrology;
using Pragmastat.Randomization;
namespace Pragmastat.Demo;
class Program
{
static void Main()
{
// --- One-Sample ---
var x = new Sample(Enumerable.Range(1, 200).Select(i => (double)i).ToArray());
WriteLine(x.Center()); // 100.5
WriteLine(x.CenterBounds()); // [86;115]
WriteLine(x.Spread()); // 59
WriteLine(x.SpreadBounds(1e-3, "demo")); // [44;87]
// --- Two-Sample ---
x = new Sample(Enumerable.Range(1, 200).Select(i => (double)i).ToArray());
var y = new Sample(Enumerable.Range(101, 200).Select(i => (double)i).ToArray());
WriteLine(x.Shift(y)); // -100
WriteLine(x.ShiftBounds(y)); // [-120;-80]
WriteLine(x.Ratio(y)); // 0.5008354224706334
WriteLine(x.RatioBounds(y)); // [0.4066666666666668;0.5958333333333332]
WriteLine(x.Disparity(y)); // -1.694915254237288
WriteLine(x.DisparityBounds(y, 1e-3, "demo")); // [-3.1025641025641026;-0.8494623655913979]
// --- Confirmatory Comparison ---
WriteLine(Toolkit.Compare1(x, [new Threshold(Metric.Center, new Measurement(50, MeasurementUnit.Number), 1e-3)])[0].Verdict.ToId()); // greater
WriteLine(Toolkit.Compare2(x, y, [new Threshold(Metric.Shift, new Measurement(0, MeasurementUnit.Number), 1e-3)])[0].Verdict.ToId()); // less
// --- Randomization ---
var rng = new Rng("demo-uniform");
WriteLine(rng.UniformDouble()); // 0.2640554428629759
WriteLine(rng.UniformDouble()); // 0.9348534835582796
rng = new Rng("demo-uniform-int");
WriteLine(rng.UniformInt32(0, 100)); // 41
rng = new Rng("demo-sample");
WriteLine(string.Join(", ", rng.Sample([0.0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3))); // 3, 8, 9
rng = new Rng("demo-resample");
WriteLine(string.Join(", ", rng.Resample([1.0, 2, 3, 4, 5], 7))); // 3, 1, 3, 2, 4, 1, 2
rng = new Rng("demo-shuffle");
WriteLine(string.Join(", ", rng.Shuffle([1.0, 2, 3, 4, 5]))); // 4, 2, 3, 5, 1
// --- Distributions ---
rng = new Rng("demo-dist-additive");
WriteLine(new Additive(0, 1).Sample(rng)); // 0.17410448679568188
rng = new Rng("demo-dist-multiplic");
WriteLine(new Multiplic(0, 1).Sample(rng)); // 1.1273244602673853
rng = new Rng("demo-dist-exp");
WriteLine(new Exp(1).Sample(rng)); // 0.6589065267276553
rng = new Rng("demo-dist-power");
WriteLine(new Power(1, 2).Sample(rng)); // 1.023677535537084
rng = new Rng("demo-dist-uniform");
WriteLine(new Uniform(0, 10).Sample(rng)); // 6.54043657816832
}
}
```
--------------------------------
### Initialize and use Bounds class
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Bounds.Rd
Demonstrates creating a new Bounds object and using its fields and the contains method.
```R
b <- Bounds$new(1.5, 4.5)
b$lower # 1.5
b$upper # 4.5
b$contains(3) # TRUE
b$contains(5) # FALSE
```
--------------------------------
### Scalar Arithmetic on Sample
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/Sample.Rd
Illustrates applying scalar multiplication to a Sample object.
```R
# Scalar arithmetic
x2 <- x * 0.001 # scale values
```
--------------------------------
### Running Test Suites
Source: https://github.com/andreyakinshin/pragmastat/blob/main/py/AGENTS.md
Execute project tests using mise or pytest. Use specific file paths to run subsets of the test suite.
```bash
mise run py:test # All tests (preferred)
pytest tests/ # All tests (raw)
pytest tests/test_reference.py # Reference tests only
```
--------------------------------
### Execute build tasks with mise
Source: https://github.com/andreyakinshin/pragmastat/blob/main/AGENTS.md
Use mise to manage project tasks and CI workflows across supported languages.
```bash
mise tasks # List all available tasks
mise run :ci # Full CI for one language (cs, go, kt, py, r, rs, ts)
mise run ci # Full CI for all languages
```
--------------------------------
### Create and sample from a uniform distribution
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/dist_uniform.Rd
Initializes a uniform distribution between 0 and 10 and generates a sample using a demo random number generator.
```R
r <- rng("demo-dist-uniform")
dist <- dist_uniform(0, 10)
dist$sample(r)
```
--------------------------------
### Initialize and query a standard unit registry
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/pragmastat/man/standard_registry.Rd
Creates a registry instance and resolves the full names of the three standard units.
```R
reg <- standard_registry()
reg$resolve("number")$full_name # "Number"
reg$resolve("ratio")$full_name # "Ratio"
reg$resolve("disparity")$full_name # "Disparity"
```
--------------------------------
### Run All Language CIs
Source: https://github.com/andreyakinshin/pragmastat/blob/main/tests/README.md
Triggers the CI process for all supported languages to verify test suites.
```bash
mise run ci
```
--------------------------------
### Pragmastat Library Usage Demo
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/pragmastat/README.md
Demonstrates core functionality including sample statistics, hypothesis testing, random number generation, distribution sampling, and unit conversion.
```rust
use pragmastat::distributions::{Additive, Distribution, Exp, Multiplic, Power, Uniform};
use pragmastat::*;
fn main() {
// --- One-Sample (Sample-based API) ---
let x = Sample::new((1..=200).map(|i| i as f64).collect()).unwrap();
println!("{}", center(&x).unwrap().value); // 100.5
let bounds = center_bounds(&x, 1e-3).unwrap();
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper); // {lower: 86, upper: 115}
println!("{}", spread(&x).unwrap().value); // 59
let bounds = spread_bounds_with_seed(&x, 1e-3, "demo").unwrap();
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper); // {lower: 44, upper: 87}
// --- Two-Sample (Sample-based API) ---
let x = Sample::new((1..=200).map(|i| i as f64).collect()).unwrap();
let y = Sample::new((101..=300).map(|i| i as f64).collect()).unwrap();
println!("{}", shift(&x, &y).unwrap().value); // -100
let bounds = shift_bounds(&x, &y, 1e-3).unwrap();
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper); // {lower: -120, upper: -80}
println!("{}", ratio(&x, &y).unwrap().value); // 0.5008354224706334
let bounds = ratio_bounds(&x, &y, 1e-3).unwrap();
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper); // {lower: 0.4066666666666668, upper: 0.5958333333333332}
println!("{}", disparity(&x, &y).unwrap().value); // -1.694915254237288
let bounds = disparity_bounds_with_seed(&x, &y, 1e-3, "demo").unwrap();
println!("{{lower: {}, upper: {}}}", bounds.lower, bounds.upper); // {lower: -3.1025641025641026, upper: -0.8494623655913979}
// --- Confirmatory Comparison ---
let th = Threshold::new(Metric::Center, Measurement::number(50.0), 1e-3).unwrap();
println!("{}", compare1(&x, &[th]).unwrap()[0].verdict().as_str()); // greater
let th = Threshold::new(Metric::Shift, Measurement::number(0.0), 1e-3).unwrap();
println!("{}", compare2(&x, &y, &[th]).unwrap()[0].verdict().as_str()); // less
// --- Randomization ---
let mut rng = Rng::from_string("demo-uniform");
println!("{}", rng.uniform_f64()); // 0.2640554428629759
println!("{}", rng.uniform_f64()); // 0.9348534835582796
let mut rng = Rng::from_string("demo-uniform-int");
println!("{}", rng.uniform_i64(0, 100)); // 41
let mut rng = Rng::from_string("demo-sample");
println!(
"{:?}",
rng.sample(&[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], 3)
); // [3.0, 8.0, 9.0]
let mut rng = Rng::from_string("demo-resample");
println!("{:?}", rng.resample(&[1.0, 2.0, 3.0, 4.0, 5.0], 7)); // [3.0, 1.0, 3.0, 2.0, 4.0, 1.0, 2.0]
let mut rng = Rng::from_string("demo-shuffle");
println!("{:?}", rng.shuffle(&[1.0, 2.0, 3.0, 4.0, 5.0])); // [4.0, 2.0, 3.0, 5.0, 1.0]
// --- Distributions ---
let mut rng = Rng::from_string("demo-dist-additive");
println!("{}", Additive::new(0.0, 1.0).sample(&mut rng)); // 0.17410448679568188
let mut rng = Rng::from_string("demo-dist-multiplic");
println!("{}", Multiplic::new(0.0, 1.0).sample(&mut rng)); // 1.1273244602673853
let mut rng = Rng::from_string("demo-dist-exp");
println!("{}", Exp::new(1.0).sample(&mut rng)); // 0.6589065267276553
let mut rng = Rng::from_string("demo-dist-power");
println!("{}", Power::new(1.0, 2.0).sample(&mut rng)); // 1.023677535537084
let mut rng = Rng::from_string("demo-dist-uniform");
println!("{}", Uniform::new(0.0, 10.0).sample(&mut rng)); // 6.54043657816832
// --- Unit system ---
let ms = MeasurementUnit::new("ms", "Time", "ms", "Millisecond", 1_000_000);
let ns = MeasurementUnit::new("ns", "Time", "ns", "Nanosecond", 1);
let s = Sample::with_unit(vec![1.0, 2.0, 3.0], ms).unwrap();
let converted = s.convert_to(&ns).unwrap();
println!("Converted: {:?}", converted.values()); // [1000000.0, 2000000.0, 3000000.0]
let registry = UnitRegistry::standard();
let unit = registry.resolve("number").unwrap();
println!("Resolved: {}", unit.full_name()); // Number
}
```
--------------------------------
### Define a test file structure
Source: https://github.com/andreyakinshin/pragmastat/blob/main/tests/README.md
The base structure for all test files, requiring input and output fields.
```json
{
"input": { ... },
"output": ...
}
```
--------------------------------
### Repository directory structure
Source: https://github.com/andreyakinshin/pragmastat/blob/main/AGENTS.md
Overview of the project file organization.
```text
pragmastat/
├── cs/, go/, kt/, py/, r/, rs/, ts/ # Language implementations
├── manual/ # Source content (Typst)
│ └── definitions.typ # Shared definitions and version
├── tests/ # Cross-language test data (JSON)
├── tools/ # Rust CLI for content generation
├── img/ # Source images (_light/_dark variants)
├── web/ # Generated web output (Astro)
├── sim/ # Simulation output data
├── VERSION # Single version source
├── CITATION.cff # Citation metadata
└── mise.toml # Build configuration
```
--------------------------------
### Run CI linting checks
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/AGENTS.md
Executes the standard suite of linting and formatting checks using mise.
```bash
mise run rs:check
```
--------------------------------
### Run TypeScript Build Commands
Source: https://github.com/andreyakinshin/pragmastat/blob/main/ts/AGENTS.md
Use these commands via mise to manage the build, test, and linting lifecycle of the TypeScript project.
```bash
mise run ts:ci # Full CI: clean → restore → check → build → test
mise run ts:test # Run tests only
mise run ts:check # Lint (ESLint) + format check (Prettier)
mise run ts:check:fix # Auto-format code
mise run ts:demo # Run demo with ts-node
mise run ts:build # Compile TypeScript
mise run ts:coverage # Run tests with coverage
mise run ts:pack # Create npm tarball
```
--------------------------------
### Build Commands for R Package
Source: https://github.com/andreyakinshin/pragmastat/blob/main/r/AGENTS.md
Commands to manage the R package lifecycle, including testing, building, and documentation generation.
```bash
mise run r:ci # Full CI: clean → restore → check → build → test
mise run r:test # Run tests only
mise run r:check # R CMD check (no tests, no dependencies)
mise run r:check:fix # Format with styler
mise run r:demo # Run demo
mise run r:build # Build source package (.tar.gz)
mise run r:restore # Install package locally
mise run r:doc # Build documentation with roxygen2
```
--------------------------------
### Typed Sample API
Source: https://github.com/andreyakinshin/pragmastat/blob/main/rs/AGENTS.md
Recommended primary interface that accepts &Sample and returns unit-carrying Measurement or Bounds types.
```rust
pub fn center(x: &Sample) -> Result
pub fn spread(x: &Sample) -> Result
pub fn shift(x: &Sample, y: &Sample) -> Result
pub fn ratio(x: &Sample, y: &Sample) -> Result
pub fn disparity(x: &Sample, y: &Sample) -> Result
pub fn shift_bounds(x: &Sample, y: &Sample, misrate: f64) -> Result
pub fn ratio_bounds(x: &Sample, y: &Sample, misrate: f64) -> Result
pub fn disparity_bounds(x: &Sample, y: &Sample, misrate: f64) -> Result
pub fn center_bounds(x: &Sample, misrate: f64) -> Result
pub fn spread_bounds(x: &Sample, misrate: f64) -> Result
pub fn spread_bounds_with_seed(x: &Sample, misrate: f64, seed: &str) -> Result
pub fn disparity_bounds_with_seed(x: &Sample, y: &Sample, misrate: f64, seed: &str) -> Result
```