rs-stats
A comprehensive statistical library written in Rust, providing powerful tools for probability, distributions, and hypothesis testing.
rs-stats offers a broad range of statistical functionality implemented in pure Rust. It's designed to be intuitive, efficient, and reliable for both simple and complex statistical analysis. The library aims to provide a comprehensive set of tools for data scientists, researchers, and developers working with statistical models.
Features
-
Probability Functions
- Error functions (erf, erfc)
- Cumulative distribution functions
- Probability density functions
- Z-scores
- Basic statistics (mean, variance, standard deviation, standard error)
-
Statistical Distributions
- Normal (Gaussian) distribution
- Binomial distribution
- Exponential distribution
- Poisson distribution
- Uniform distribution
-
Regression Analysis
- Linear Regression (fit, predict, confidence intervals)
- Multiple Linear Regression (multiple predictor variables)
- Model statistics (R², adjusted R², standard error)
- Model persistence (save/load models in JSON or binary format)
-
Hypothesis Testing
- ANOVA (Analysis of Variance)
- Chi-square tests (independence and goodness of fit)
- T-tests (one-sample, two-sample, paired)
Installation
Add rs-stats to your Cargo.toml:
[]
= "1.2.0"
Or use cargo add:
Usage Examples
Basic Statistical Functions
use ;
Working with Distributions
use ;
Hypothesis Testing
use ;
use ;
use one_way_anova;
Regression Analysis
use LinearRegression;
use MultipleLinearRegression;
Decision Trees
use ;
// Example 1: Regression Tree for Patient Recovery Time Prediction
let mut recovery_time_tree = new;
// Training data: [age, treatment_intensity, bmi, comorbidity_score, initial_severity]
let patient_features = vec!;
let recovery_days = vec!; // Recovery time in days
// Train the model to predict recovery time
recovery_time_tree.fit;
// Make predictions for a new patient
let new_patient = vec!;
let predicted_recovery_days = recovery_time_tree.predict;
// Example 2: Classification Tree for Diabetes Risk Assessment
let mut diabetes_risk_tree = new;
// Training data: [glucose_level, bmi, blood_pressure, age, family_history]
let medical_features = vec!;
let diabetes_status = vec!; // 0: No diabetes, 1: Diabetes
// Train the classifier
diabetes_risk_tree.fit;
// Print tree structure and summary
println!;
println!;
// Feature importance - which medical measurements are most predictive
let importance = diabetes_risk_tree.feature_importances;
println!;
The Decision Tree implementation supports:
- Both regression and classification tasks
- Multiple split criteria (MSE, MAE for regression; Gini, Entropy for classification)
- Generic types with appropriate trait bounds
- Parallel processing for optimal performance
- Tree visualization and interpretation tools
- Feature importance calculation
Documentation
For detailed API documentation, run:
Testing
The library includes a comprehensive test suite. Run the tests with:
Contributing
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/my-new-feature - Submit a pull request
Before submitting your PR, please make sure:
- All tests pass
- Code follows the project's style and conventions
- New features include appropriate documentation and tests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- The Rust community for their excellent documentation and support
- Contributors to the project
- Various statistical references and research papers that informed the implementations