2026-09-11

What is Simple Linear Regression

  • Examines the relationship between two quantitative variables
  • Helps determine how one variable is related to another
  • Our variables:
    • Home Runs (HR)
    • Runs Batted In (RBI)
  • Were trying to determine whether players who hit more Homeruns (HR) also tend to have more Runs Batted In (RBI)
  • The data comes from MLB players in the ‘batting’ data-set

The Linear Regression Model

Simple linear regression can be represented by the following model:

\[ Y = \beta_0 + \beta_1 \cdot X + \varepsilon \]

  • \(Y\) = the variable we are trying to predict
  • \(X\) = the variable used to make the prediction
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\varepsilon\) = random error

Applying the Model

For our baseball example, the linear regression model becomes:

\[ RBI = \beta_0 + \beta_1 \cdot HR + \varepsilon \]

  • \(RBI\) = Runs batted In
  • \(HR\) = Home Runs
  • \(\beta_0\) = expected RBI when HR is 0
  • \(\beta_1\) = expected change in RBI for each additional home run
  • \(\varepsilon\) = other factors may affect RBI

The Batting Data-set

The ‘batting’ data-set contains batting statistics for 438 MLB players from the 2002 season. For this analysis, we will focus on Home Runs (HR) and Runs Batted In (RBI).

##      playerID HR RBI
## 157 youngdm01  7  27
## 161 velarra01  2   8
## 162 tynerja01  0   9
## 163 thompry01  8  24
## 173 selbybi01  6  21
## 176 riverru01  4  14

These variables will be used to determine whether players with more home runs also tend to have more RBIs.

Home Runs vs RBIs

This scatterplot shows the relationship between home runs and runs batted in.

The graph suggests a positive relationship as the points trend upward, meaning players who hit more home runs tend to have more RBIs

Regression Line

A regression line can be added to clearly show the relationship between home runs and RBIs

## `geom_smooth()` using formula = 'y ~ x'

The positive slope of the regression line shows the positive relationship between home runs and RBIs.

Our Regression Equation

Using the batting data, our fitted regression equation is:

\[ \widehat{RBI} = 16.550 + 2.653 \cdot HR \]

  • 16.550 is the intercept
  • 2.653 is the slope
  • For each additional home run, the model predicts 2.653 more RBIs
  • A player with no home runs is predicted to only have 16.55 RBIs

Interactive Regression Plot

This interactive plotly graphs lets us see single player stats while viewing the overall relationship between home runs and RBIs

R Code Used

The following code creates the regression plot used in our analysis.

ggplot(batting, aes(x = HR, y = RBI)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Home Runs", y = "Runs Batted In")

Conclusion

  • Simple linear regression allowed us to examine the relationship between home runs and RBIs
  • The scatterplot and regression line showed a positive relationship between the two variables
  • The model was:

\[ \widehat{RBI} = 16.550 + 2.653 \cdot HR \]

  • The model predicts about 2.653 additional RBIs for each additional home run