pub struct RegressionModel { /* private fields */ }
Expand description

A fitted regression model.

Is the result of FormulaRegressionBuilder.fit().

Implementations

The names of the regressor columns

The two-tailed p-values for the t-statistics of the parameters

Iterates over pairs of regressor columns and their associated p-values

Note

This does not include the value for the intercept.

Usage
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};

let y = vec![1.,2. ,3. , 4.];
let x1 = vec![4., 3., 2., 1.];
let x2 = vec![1., 2., 3., 4.];
let data = vec![("Y", y), ("X1", x1), ("X2", x2)];
let data = RegressionDataBuilder::new().build_from(data)?;
let model = FormulaRegressionBuilder::new().data(&data).formula("Y ~ X1 + X2").fit()?;
let pairs: Vec<(&str, f64)> = model.iter_p_value_pairs().collect();
assert_eq!(pairs[0], ("X1", 1.7052707580549508e-28));
assert_eq!(pairs[1], ("X2", 2.522589878779506e-31));

The residuals of the model

The model’s intercept and slopes (also known as betas)

Iterates over pairs of regressor columns and their associated slope values

Note

This does not include the value for the intercept.

Usage
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};

let y = vec![1.,2. ,3. , 4.];
let x1 = vec![4., 3., 2., 1.];
let x2 = vec![1., 2., 3., 4.];
let data = vec![("Y", y), ("X1", x1), ("X2", x2)];
let data = RegressionDataBuilder::new().build_from(data)?;
let model = FormulaRegressionBuilder::new().data(&data).formula("Y ~ X1 + X2").fit()?;
let pairs: Vec<(&str, f64)> = model.iter_parameter_pairs().collect();
assert_eq!(pairs[0], ("X1", -0.03703703703703709));
assert_eq!(pairs[1], ("X2", 0.9629629629629626));

The standard errors of the parameter estimates

Iterates over pairs of regressor columns and their associated standard errors

Note

This does not include the value for the intercept.

Usage
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};

let y = vec![1.,2. ,3. , 4.];
let x1 = vec![4., 3., 2., 1.];
let x2 = vec![1., 2., 3., 4.];
let data = vec![("Y", y), ("X1", x1), ("X2", x2)];
let data = RegressionDataBuilder::new().build_from(data)?;
let model = FormulaRegressionBuilder::new().data(&data).formula("Y ~ X1 + X2").fit()?;
let pairs: Vec<(&str, f64)> = model.iter_parameter_pairs().collect();
assert_eq!(pairs[0], ("X1", -0.03703703703703709));
assert_eq!(pairs[1], ("X2", 0.9629629629629626));

Sum of squared residuals

R-squared of the model

Adjusted R-squared of the model

A scale factor for the covariance matrix

Note that the square root of scale is often called the standard error of the regression.

Evaluates the model on given new input data and returns the predicted values.

The new data is expected to have the same columns as the original data. See RegressionDataBuilder.build for details on the type of the new_data parameter.

Note

This function does no special handling of non real values (NaN or infinity or negative infinity). Such a value in new_data will result in a corresponding meaningless prediction.

Example
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).unwrap();
let formula = "Y ~ X1 + X2 + X3";
let model = FormulaRegressionBuilder::new()
    .data(&data)
    .formula(formula)
    .fit()?;
let new_data = vec![
    ("X1", vec![2.5, 3.5]),
    ("X2", vec![2.0, 8.0]),
    ("X3", vec![2.0, 1.0]),
];
let prediction: Vec<f64> = model.predict(new_data)?;
assert_slices_almost_eq!(&prediction, &[3.500000000000028, 2.5000000000000644]);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.