Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.1 KB

File metadata and controls

41 lines (35 loc) · 1.1 KB

Linear Regression

Implicit Assumptions
◻️ Dependent variable is continuous.
Actual Code
  1. Run the linear regression model.
Simple Linear Regression
fit <- lm(mpg ~ hp, mtcars)
summary(fit)
Multiple Linear Regression (w/o Interaction)
fit <- lm(Petal.Length ~ Species + Sepal.Length, iris)
summary(fit)
Multiple Linear Regression (w Interaction)
fit <- lm(Petal.Length ~ Species * Sepal.Length + Sepal.Width, iris)
#fit <- lm(Petal.Length ~ Species * Sepal.Length, iris)
summary(fit)
  1. Examine its residual plots.
plot(fit, 1)
plot(fit, 2)
abline(a = 0, b = 0)
  1. If required, obtain prediction and/or residuals.
iris$predicted <- predict(fit)
iris$residuals <- residuals(fit)