# Ten days of statistics (9) - Linear Regression

## Least square regression line

Regression line is the straight line which best describes the relationship between 2 variables $X$ and $Y$. Formally

$Y = a+bX$

### Find the value of $b$

The value of $b$ can be calculated using either of the following:

\begin{align*} b &= \rho(X,Y) \frac{\sigma_Y}{\sigma_X} \\ b &= \frac{n\sum_{i=1}^n(x_iy_i) - \sum_{i=1}^n(x_i)\sum_{i=1}^n(y_i)}{n\sum_{i=1}^n(x^2_i) - (\sum_{i=1}^n(x_i))^2} \end{align*}

### Find the value of $a$

$a = \bar{y} - b\bar{x}$

Where $\bar{x}$ and $\bar{y}$ is the mean of $X$ and $Y$ respectively

## Practice

Hackerrank has an exercise for you to test your knowledge:

Next lesson: Multiple regression

That's all! Thank you for reading all the way here 😊

Made with love using Svelte, Three.js, TailwindCSS