Expand description
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 an R-style formula or a list of columns to use.
Currently only very simple formulae are supported,
see FormulaRegressionBuilder.formula
for details.
§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", -1.0000000000000004),
("X2", 1.5508427875232655e-15),
("X3", -1.4502288259166107e-15),
]
);
assert_eq!(
standard_errors,
vec![
("X1", 9.22799842631787e-13),
("X2", 4.184801029355531e-15),
("X3", 2.5552590991720465e-15),
]
);
assert_eq!(
pvalues,
vec![
("X1", 5.874726257570879e-13),
("X2", 0.7740647742008093),
("X3", 0.6713674042015161),
]
);
Macros§
- Only exposed for use in doc comments. This macro is not considered part of this crate’s stable API.
- Only exposed for use in doc comments. This macro is not considered part of this crate’s stable API.
Structs§
- A builder to create and fit a linear regression model.
- A fitted regression model
- A container struct for the regression data.
- A builder to create a RegressionData struct for use with a
FormulaRegressionBuilder
. - A fitted regression model.
Enums§
- An error that can occur in this crate.
- How to proceed if given non real
f64
values (NaN or infinity or negative infinity).
Functions§
- Fit a regression model directly on a matrix of input data
- Like
fit_low_level_regression_model
but does not compute any statistics after fitting the model.