### 20 releases

0.5.3 | Aug 29, 2023 |
---|---|

0.5.2 | Jul 4, 2023 |

0.5.1 | Feb 4, 2023 |

0.5.0 | Jul 12, 2022 |

0.1.3 | Mar 24, 2019 |

#**8** in Science

**139,704** downloads per month

Used in **279** crates
(5 directly)

**MIT**license

75KB

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

## License

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

### Third party software

The stats module contains code adapted from the statrs library, that is licensed under the MIT License. See LICENSE-THIRD-PARTY for details.

###
`lib.rs`

:

provides an easy to use implementation of ordinary
least squared linear regression with some basic statistics.
See `linregress`

for details.`RegressionModel`

The builder

is used to construct a model from a
table of data and an R-style formula or a list of columns to use.
Currently only very simple formulae are supported,
see `FormulaRegressionBuilder`

for details.`FormulaRegressionBuilder .formula`

# Example

`use` `linregress``::``{`FormulaRegressionBuilder`,` RegressionDataBuilder`}``;`
`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`:` `Vec``<``_``>` `=` model`.``iter_parameter_pairs``(``)``.``collect``(``)``;`
`let` pvalues`:` `Vec``<``_``>` `=` model`.``iter_p_value_pairs``(``)``.``collect``(``)``;`
`let` standard_errors`:` `Vec``<``_``>` `=` model`.``iter_se_pairs``(``)``.``collect``(``)``;`
`assert_eq!``(`
parameters`,`
`vec!``[`
`(``"`X1`"``,` `-``0.``9999999999999745``)``,`
`(``"`X2`"``,` `1.``5872719805187785e-15``)``,`
`(``"`X3`"``,` `-``1.``4246416546459528e-15``)``,`
`]`
`)``;`
`assert_eq!``(`
standard_errors`,`
`vec!``[`
`(``"`X1`"``,` `9.``799066977595267e-13``)``,`
`(``"`X2`"``,` `4.``443774660560714e-15``)``,`
`(``"`X3`"``,` `2.``713389610740135e-15``)``,`
`]`
`)``;`
`assert_eq!``(`
pvalues`,`
`vec!``[`
`(``"`X1`"``,` `6.``238279788691533e-13``)``,`
`(``"`X2`"``,` `0.``7815975465725482``)``,`
`(``"`X3`"``,` `0.``6922074604135647``)``,`
`]`
`)``;`

#### Dependencies

~3MB

~56K SLoC