--- title: "houses" author: "Chris Parrish" date: "January 18, 2016" output: pdf_document --- houses references: - Cannon, et al., Stat2, chapter 04, example 4.1 Import the data. ```{r} data <- read.csv("Houses.csv", header=TRUE) head(data, 4) dim(data) ``` Predict \$Price\$ by \$Lot\$ alone. ```{r} plot(Price ~ Lot, data=data, pch=20, col="darkred") Houses.lm1 <- lm(Price ~ Lot, data=data) abline(Houses.lm1, col="orange") ``` Residuals for \$Price \sim Lot, data=data\$. ```{r} resid1 <- resid(Houses.lm1) plot(predict(Houses.lm1), resid1, pch=20, col="darkred") abline(h=0, col="orange", lty="dashed") ``` Predict \$Size\$ by \$Lot\$ alone. ```{r} plot(Size ~ Lot, data=data, pch=20, col="darkred") Houses.lm2 <- lm(Size ~ Lot, data=data) abline(Houses.lm2, col="orange") ``` Residuals for \$Size \sim Lot, data=data\$. ```{r} resid2 <- resid(Houses.lm2) plot(predict(Houses.lm2), resid2, pch=20, col="darkred") abline(h=0, col="orange", lty="dashed") ``` Model: \$resid1 \sim resid2\$ ```{r} Houses.lm3 <- lm(resid1 ~ resid2) ``` \$\widehat{resid1} =\$ `r round(coef(Houses.lm3)[1], 3)` + `r round(coef(Houses.lm3)[2], 3)` \$resid2\$ ```{r} coef(Houses.lm3) ``` Added variable plot: \$resid1 \sim resid2\$ ```{r} plot(resid1 ~ resid2, pch=20, col="darkred") abline(Houses.lm3, col="orange") cor(resid1, resid2) ``` Multiple regression. ```{r} Houses.lm4 <- lm(Price ~ Lot + Size, data=data) ``` Conclusion: > "Each additional square foot of \$Size\$ corresponds to an additional \$23.23 of \$Price\$ while controlling for \$Lot\$ being in the model." (Cannon, p.168) ```{r} options(show.signif.stars=FALSE) summary(Houses.lm4) ```