2025-10-17

Slide 2: What is linear Regression?

  • Linear regression is a statistical method that models the relationship between two variables by fitting a line to the data.
  • The line of best fit , given by \[\hat{y} = \beta_0 + \beta_1x + \varepsilon\] is found using the least squares method, which minimizes the squared differences between the observed values (\(y_i\)) and the predicted values (\(\hat{y}_i\)). \[\sum(y_i - \hat{y}_i)^2\]

Slide 3: Mathmatical formula

\[\hat{y} = \beta_0 + \beta_1x + \varepsilon\] Where

  • \(\beta_0\) is the y-Intercept
  • \(\beta_1x\) is the slope
  • \(\varepsilon\) is the random error term

Slide 4: Scatterplot( Girth Vs Height) from tree dataset

Slide 5: Plot with Regression Line

Slide 6: How Regression Line was made

The following code uses ’ geom_smooth(method ‘lm’)’ to automatically fit and draw the least squares regression line.

plot = ggplot(trees, aes(x = Girth, y = Height))+geom_point()+
  geom_smooth(method = 'lm', se = T)

Slide 7: Interactive 2D-Plot

Slide 8: Interpretation & Conclusion.

-Below we have the coefficient of determination, \(R^2\), which is low at 0.2697.

-The \(R^2\) value of 0.2697 indicates a weak relationship between Height and Girth, meaning Height alone does not explain much of the variation in Girth.

model <- lm(Girth~Height, data = trees)
summary(model)$r.squared
## [1] 0.2696518