Simple Linear Regression Basics

Simple linear regression is a method used to solve for a variable, usually ‘y’, with the formula: \[ y = \beta_0 + \beta_1(x) \].

Breaking It Down

  • y represents the variable we want to find, the dependent variable.
  • x is the independent variable. This variable can be arbitrarily chosen and plugged into the function to find y.
  • \(\beta_0\) represents the y-intercept (the point on the y-axis that intersects with the line or when x = 0).
  • \(\beta_1\) represents the slope of the line. (Remember rise over run).

Worked Example

Take the function \(y = 10 + 5x\)

  • 10 is the y intercept or the point (0,10).
  • 5 is the slope. This means the line goes up 5 steps for every 1 step right (5/1).

To solve for an arbitrary point on the line, say when the x axis is at 5, we insert 5 as the x. This results in \(y = 10 + 5(5)\) making \(y = 35\) when \(x = 5\) giving us the point (5,35).

Plotly

With two points we can calculate the slope, or in this case because we already know the slope is 5, we may use it along with the 2 points we now know (the y-intercept and (5,35) to graph the remaining points on the line.)

ggplot2

Now again using ggplot2

Another Worked Example

This time we will attempt to solve for \(x\) (i.e. \(y\) is given to us.) \[20 = 4 + 4x\]

  • 20 is our \(y\).
  • 4 is our y-intercept.
  • 4 is also our slope.
  • Step one, move the y intercept over to the other side. \(-4 + 20 = 4x\) -> \(16 = 4x\)
  • Step two, divide both sides by the slope. \(16/4 = x\) -> \(4 = x\)

This gives us our first point, (4,20). With one point and our slope of 4 that was given to us, we can calculate other points and chart the line.

ggplot2