#statistics #regression #ols

linregress

ordinary least squared linear regression with some basic statistics

12 releases

0.4.1 Apr 9, 2021
0.4.0 Jul 20, 2020
0.3.0 May 14, 2020
0.1.7 Nov 29, 2019
0.1.3 Mar 24, 2019

#35 in Algorithms

Download history 2929/week @ 2020-12-25 5393/week @ 2021-01-01 5832/week @ 2021-01-08 6141/week @ 2021-01-15 6160/week @ 2021-01-22 6179/week @ 2021-01-29 5810/week @ 2021-02-05 6657/week @ 2021-02-12 7756/week @ 2021-02-19 7890/week @ 2021-02-26 7240/week @ 2021-03-05 10169/week @ 2021-03-12 8505/week @ 2021-03-19 8174/week @ 2021-03-26 7223/week @ 2021-04-02 6351/week @ 2021-04-09

31,299 downloads per month
Used in 87 crates (3 directly)

MIT license

62KB
1.5K SLoC

linregress

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

Contact

Linregress has been developed by the Computational Systems Medicine group at the Chair of Experimental Bioinformatics. Contact:

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 linregress::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", -0.9999999999999745),
("X2", 0.00000000000000005637851296924623),
("X3", 0.00000000000000008283304597789254),
]
);
assert_eq!(
standard_errors.pairs(),
vec![
("X1", 0.00000000000019226371555402852),
("X2", 0.0000000000000008718958950659518),
("X3", 0.0000000000000005323837152041135),
]
);
assert_eq!(
pvalues.pairs(),
vec![
("X1", 0.00000000000012239888283055414),
("X2", 0.9588921357097694),
("X3", 0.9017368322742073),
]
);
# Ok(())
# }

Dependencies

~4MB
~82K SLoC