Crate linregress
source · [−]Expand description
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};
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),
]
);
Structs
A builder to create and fit a linear 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.
A parameter of a fitted RegressionModel
given for the intercept and each regressor.
Enums
An error that can occur in this crate.
How to proceed if given non real f64
values (NaN or infinity or negative infinity).