Lecture Overview:

Inference of the Fitted MLR

house = read.csv("housing_data.csv")
house = house[-which(house$bedrooms > 20),]
bed = house$bedrooms
bath = house$bathrooms
size = house$sqft.living/1000
price = house$price
mod1 = lm(log(price) ~ size)
plot(bath, log(price))

Untitled

mod2 = lm(log(price) ~ size + bath)
mod2$coefficients
##  (Intercept)      size       bath
##  12.20975329  0.37293935  0.03853378
##       b0          b1          b2

The fitted model:

$\hat{Y}=12.2098 + 0.3729X_1+0.03853X_2$

The mean log(price) are expected to increase by 0.03729 when the size of the house increases by 1 thousand sqft, holding the number of bathrooms constant.

The mean log(price) are expected to increase by 0.0385 when the number of bathrooms increases by 1, holding the size of the house constant.

Visualise in R

bathnew <- seq(1, 8, length.out = 15)
sizenew <- rep(mean(size), 15)
dat.new <- data.frame(size = sizenew, bath = bathnew)
plot(bathnew, exp(predict(mod2, newdata=dat.new)), type="l",lwd=2, ylab="price", xlab="bathrooms")