scirs2-stats
Production-ready statistical functions module for the SciRS2 ecosystem (v0.1.0), providing comprehensive statistical computing capabilities modeled after SciPy's stats module but optimized for Rust's performance and safety guarantees. Following the SciRS2 POLICY, this module ensures ecosystem consistency through scirs2-core abstractions.
Overview
SciRS2-stats is a mature, production-ready statistical computing library that provides:
- High-performance statistical algorithms optimized for Rust's memory safety and concurrency
- Comprehensive API compatibility with SciPy's stats module for easy migration
- Zero-copy operations where possible for maximum performance
- Thread-safe implementations leveraging Rust's ownership system
- Extensive test coverage with 280+ tests ensuring reliability
Features
- Descriptive statistics
- Basic measures: mean, median, variance, standard deviation
- Advanced statistics: skewness, kurtosis, moments
- Correlation measures: Pearson, Spearman, Kendall tau, partial correlation, point-biserial
- Dispersion measures: MAD, median absolute deviation, IQR, range, coefficient of variation
- Statistical distributions
- Continuous: Normal, Uniform, Student's t, Chi-square, F, Gamma, Beta, Exponential, Laplace, Logistic, Cauchy, Pareto, Weibull
- Discrete: Poisson, Binomial, Hypergeometric, Bernoulli, Geometric, Negative Binomial
- Multivariate: Multivariate Normal, Multivariate t, Dirichlet, Wishart, InverseWishart, Multinomial
- Statistical tests
- Parametric tests: t-tests (one-sample, two-sample, paired), ANOVA
- Non-parametric tests: Mann-Whitney U, Wilcoxon signed-rank, Kruskal-Wallis, Friedman
- Normality tests: Shapiro-Wilk, Anderson-Darling, D'Agostino's K²
- Goodness-of-fit tests: Chi-square, Kolmogorov-Smirnov
- Random number generation
- Regression models
- Linear, polynomial, and stepwise regression
- Robust regression methods (RANSAC, Huber, Theil-Sen)
- Regularized models (Ridge, Lasso, Elastic Net)
- Sampling techniques (bootstrap, stratified sampling)
- Contingency table functions
Installation
Add scirs2-stats to your Cargo.toml:
[]
= "0.1.0"
= "0.16.1"
This version represents Stable Release before the stable 1.0 release, offering production-ready functionality with a stable API and zero-warning code quality.
Requirements
Usage Examples
Descriptive Statistics
use array;
use ;
let data = array!;
// Calculate basic statistics
let mean_val = mean.unwrap;
let median_val = median.unwrap;
let var_val = var.unwrap; // ddof = 0 for population variance
let std_val = std.unwrap; // ddof = 0 for population standard deviation
// Advanced statistics
let skewness = skew.unwrap; // bias = false
let kurt = kurtosis.unwrap; // fisher = true, bias = false
Statistical Distributions
use distributions;
// Normal distribution
let normal = norm.unwrap;
let pdf = normal.pdf;
let cdf = normal.cdf;
let samples = normal.rvs.unwrap;
// Poisson distribution
let poisson = poisson.unwrap;
let pmf = poisson.pmf;
let cdf = poisson.cdf;
let samples = poisson.rvs.unwrap;
Correlation Measures
use ;
use ;
// Calculate Pearson correlation coefficient (linear correlation)
let x = array!;
let y = array!;
let r = pearson_r.unwrap;
println!; // Should be -1.0 (perfect negative correlation)
// Spearman rank correlation (monotonic relationship)
let rho = spearman_r.unwrap;
println!;
// Kendall tau rank correlation
let tau = kendall_tau.unwrap;
println!;
// Correlation matrix for multiple variables
let data = array!;
let corr_matrix = corrcoef.unwrap;
println!;
Dispersion Measures
use array;
use ;
let data = array!; // Note the outlier
// Mean absolute deviation (from mean)
let mad = mean_abs_deviation.unwrap;
println!;
// Median absolute deviation (robust to outliers)
let median_ad = median_abs_deviation.unwrap;
println!;
// Scaled median absolute deviation (to match std. dev. in normal distributions)
let scaled_mad = median_abs_deviation.unwrap;
println!;
// Interquartile range (Q3 - Q1)
let iqr_val = iqr.unwrap;
println!;
// Range (max - min)
let range_val = data_range.unwrap;
println!;
// Coefficient of variation (std/mean)
let cv = coef_variation.unwrap; // 1 = sample
println!;
Statistical Tests
use ;
use ;
// Parametric tests
let data = array!;
let = ttest_1samp.unwrap;
println!;
let group1 = array!;
let group2 = array!;
let = ttest_ind.unwrap;
println!;
// Normality tests
let = shapiro_wilk.unwrap;
println!;
let = anderson_darling.unwrap;
println!;
// Non-parametric tests
let before = array!;
let after = array!;
let = wilcoxon.unwrap;
println!;
// Kruskal-Wallis test for independent samples
let group3 = array!;
let samples = vec!;
let = kruskal_wallis.unwrap;
println!;
// Friedman test for repeated measures
let repeated_data = array!;
let = friedman.unwrap;
println!;
Random Number Generation
use ;
use array;
// Generate uniform random numbers between 0 and 1
let uniform_samples = uniform.unwrap;
// Generate standard normal random numbers
let normal_samples = randn.unwrap;
// Generate random integers between 1 and 100
let int_samples = randint.unwrap;
// Randomly choose elements from an array
let options = array!;
let choices = choice.unwrap;
Statistical Sampling
use sampling;
use array;
// Create an array
let data = array!;
// Generate bootstrap samples
let bootstrap_samples = bootstrap.unwrap;
// Generate a random permutation
let permutation = permutation.unwrap;
Production Readiness
This release (0.1.0) represents a production-ready state with:
- ✅ Comprehensive functionality: All core statistical operations implemented
- ✅ Extensive testing: 280+ tests with 99.6% pass rate
- ✅ API stability: Stable public API ready for production use
- ✅ Performance optimized: Benchmarked against SciPy for competitive performance
- ✅ Memory safe: Leverages Rust's ownership system for memory safety
- ✅ Documentation complete: Comprehensive API documentation with examples
Roadmap to 1.0
The next major release (1.0.0) will focus on:
- API stabilization and final polish
- Additional optimization passes
- Extended integration testing
- Performance benchmarking suite
License
This project is dual-licensed under:
You can choose to use either license. See the LICENSE file for details.
See Also
Check the TODO.md file for future enhancements and development roadmap.