Struct linregress::FormulaRegressionBuilder
source · [−]pub struct FormulaRegressionBuilder<'a> { /* private fields */ }
Expand description
A builder to create and fit a linear regression model.
Given a dataset and a regression formula this builder will produce an ordinary least squared linear regression model.
See formula
and data
for details on how to configure this builder.
The pseudo inverse method is used to fit the model.
Usage
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};
let y = vec![1., 2. ,3., 4.];
let x = vec![4., 3., 2., 1.];
let data = vec![("Y", y), ("X", x)];
let data = RegressionDataBuilder::new().build_from(data)?;
let model = FormulaRegressionBuilder::new().data(&data).formula("Y ~ X").fit()?;
assert_eq!(model.parameters.intercept_value, 4.999999999999998);
assert_eq!(model.parameters.regressor_values[0], -0.9999999999999989);
assert_eq!(model.parameters.regressor_names[0], "X");
Implementations
sourceimpl<'a> FormulaRegressionBuilder<'a>
impl<'a> FormulaRegressionBuilder<'a>
sourcepub fn data(self, data: &'a RegressionData<'a>) -> Self
pub fn data(self, data: &'a RegressionData<'a>) -> Self
Set the data to be used for the regression.
The data has to be given as a reference to a RegressionData
struct.
See RegressionDataBuilder
for details.
sourcepub fn formula<T: Into<Cow<'a, str>>>(self, formula: T) -> Self
pub fn formula<T: Into<Cow<'a, str>>>(self, formula: T) -> Self
Set the formula to use for the regression.
The expected format is <regressand> ~ <regressor 1> + <regressor 2>
.
E.g. for a regressand named Y and three regressors named A, B and C
the correct format would be Y ~ A + B + C
.
Note that there is currently no special support for categorical variables.
So if you have a categorical variable with more than two distinct values
or values that are not 0
and 1
you will need to perform “dummy coding” yourself.
sourcepub fn fit(self) -> Result<RegressionModel, Error>
pub fn fit(self) -> Result<RegressionModel, Error>
Fits the model and returns a RegressionModel
if successful.
You need to set the data with data
and a formula with formula
before you can use it.
sourcepub fn fit_without_statistics(self) -> Result<RegressionParameters, Error>
pub fn fit_without_statistics(self) -> Result<RegressionParameters, Error>
Like fit
but does not perfom any statistics on the resulting model.
Returns a RegressionParameters
struct containing the model parameters
if successfull.
This is usefull if you do not care about the statistics or the model and data you want to fit result in too few residual degrees of freedom to perform statistics.
Trait Implementations
sourceimpl<'a> Clone for FormulaRegressionBuilder<'a>
impl<'a> Clone for FormulaRegressionBuilder<'a>
sourcefn clone(&self) -> FormulaRegressionBuilder<'a>
fn clone(&self) -> FormulaRegressionBuilder<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for FormulaRegressionBuilder<'a>
impl<'a> Debug for FormulaRegressionBuilder<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for FormulaRegressionBuilder<'a>
impl<'a> Send for FormulaRegressionBuilder<'a>
impl<'a> Sync for FormulaRegressionBuilder<'a>
impl<'a> Unpin for FormulaRegressionBuilder<'a>
impl<'a> UnwindSafe for FormulaRegressionBuilder<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
sourcepub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
sourcepub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
sourcepub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
sourcepub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more