2026-10-18

What is simple linear regression?

Simple linear regression models the relationship between one independent variable (x) and one dependent variable (y) using a straight-line equation.

\[ Y = \beta_0 + \beta_1 X + \epsilon \]

  • \(\beta_0\): the intercept
  • \(\beta_1\): the slope
  • \(\epsilon\): the random error

Why Do We Use Linear Regression?

The goal is to find the line of best fit that minimizes the sum of squared residuals between observed and predicted values.

We use linear regression to:

  • Understand relationships between variables.
  • Make predictions.
  • Identify trends in data.

Introduction to the Data Set

The trees data set in R contains 31 observations and three variables:

  • Girth: Tree diameter in inches.
  • Height: Tree height in feet.
  • Volume: Timber volume in cubic feet.

We want to investigate the linear relationships between girth and volume, and height and volume.

Introduction to the Data Set

data(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

Regression Models

We consider two simple linear regression models.

Model 1: Girth vs Volume

  • Independent variable (X): Girth
  • Dependent variable (Y): Volume

Model 2: Height vs Volume

  • Independent variable (X): Height
  • Dependent variable (Y): Volume

Model 1: Girth vs. Volume

p1 = ggplot(trees, aes(x = Girth, y = Volume)) +
     geom_point(color = "steelblue", size = 3) +
     geom_smooth(method = "lm", se = FALSE, color = "red") +
     labs(title = "Girth vs Volume",
        x = "Girth (inches)",
        y = "Volume (cubic feet)")

Model 1: Girth vs. Volume

ggplotly(p1)

Model 1: Girth vs. Volume

model1 = lm(Volume ~ Girth, data = trees)
model1
## 
## Call:
## lm(formula = Volume ~ Girth, data = trees)
## 
## Coefficients:
## (Intercept)        Girth  
##     -36.943        5.066

The fitted regression equation is:

\[ \widehat{Volume} = -36.943 + 5.066(Girth) \]

Model 2: Height vs. Volume

p2 = ggplot(trees, aes(x = Height, y = Volume)) +
     geom_point(color = "steelblue", size = 3) +
     geom_smooth(method = "lm", se = FALSE, color = "red") +
     labs(title = "Height vs Volume",
        x = "Height (feet)",
        y = "Volume (cubic feet)")

Model 2: Height vs. Volume

ggplotly(p2)

Model 2: Height vs. Volume

model2 = lm(Volume ~ Height, data = trees)
model2
## 
## Call:
## lm(formula = Volume ~ Height, data = trees)
## 
## Coefficients:
## (Intercept)       Height  
##     -87.124        1.543

The fitted regression equation is:

\[ \widehat{Volume} = -87.124 + 1.543(Height) \]

Observation

Model 1: Girth vs Volume

  • Girth and volume have a strong, positive linear relationship.
  • The observed points are relatively close to the fitted regression line.
  • There are no obvious outliers.

Model 2: Height vs Volume

  • Height and volume have a weaker, positive linear relationship.
  • The observed points are more widely scattered around the fitted regression line.
  • Some observations have relatively large residuals.

Exploring the correlation between Height and Girth

cor(trees$Height, trees$Girth)
## [1] 0.5192801

We find that height and girth has a moderate positive relationship.

Conclusion

  • Both girth and height have positive linear relationships with volume. Girth has a stronger linear relationship with volume than height, suggesting that girth is a better predictor of tree volume.

  • Height and girth have a moderate positive correlation (r = 0.519). This suggests a possible indirect association between height and volume through girth. However, correlation does not imply causation.

  • To improve prediction accuracy, we could explore more advanced models, such as multiple linear regression, models with interaction terms, or higher-order polynomial regression.