# How do I perform linear regression on data?

Apr 22, 2018

You need to see full answer to understand

#### Explanation:

I don't fully know what you mean first you get your data set where you regress y on x to find how a change in x effects y.

x y
1 4
2 6
3 7
4 6
5 2

And you want to find the relationship between x and y so say you believe the model is like

$y = m x + c$

or in stats

$y = {\beta}_{0} + {\beta}_{1} x + u$

these ${\beta}_{0} , {\beta}_{1}$ are the parameters in the population and $u$ is the effect of unobserved variables otherwise called the error term so you want estimators ${\hat{\beta}}_{0} , {\hat{\beta}}_{1}$

So $\hat{y} = {\hat{\beta}}_{0} + {\hat{\beta}}_{1} x$

This tells you that the predicted coefficents will give you the predicted y value.

So now you want to find the best estimates for these co-efficents we do this by finding the lowest difference between the actual y value and predicted.

min sum_(i=1)^nhatu_i^2~hatbeta_0,hatbeta_1

This basically says that you want the minimum of the sum of the differences between the acutal y values and predicted y values for your regression line

So the formulas for finding them are

${\hat{\beta}}_{1} = \frac{{\sum}_{i = 1}^{n} \left({x}_{i} - \overline{x}\right) \left({y}_{i} - \overline{y}\right)}{{\sum}_{i = 1}^{n} {\left({x}_{i} - \overline{x}\right)}^{2}}$

${\hat{\beta}}_{0} = \overline{y} - {\hat{\beta}}_{1} \overline{x}$