pub fn fit_low_level_regression_model(
    data_row_major: &[f64],
    num_rows: usize,
    num_columns: usize
) -> Result<LowLevelRegressionModel, Error>
Expand description

Fit a regression model directly on a matrix of input data

Expects a matrix in the format

regressandinterceptregressor 1regressor 2
value1.0valuevalue

in row major order.

Note

  • The matrix should already contain the intercept column consisting of only the value 1.0.
  • No validation of the data is performed, except for a simple dimension consistency check.

Example

use linregress::{fit_low_level_regression_model, assert_slices_almost_eq};

let data_row_major: Vec<f64> = vec![
    1., 1.0, 1., 7.,
    3., 1.0, 2., 6.,
    4., 1.0, 3., 5.,
    5., 1.0, 4., 4.,
    2., 1.0, 5., 3.,
    3., 1.0, 6., 2.,
    4., 1.0, 7., 1.,
];
let model = fit_low_level_regression_model(&data_row_major, 7, 4)?;
let params = [
    0.09523809523809518f64,
    0.5059523809523807,
    0.2559523809523811,
];
assert_slices_almost_eq!(model.parameters(), &params);