Linear Regression

What is it?

  • Linear Regression is a statistics method that shows the relationship between an independent variable and a dependent variables and allows us to predict outcomes.

Variables

  • Independent Variable: The input variable. Usually denoted as \(\mathcal{x}\)

  • Dependent Variable: The output that the input variable effects. Usually denoted as \(\mathcal{y}\)

Variables Graphed

Example: AS The study hours increase to do the study scores Real-world data rarely follows a perfect linear pattern. Linear regression allows us to find the line that best represents the overall trend.

The Regression Line

  • The Regression Equation: An equation that best models the relationship between the independent and dependent variables. It is represented by \(\hat{y} = b_0 + b_1 \mathcal{x}\) where \(b_0\) is the constant and \(b_1\) is the slope.

  • First find the slope:

    \(b_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}\)

  • Then find the Y-intercept:

    \(b_0 = \bar{y} - b_1 \bar{x}\)

    Where \(\bar{x}\) is the mean of \(\mathcal{x}\) and \(\bar{y}\) is the mean of \(\mathcal{y}\).

Example- Hours Studies vs Exam scores

In order to better understand the relationship and make conclusions we would need to find the regression line for this graph.

Finding the Linear Regression line

Find the mean of x variables \({\bar{x}}\)

\(\frac{ 1 + 2 + 3 + 4 + 5 + 6 + 7}{7} = 4\)

Find the mean of y variables \({\bar{y}}\)

\(\frac{ 58 + 67 + 72 + 74 + 88 + 85 + 97}{7}= 77.286\)

Finding the Linear Regression line(2)

Use the values in the previously mentioned equations to find the slope and y-intercept

\(b_1 = \frac{\sum (x_i - 4)(y_i - 77.286)}{\sum (x_i - 4)^2}= \frac{169}{28} = 6.036\)

\(b_0 = 77.286 - 6.036(4)= 53.143\)

Then plug them into the equation

\(\hat{y} = 53.143 + 6.036 \mathcal{x}\)

New Graph with the Linear Regression Line

Here is the linear regression line on the graph

Prediction

with our linear regression line we can now predict a students exam score based on their hours of study. Say a student studied 4.5 hours then:

\(\mathcal{x}=4.5\)

\(\hat{y} = 53.143 + 6.036(4.5)=80.43\)%