#statistics #regression #ols

linregress

ordinary least squared linear regression with some basic statistics

3 releases

✓ Uses Rust 2018 edition

0.1.2 Mar 11, 2019
0.1.1 Mar 11, 2019
0.1.0 Mar 11, 2019

#3 in #regression

Download history

4 downloads per month

MIT license

45KB
919 lines

linregress

A Rust library providing an easy to use implementation of ordinary least squared linear regression with some basic statistics.

Documentation

Full API documentation

License

This project is licensed under the MIT License. See LICENSE-MIT for details.

Third party software

The special functions module contains functions that are based on the C implementation in the Cephes library. They are considered a derivative of the Cephes library that is compatibly licensed. See LICENSE-THIRD-PARTY for details.


lib.rs:

Crate linregress provides an easy to use implementation of ordinary least squared linear regression with some basic statistics. See RegressionModel for details.

The builder FormulaRegressionBuilder is used to construct a model from a table of data and a R-style formula. Currently only very simple formulae are supported, see FormulaRegressionBuilder.formula for details.

Example

use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};

# use failure::Error;
# fn main() -> Result<(), Error> {
let y = vec![1.,2. ,3. , 4., 5.];
let x1 = vec![5., 4., 3., 2., 1.];
let x2 = vec![729.53, 439.0367, 42.054, 1., 0.];
let x3 = vec![258.589, 616.297, 215.061, 498.361, 0.];
let data = vec![("Y", y), ("X1", x1), ("X2", x2), ("X3", x3)];
let data = RegressionDataBuilder::new().build_from(data)?;
let formula = "Y ~ X1 + X2 + X3";
let model = FormulaRegressionBuilder::new()
.data(&data)
.formula(formula)
.fit()?;
let parameters = model.parameters;
let standard_errors = model.se;
let pvalues = model.pvalues;
assert_eq!(
parameters.pairs(),
vec![
("X1".to_string(), -0.9999999999999745),
("X2".to_string(), 0.00000000000000005637851296924623),
("X3".to_string(), 0.00000000000000008283304597789254),
]
);
assert_eq!(
standard_errors.pairs(),
vec![
("X1".to_string(), 0.00000000000019226371555402852),
("X2".to_string(), 0.0000000000000008718958950659518),
("X3".to_string(), 0.0000000000000005323837152041135),
]
);
assert_eq!(
pvalues.pairs(),
vec![
("X1".to_string(), 0.00000000000012239888283055414),
("X2".to_string(), 0.9588921357097694),
("X3".to_string(), 0.9017368322742073),
]
);
# Ok(())
# }

Dependencies

~4MB
~68K SLoC