2025-03-13

Linear Regression

  • linear regression is a relationship between a dependent variable and a independent variable
  • Linear regression can defined by the following equation:
  • \(y = m\Omega + \eta\)
  • where \(y\) is a dependent variable and \(\Omega\) is your independent variable.

Linear Regression Ctd

  • Polynomial regressions are also another type of linear regression
  • examples of higher order polynomial regression are :
  • \(y = a\Omega^2 + b\Omega + \eta\)
  • \(y = a\Omega^3 + b\Omega^2 + c\Omega + \eta\)
  • The following slides are examples using built in data sets of r and various packages.

Slide with C02 Dataset

city = filter(CO2, Type == "Quebec")
chilled = filter(city, Treatment == "chilled")
ggplot(chilled, aes(x = conc, y = uptake, color = Plant)) + geom_point() +
  geom_smooth(se = F, method = "lm", formula = y~poly(x,2), color = "blue")

Slide with Cars dataset

Shows the the relationship between speed and stopping distance

ggplot(cars, aes(x = speed, y = dist)) + geom_point(color = "lightpink") + 
  geom_smooth(se = F, method = "lm", formula = y~x, color = "grey")

Slide with Puromycin Dataset

ggplot(Puromycin, aes(x = conc, y = rate, color = state)) + geom_point() + 
  geom_smooth(se = F, method = "lm", formula = y~poly(x,2))

Slide with Storm dataset

Shows storms that occured in the world from a period of 2001 - 2022

s = select(storms, c(year, status,wind, pressure))
s = filter(s, year >= 2000)
 g = ggplot(s, aes(x = pressure, y = wind, colour = status)) + geom_point() +
  geom_smooth(se = F, method = "lm", formula = y~x, color = "red")
 ggplotly(g, width = 700, height = 350)

Slide with Orange Dataset

Shows the growth of orange trees

p = ggplot(Orange, aes(x = age, y = circumference, color = Tree)) + geom_point() + 
  geom_smooth(se = F, method = "lm", formula = y~x, color = "lightblue")
ggplotly(p, width = 700, height = 400)