rm(list = ls(all=TRUE))
setwd("C:/Users/Nick/Desktop/School/Year 4/Winter/Data Science/Assignment 4")
price_input = as.data.frame(read.csv("housingprices.csv"))
library(lattice)
splom(~price_input[c(2:5)], groups = NULL, data = price_input, axis.line.tck = 0,
axis.text.alpha = 0)

results<-lm(Price ~ Waterfront + Age, price_input)
summary(results)
##
## Call:
## lm(formula = Price ~ Waterfront + Age, data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -224965 -65267 -20755 42416 566741
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 228943.38 3158.33 72.489 < 2e-16 ***
## Waterfront 168623.59 24738.70 6.816 1.29e-11 ***
## Age -667.23 76.74 -8.694 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 95370 on 1731 degrees of freedom
## Multiple R-squared: 0.06457, Adjusted R-squared: 0.06349
## F-statistic: 59.74 on 2 and 1731 DF, p-value: < 2.2e-16
results1<- lm(Price ~ LotSize + Waterfront + Age + LandValue, price_input)
summary(results1)
##
## Call:
## lm(formula = Price ~ LotSize + Waterfront + Age + LandValue,
## data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -263744 -46822 -11184 34527 506489
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.651e+05 3.387e+03 48.734 < 2e-16 ***
## LotSize 1.736e+04 2.648e+03 6.556 7.28e-11 ***
## Waterfront 9.525e+04 2.008e+04 4.743 2.28e-06 ***
## Age -6.118e+02 6.184e+01 -9.894 < 2e-16 ***
## LandValue 1.572e+00 5.328e-02 29.498 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 76820 on 1729 degrees of freedom
## Multiple R-squared: 0.3939, Adjusted R-squared: 0.3925
## F-statistic: 280.9 on 4 and 1729 DF, p-value: < 2.2e-16
results2<- lm(Price ~ Bedrooms + Fireplaces + Bathrooms + Rooms, price_input)
summary(results2)
##
## Call:
## lm(formula = Price ~ Bedrooms + Fireplaces + Bathrooms + Rooms,
## data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -237657 -45491 -9408 32555 494070
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2151 7500 0.287 0.774
## Bedrooms -1901 2994 -0.635 0.526
## Fireplaces 19874 3591 5.534 3.62e-08 ***
## Bathrooms 59916 3395 17.647 < 2e-16 ***
## Rooms 12758 1099 11.606 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 74130 on 1729 degrees of freedom
## Multiple R-squared: 0.4355, Adjusted R-squared: 0.4342
## F-statistic: 333.5 on 4 and 1729 DF, p-value: < 2.2e-16
results3<- lm(Price ~ Waterfront + Rooms + LandValue, price_input)
summary(results3)
##
## Call:
## lm(formula = Price ~ Waterfront + Rooms + LandValue, data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -218874 -43575 -6896 34330 431294
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.624e+04 5.406e+03 8.553 < 2e-16 ***
## Waterfront 1.206e+05 1.843e+04 6.543 7.9e-11 ***
## Rooms 1.719e+04 7.657e+02 22.449 < 2e-16 ***
## LandValue 1.256e+00 5.110e-02 24.584 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 70310 on 1730 degrees of freedom
## Multiple R-squared: 0.492, Adjusted R-squared: 0.4911
## F-statistic: 558.5 on 3 and 1730 DF, p-value: < 2.2e-16
results4<- lm(Price ~ LotSize + Waterfront + Age + LandValue +Bedrooms +
Fireplaces + Bathrooms + Rooms, price_input)
summary(results4)
##
## Call:
## lm(formula = Price ~ LotSize + Waterfront + Age + LandValue +
## Bedrooms + Fireplaces + Bathrooms + Rooms, data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -232094 -37268 -7105 29481 415818
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.770e+03 6.784e+03 0.851 0.3951
## LotSize 1.004e+04 2.182e+03 4.601 4.50e-06 ***
## Waterfront 1.264e+05 1.649e+04 7.664 3.00e-14 ***
## Age -1.512e+02 5.578e+01 -2.710 0.0068 **
## LandValue 1.087e+00 4.662e-02 23.316 < 2e-16 ***
## Bedrooms 2.408e+03 2.589e+03 0.930 0.3525
## Fireplaces 1.346e+04 3.056e+03 4.404 1.13e-05 ***
## Bathrooms 4.637e+04 3.129e+03 14.821 < 2e-16 ***
## Rooms 8.915e+03 9.445e+02 9.438 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 62750 on 1725 degrees of freedom
## Multiple R-squared: 0.5965, Adjusted R-squared: 0.5946
## F-statistic: 318.7 on 8 and 1725 DF, p-value: < 2.2e-16
results5<- lm(Price ~ Bathrooms + Bedrooms + Age + LandValue, price_input)
summary(results5)
##
## Call:
## lm(formula = Price ~ Bathrooms + Bedrooms + Age + LandValue,
## data = price_input)
##
## Residuals:
## Min 1Q Median 3Q Max
## -244428 -40793 -8021 29640 405705
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 11755.2853 7086.5120 1.659 0.09733 .
## Bathrooms 57909.1974 3084.0379 18.777 < 2e-16 ***
## Bedrooms 16503.2306 2247.8855 7.342 3.23e-13 ***
## Age -164.8104 58.7154 -2.807 0.00506 **
## LandValue 1.2304 0.0479 25.687 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 66200 on 1729 degrees of freedom
## Multiple R-squared: 0.5499, Adjusted R-squared: 0.5488
## F-statistic: 528 on 4 and 1729 DF, p-value: < 2.2e-16
confint(results5, level = 0.95)
## 2.5 % 97.5 %
## (Intercept) -2143.752749 25654.323415
## Bathrooms 51860.359915 63958.034964
## Bedrooms 12094.369623 20912.091484
## Age -279.971161 -49.649691
## LandValue 1.136473 1.324374
Bathrooms<-2
Bedrooms<-3
Age<-10
LandValue<-15000
new_pt <-data.frame(Bathrooms, Bedrooms, Age, LandValue)
conf_int_pt <- predict(results5, new_pt, level = 0.95, interval = "prediction")