Skip to main content

predict_multiple_intervals

Function predict_multiple_intervals 

Source
pub fn predict_multiple_intervals(
    model: &MultipleRegressionResult,
    predictors_new: &[&[f64]],
    level: f64,
) -> Option<Vec<RegressionPrediction>>
Expand description

Predictions of a multiple regression at the new points predictors_new (one slice per predictor, in the training order), each with the confidence interval of the mean response and the prediction interval of a new observation at two-sided level (Student’s t on n − p − 1 degrees of freedom).

Var(ŷ₀) = x₀’ V x₀, x₀ = (1, x₀₁, …, x₀ₚ) and V the coefficients’ covariance (MultipleRegressionResult::covariance).

§Returns

None when the predictor count differs from the model’s, the slices differ in length, a value is not finite, or level is not strictly between 0 and 1.

§References

Montgomery, Peck & Vining (2012). “Introduction to Linear Regression Analysis”, 5th edition, §3.4.

§Examples

use u_analytics::regression::{multiple_linear_regression, predict_multiple_intervals};

let x1 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
let x2 = [2.0, 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0];
let y = [5.1, 5.0, 9.2, 8.9, 13.1, 12.0, 17.2, 15.9];
let model = multiple_linear_regression(&[&x1, &x2], &y).unwrap();
let p = predict_multiple_intervals(&model, &[&[4.5], &[3.0]], 0.95).unwrap();
assert!(p[0].prediction_lower < p[0].fit && p[0].fit < p[0].prediction_upper);