Introduction

  • Linear Regression models the relationship between a dependent and an independent variable.
  • Equation of a simple linear regression model:

\[ y = \beta_0 + \beta_1 x + \epsilon\]

Why trees Dataset is Good for Linear Regression

  • The ‘trees’ dataset involves continuous data, good for modeling relationships.
  • Tree volume depends on Girth, making it easy to explore a predictive relationship.
  • There is a strong correlation between Girth and Volume, which makes regression a good way to measure this relationship.

Scatter Plot Tree Girth vs Volume

g <- ggplot(trees, aes(x = Girth, y = Volume)) + geom_point() +
    labs(title="Tree Girth vs Volume", x="Girth", y="Volume")
g

Adding Regression Line

g + geom_smooth(method="lm", se=FALSE, color="blue")
## `geom_smooth()` using formula = 'y ~ x'

3D Scatter Plot Tree Girth vs Height vs Volume

Mathematical Formulation

  • The Least Squares Estimator minimizes:

\[ \sum_{i=1}^{n} (y_i - (\beta_0 + \beta_1 x_i))^2 \]

  • The estimated parameters:

\[ \hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]

\[ \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]

R Code for Model Fitting

mod <- lm(Volume ~ Girth, data=trees)
print(summary(mod))

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

Model Interpretation

  • Intercept (\(\beta_0 = -36.9435\)): This suggests that if a tree had zero girth, its predicted volume would be negative, which is not meaningful.
  • Slope (\(\beta_1 = 5.0659\)): This means that for every additional inch of girth, the tree’s volume increases by about 5.07 cubic feet.
  • \(R^2 = 0.9353\): This indicates that 93.53% of the variability in tree volume is explained by girth.
  • p-value (\(< 2.2e^{-16}\)): Since the p-value is extremely small, the relationship between girth and volume is statistically significant.

The End, Thank You!