Intelligence Refinery / Jan 14 2020
Remix of R Template by Nextjournal
Multiple linear regression
Import data
house <- read.csv('https://github.com/nchelaru/practical_statistics/raw/master/kc_house_data.csv')
house$date <- as.Date(house$date, "%Y%m%dT000000")
head(house)
0.5s
multiple_linear_regression (R)
0 items
Multiple regression
The jtools
package is a very useful one for summarizing and visualizing regression results. For more information, see here.
library(jtools)
house_lm <- lm(price ~ .,
data=house,
na.action=na.omit)
summ(house_lm)
multiple_linear_regression (R)
Stepwise regression
library(MASS)
step <- stepAIC(house_lm, direction="both")
summ(step)
multiple_linear_regression (R)
Weighted regression
library(lubridate)
house$Year = year(house$date)
house$Weight = house$Year - 2005
house_wt <- lm(price ~ .,
data=house,
weight=Weight)
summ(house_wt)
multiple_linear_regression (R)
Compare models
plot_coefs(house_lm, house_wt, step,
scale = TRUE,
model.names = c("Full", "Weighted", "Stepwise"))
multiple_linear_regression (R)