[−][src]Struct linregress::FormulaRegressionBuilder
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, 5.0); assert_eq!(model.parameters.regressor_values[0], -0.9999999999999993); assert_eq!(model.parameters.regressor_names[0], "X");
Methods
impl<'a> FormulaRegressionBuilder<'a>
[src]
pub fn new() -> Self
[src]
Create as new FormulaRegressionBuilder with no data or formula set.
pub fn data(self, data: &'a RegressionData<'a>) -> Self
[src]
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.
pub fn formula<T: Into<Cow<'a, str>>>(self, formula: T) -> Self
[src]
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.
pub fn fit(self) -> Result<RegressionModel, Error>
[src]
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.
Trait Implementations
impl<'a> Default for FormulaRegressionBuilder<'a>
[src]
impl<'a> Clone for FormulaRegressionBuilder<'a>
[src]
fn clone(&self) -> FormulaRegressionBuilder<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> Debug for FormulaRegressionBuilder<'a>
[src]
Auto Trait Implementations
impl<'a> Send for FormulaRegressionBuilder<'a>
impl<'a> Sync for FormulaRegressionBuilder<'a>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,