2026-11-01

What is Linear Regression

  • Linear regression is to see if two things are related
  • It draws a line through the data that shows which way it trends
  • Example: Does budget affect the rating of a movie?

The formula

\[\hat{y} = \beta_0 + \beta_1 x\]

  • where \(\hat{y}\) is the predicted value
    • in our case the “rating” of the movie
  • \(x\) is the predictor
    • budget
  • \(\beta_0\) is the intercept
  • \(\beta_1\) is the slope of the line

How the Line is fit

\[\sum_{i=1}^{n} (y_i - \hat{y}_i)^2\]

  • For each dot, it finds the gap between the real rating and the line’s guess
    • this is called the residual
  • It squares each gap so that they are all positive in case there are any negatives
  • Then it adds them up and the best line comes out with the smallest total

Example: Budget Vs. Rating

  • We will be using the data from IMDB (ggplot2movies package)

    • This will be a total of 58788 movies
  • Does the budget affect the rating of a movie?

  • We’ve only kept movies that have a budget

    • The movies with no budget would not be on the chart
  • This leaves us with 5183 movies

Budget Vs Rating (ggplot)

Adding Regression Line

  • A bigger budget does not seem to guarantee a better rating

Plotly (Interactive)

R Code

graph <- lm(rating ~ log10(budget), data = budgetOfMovie)

form <- coef(graph)
names(form) <- c("Intercept", "Slope")

form
##  Intercept      Slope 
##  6.7657534 -0.1008903
  • The slope comes out negative
    • meaning higher budget predicts a slightly lower rating