# [−][src]Crate linreg

Linear regression

`linreg` calculates linear regressions for two dimensional measurements, also known as simple linear regression.

Base for all calculations of linear regression is the simple model found in https://en.wikipedia.org/wiki/Ordinary_least_squares#Simple_linear_regression_model.

## Example use

```   use linreg::{linear_regression, linear_regression_of};

// Example 1: x and y values stored in two different vectors
let xs: Vec<f64> = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let ys: Vec<f64> = vec![2.0, 4.0, 5.0, 4.0, 5.0];

assert_eq!(Ok((0.6, 2.2)), linear_regression(&xs, &ys));

// Example 2: x and y values stored as tuples
let tuples: Vec<(f32, f32)> = vec![(1.0, 2.0),
(2.0, 4.0),
(3.0, 5.0),
(4.0, 4.0),
(5.0, 5.0)];

assert_eq!(Ok((0.6, 2.2)), linear_regression_of(&tuples));

// Example 3: directly operating on integer (converted to float as required)
let xs: Vec<u8> = vec![1, 2, 3, 4, 5];
let ys: Vec<u8> = vec![2, 4, 5, 4, 5];

assert_eq!(Ok((0.6, 2.2)), linear_regression(&xs, &ys));```

## Enums

 Error The kinds of errors that can occur when calculating a linear regression.

## Functions

 lin_reg Calculates a linear regression with a known mean. lin_reg_imprecise Single-pass simple linear regression. linear_regression Two-pass simple linear regression from slices. linear_regression_of Two-pass linear regression from tuples.