Expand description
Linear Regression Library with WASM bindings.
This library provides Ordinary Least Squares (OLS) regression and
statistical diagnostic tests. When the wasm feature is enabled,
it exposes JavaScript bindings for use in web browsers.
§Features
- OLS regression with QR decomposition for numerical stability
- Comprehensive diagnostic tests (Rainbow, Harvey-Collier, Breusch-Pagan, White, Jarque-Bera, Durbin-Watson, Shapiro-Wilk, Anderson-Darling)
- Variance Inflation Factor (VIF) analysis
- Custom implementations of all linear algebra and statistical functions
§Module Structure
core- OLS regression implementationdiagnostics- Statistical diagnostic testsdistributions- Statistical distributions (t, F, chi-squared, normal)linalg- Matrix operations and QR decompositionerror- Error types
§WASM API
When the wasm feature is enabled, the library exposes JavaScript bindings that
accept and return JSON strings for easy integration. By default, all domains are
allowed. To restrict usage to specific domains, set the LINREG_DOMAIN_RESTRICT
environment variable at build time:
LINREG_DOMAIN_RESTRICT=example.com,mysite.com wasm-pack build§Example (Native Rust)
use linreg_core::core::ols_regression;
use linreg_core::Error;
let y = vec![2.5, 3.7, 4.2, 5.1, 6.3, 7.0];
let x1 = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let x2 = vec![2.0, 4.0, 5.0, 4.0, 3.0, 2.0];
let names = vec![
"Intercept".to_string(),
"Temperature".to_string(),
"Pressure".to_string(),
];
let result = ols_regression(&y, &[x1, x2], &names)?;
println!("R²: {}", result.r_squared);Re-exports§
pub use core::RegressionOutput;pub use core::VifResult;pub use diagnostics::DiagnosticTestResult;pub use diagnostics::RainbowTestOutput;pub use diagnostics::RainbowSingleResult;pub use diagnostics::RainbowMethod;pub use diagnostics::WhiteTestOutput;pub use diagnostics::WhiteSingleResult;pub use diagnostics::WhiteMethod;pub use diagnostics::CooksDistanceResult;pub use diagnostics::rainbow_test as rainbow_test_core;pub use diagnostics::white_test as white_test_core;pub use error::Error;pub use error::Result;pub use error::error_json;pub use error::error_to_json;
Modules§
- core
- Core OLS regression implementation.
- diagnostics
- distributions
- Custom implementation of statistical distributions to replace statrs dependency. Includes Log Gamma, Incomplete Beta, Incomplete Gamma, Student’s T, F-distribution, Chi-Squared, and Normal distribution functions.
- error
- Error types for the linear regression library.
- linalg
- Minimal Linear Algebra module to replace nalgebra dependency.
Functions§
- anderson_
darling_ test - Performs the Anderson-Darling test for normality via WASM.
- breusch_
pagan_ test - Performs the Breusch-Pagan test for heteroscedasticity via WASM.
- cooks_
distance_ test - Computes Cook’s distance for identifying influential observations via WASM.
- durbin_
watson_ test - Performs the Durbin-Watson test for autocorrelation via WASM.
- get_
normal_ inverse - Computes the inverse of the standard normal CDF (probit function).
- get_
t_ cdf - Computes the Student’s t-distribution cumulative distribution function.
- get_
t_ critical - Computes the critical t-value for a given significance level.
- get_
version - Returns the current version of the library.
- harvey_
collier_ test - Performs the Harvey-Collier test for linearity via WASM.
- jarque_
bera_ test - Performs the Jarque-Bera test for normality via WASM.
- ols_
regression - Performs OLS regression via WASM.
- parse_
csv - Parses CSV data and returns it as a JSON string.
- python_
white_ test - Performs the Python method White test for heteroscedasticity via WASM.
- r_
white_ test - Performs the R method White test for heteroscedasticity via WASM.
- rainbow_
test - Performs the Rainbow test for linearity via WASM.
- shapiro_
wilk_ test - Performs the Shapiro-Wilk test for normality via WASM.
- test
- Simple test function to verify WASM is working.
- test_ci
- Test function for confidence interval computation.
- test_
housing_ regression - Test function for regression validation against R reference values.
- test_
r_ accuracy - Test function for R accuracy validation.
- test_
t_ critical - Test function for t-critical value computation.
- white_
test - Performs the White test for heteroscedasticity via WASM.