2025-06-08

What Is Simple Linear Regression?

Simple linear regression models the relationship between two continuous variables by fitting a straight line:

  • Dependent (response) Y: the variable we predict
  • Independent (predictor) X: the variable we use for prediction

Key equation: \[ Y = \beta_0 + \beta_1 X + \epsilon \] \[ \hat{Y} = b_0 + b_1 X \]

Least Squares Estimation

We choose \(b_0, b_1\) to minimize the sum of squared errors: \[ \mathrm{SSE} = \sum_{i=1}^n (y_i - \hat y_i)^2 \] \[ b_1 = \frac{\sum (x_i - \bar x)(y_i - \bar y)}{\sum (x_i - \bar x)^2} \quad,\quad b_0 = \bar y - b_1 \bar x \]

Formulas adapted from “An Introduction to Statistical Learning”

Our Dataset: trees

We’ll use R’s built-in trees (31 black cherry trees):

head(trees)
##   Girth Height Volume
## 1   8.3     70   10.3
## 2   8.6     65   10.3
## 3   8.8     63   10.2
## 4  10.5     72   16.4
## 5  10.7     81   18.8
## 6  10.8     83   19.7

Data Exploration

ggplot(trees, aes(x = Girth, y = Volume)) +
  geom_point(color = "steelblue", size = 3, alpha = 0.8) +
  labs(title = "Volume vs. Girth", x = "Girth (in)", y = "Volume (cu ft)") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))

Fitting the Regression Line

ggplot(trees, aes(x = Girth, y = Volume)) +
  geom_point(color = "steelblue", size = 3, alpha = 0.8) +
  geom_smooth(method = "lm", se = TRUE, color = "red", fill = "pink") +
  labs(title = "Tree Volume vs. Girth with Regression Line",
       x = "Girth (inches)", y = "Volume (cubic feet)") +
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5))

Interactive 3D Visualization (HTML Only)

Model Summary

model <- lm(Volume ~ Girth, data = trees)
summary(model)
## 
## Call:
## lm(formula = Volume ~ Girth, data = trees)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.065 -3.107  0.152  3.495  9.587 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -36.9435     3.3651  -10.98 7.62e-12 ***
## Girth         5.0659     0.2474   20.48  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.252 on 29 degrees of freedom
## Multiple R-squared:  0.9353, Adjusted R-squared:  0.9331 
## F-statistic: 419.4 on 1 and 29 DF,  p-value: < 2.2e-16

Interpretation:
- Intercept (b₀): value at Girth = 0 (not physically meaningful here)
- Slope (b₁): +5.07 cu ft per inch of girth
- R² = 0.935: 93.5% of Volume variance explained by Girth

Diagnostic Plot: Residuals vs Fitted

plot(model, which = 1)

Diagnostic Plot: Q–Q of Residuals

plot(model, which = 2)

Key Assumptions Checked

  1. Linearity – confirmed by scatter + fit
  2. Independence – trees measured independently
  3. Homoscedasticity – residuals show constant spread
  4. Normality – residuals align on Q–Q line

Conclusion

  • Girth is an excellent predictor of Volume in black cherry trees.
  • Always pair model fitting with diagnostics to validate assumptions.
  • Simple linear regression provides a foundation for more complex models.