Show the code
library(tidyverse)
library(mosaic)
library(knitr)Course MATH 425
Lexi Soelberg
train <- train %>%
mutate(Cond = case_when(Condition1 %in% c("Norm") ~ 1, TRUE ~ 0),
SaleCond = case_when(SaleCondition %in% c("Normal") ~ 1, TRUE ~ 0))
lm.over.log <- lm(log(SalePrice) ~ OverallQual + GrLivArea + I(GrLivArea^2) + GarageCars + KitchenQual + YearBuilt + I(YearBuilt^2) + TotalBsmtSF + SaleCond + OverallQual:Cond + OverallQual:SaleCond + OverallQual:GrLivArea + OverallQual:YearBuilt, data=train)
summary(lm.over.log)
Call:
lm(formula = log(SalePrice) ~ OverallQual + GrLivArea + I(GrLivArea^2) +
GarageCars + KitchenQual + YearBuilt + I(YearBuilt^2) + TotalBsmtSF +
SaleCond + OverallQual:Cond + OverallQual:SaleCond + OverallQual:GrLivArea +
OverallQual:YearBuilt, data = train)
Residuals:
Min 1Q Median 3Q Max
-0.90057 -0.07891 0.00727 0.09134 0.57754
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -6.161e+01 1.933e+01 -3.188 0.00146 **
OverallQual 1.467e+00 2.336e-01 6.280 4.48e-10 ***
GrLivArea 5.398e-04 3.313e-05 16.294 < 2e-16 ***
I(GrLivArea^2) -1.378e-07 1.151e-08 -11.977 < 2e-16 ***
GarageCars 6.963e-02 7.534e-03 9.241 < 2e-16 ***
KitchenQualFa -2.429e-01 3.377e-02 -7.192 1.02e-12 ***
KitchenQualGd -1.116e-01 1.949e-02 -5.729 1.23e-08 ***
KitchenQualTA -1.928e-01 2.212e-02 -8.715 < 2e-16 ***
YearBuilt 6.767e-02 1.995e-02 3.393 0.00071 ***
I(YearBuilt^2) -1.572e-05 5.153e-06 -3.050 0.00233 **
TotalBsmtSF 1.573e-04 1.202e-05 13.087 < 2e-16 ***
SaleCond 2.924e-01 4.662e-02 6.273 4.68e-10 ***
OverallQual:Cond 1.041e-02 2.063e-03 5.049 5.02e-07 ***
OverallQual:SaleCond -3.963e-02 7.161e-03 -5.534 3.72e-08 ***
OverallQual:GrLivArea 3.406e-05 7.557e-06 4.507 7.11e-06 ***
OverallQual:YearBuilt -7.194e-04 1.202e-04 -5.985 2.72e-09 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1544 on 1444 degrees of freedom
Multiple R-squared: 0.852, Adjusted R-squared: 0.8505
F-statistic: 554.4 on 15 and 1444 DF, p-value: < 2.2e-16
(Intercept) OverallQual GrLivArea
1.756328e-27 4.334685e+00 1.000540e+00
I(GrLivArea^2) GarageCars KitchenQualFa
9.999999e-01 1.072106e+00 7.843718e-01
KitchenQualGd KitchenQualTA YearBuilt
8.943670e-01 8.246796e-01 1.070016e+00
I(YearBuilt^2) TotalBsmtSF SaleCond
9.999843e-01 1.000157e+00 1.339696e+00
OverallQual:Cond OverallQual:SaleCond OverallQual:GrLivArea
1.010467e+00 9.611496e-01 1.000034e+00
OverallQual:YearBuilt
9.992809e-01
(Intercept) ~ 0 Not meaningful on its own — it’s the baseline log-price when all variables are zero, which is outside the range of real houses.
OverallQual (4.334685) Each 1-point increase in quality multiplies SalePrice by 4.33× — this is huge, the biggest one for sure. We will take a closer look in the graphs below.
GrLivArea (1.000540e+00) Each additional square foot increases SalePrice by ~0.054%.
I(GrLivArea^2) (9.999999e-01) Very slight diminishing returns to square footage. The overall effect is curved, this shows that of course large homes sell for more but there might be a slight disadvantage to too large of a home, such as if that home was being sold during the 2008 economic crisis. This data as quadratic only makes sense because of the couple of houses in the data set that are very large in square footage but low in price.
GarageCars (1.072106e+00) Each extra garage spot increases price by ~7.2%.
KitchenQualFa (7.843718e-01) “Fair” kitchen drops price by ~21.6% compared to Ex (Excellent).
KitchenQualGd (8.943670e-01) “Good” kitchen is ~10.6% lower than Ex (Excellent).
KitchenQualTA (0.825) “Typical/Average” is ~17.5% lower than Ex (Excellent).
YearBuilt (1.070016e+00) Each additional year adds ~7% to SalePrice excepting our quadratic term,
I(YearBuilt^2) (9.999843e-01) Slight negative curve, which alters the effect as the year increases, this is again true as we look at when these homes were built and sold. It is probably the same couple of houses that affected our greater living area variable as well.
TotalBsmtSF (1.000157e+00) Each extra square foot in the basement adds ~0.016% to price.
SaleCond (1.339696e+00) “Normal” sales are priced ~33.97% higher than other sale types.
OverallQual:Cond (1.010467e+00) For homes with normal Condition1, the effect of quality is ~1% stronger.
OverallQual:SaleCond (9.611496e-01) For normal sales, the effect of quality is slightly weaker (~3.9% reduction) This is most likely due to the coding of SalCond at 1 = Normal and not demonstrating each type of sale condition to each overall quality. Although this is the is the term that most negatively affects the model it also provides a better validation R^2 so I was not about to take it out of the regression.
GrLivArea:OverallQual (1.000034e+00) The benefit of additional GrLivArea ever so slighlty increases with higher quality.
OverallQual:YearBuilt (9.992809e-01) As homes get newer, the value of quality slightly decreases (by ~0.072% per year).
## validation
set.seed(42)
num_rows <- 1000 # Sample size for training
keep <- sample(1:nrow(train), num_rows)
mytrain <- train[keep, ] # Training set
mytest <- train[-keep, ] # Testing set
# Fit the regression model
househd <- lm.over.log
# Predictions on test set
yh_hd <- predict(househd, newdata = mytest)
ybar <- mean((log(mytest$SalePrice)))
SSTO <- sum((log(mytest$SalePrice) - ybar)^2)
# Compute SSE (Sum of Squared Errors)
SSE_hd <- sum((log(mytest$SalePrice) - yh_hd)^2)
# Compute R-squared
rs_hd <- 1 - SSE_hd / SSTO
# Compute Adjusted R-squared
n <- nrow(mytest)
p_hd <- length(coef(househd))
rsa_hd <- 1 - (SSE_hd / SSTO) * ((n - 1) / (n - p_hd))
# Create validation table
my_output_table <- data.frame(
Model = "House Price Regression",
`Original R^2` = summary(househd)$r.squared,
`Original Adj. R^2` = summary(househd)$adj.r.squared,
`Validation R^2` = rs_hd,
`Validation Adj. R^2` = rsa_hd
)
# Format table for display
colnames(my_output_table) <- c("Model", "Original $R^2$", "Original Adj. $R^2$", "Validation $R^2$", "Validation Adj. $R^2$")
knitr::kable(my_output_table, escape = TRUE, digits = 4)| Model | Original R^2 | Original Adj. R^2 | Validation R^2 | Validation Adj. R^2 |
|---|---|---|---|---|
| House Price Regression | 0.852 | 0.8505 | 0.8646 | 0.86 |
library(ggplot2)
lm.over.log <- lm(log(SalePrice) ~ GrLivArea + OverallQual + I(GrLivArea^2) + GarageCars + KitchenQual + YearBuilt + I(YearBuilt^2) + TotalBsmtSF + SaleCond + OverallQual:Cond + OverallQual:SaleCond + OverallQual:GrLivArea + OverallQual:YearBuilt, data=train)
b <- coef(lm.over.log)
ggplot(train, aes(y=SalePrice, x=GrLivArea, fill = OverallQual)) +
geom_point(pch=21, color="gray", size = 2.5) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Base Prediction")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 1, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Three Car Garage")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Good Qual Kitchen")) +
stat_function(fun = function(GrLivArea, OverallQual = 10,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Overall Quality = 10")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 1980, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Year Built = 1980")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 500, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Basement Sq Footage = 500")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 0, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Sale Condition Not Normal")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 0) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Condition Not Normal")) +
labs(
title = "The Best Prediction of How a House Will Sell",
x = "Above Ground Living Area",
y = "Sale Price (log)"
)The base line shows where you can expect your house to cost based on total living area with the variables set at OverallQual = 5, GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1.
Every additional line contributes to one adjustment in the base line variable selection.
We can see from the graph that the biggest isolating principle has to be the Overall Quality. It seems fairly obvious that when the Overall Quality is a 10 then the sale price goes right up. Combined with the Above Ground Living Area of 3200 you’re looking at around the highest price that this model can produce.
The rest of the lines as shown in the legend of the graph do little to add to the base line. The second best would be a good quality kitchen, and the worst would be a 3 car garage.
library(ggplot2)
lm.over.log <- lm(log(SalePrice) ~ GrLivArea + OverallQual + I(GrLivArea^2) + GarageCars + KitchenQual + YearBuilt + I(YearBuilt^2) + TotalBsmtSF + SaleCond + OverallQual:Cond + OverallQual:SaleCond + OverallQual:GrLivArea + OverallQual:YearBuilt, data=train)
b <- coef(lm.over.log)
ggplot(train, aes(y=SalePrice, x=GrLivArea, fill = OverallQual)) +
geom_point(pch=21, color="gray", size = 2.5) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Base Prediction")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 1, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Three Car Garage")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Good Qual Kitchen")) +
stat_function(fun = function(GrLivArea, OverallQual = 10,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Overall Quality = 10")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 1980, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Year Built = 1980")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 500, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Basement Sq Footage = 500")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 0, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Sale Condition Not Normal")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 1, KitchenQualTA = 0, SaleCond = 1, Cond = 0) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="Condition Not Normal")) +
labs(
title = "The Best Prediction of How a House Will Sell",
x = "Above Ground Living Area",
y = "Sale Price (log)"
) +
facet_wrap(~OverallQual)library(ggplot2)
lm.over.log <- lm(log(SalePrice) ~ GrLivArea + OverallQual + I(GrLivArea^2) + GarageCars + KitchenQual + YearBuilt + I(YearBuilt^2) + TotalBsmtSF + SaleCond + OverallQual:Cond + OverallQual:SaleCond + OverallQual:GrLivArea + OverallQual:YearBuilt, data=train)
b <- coef(lm.over.log)
ggplot(train, aes(y=SalePrice, x=GrLivArea, fill = OverallQual)) +
geom_point(pch=21, color="gray", size = 2.5) +
stat_function(fun = function(GrLivArea, OverallQual = 1,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=1")) +
stat_function(fun = function(GrLivArea, OverallQual = 2,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=2")) +
stat_function(fun = function(GrLivArea, OverallQual = 3,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=3")) +
stat_function(fun = function(GrLivArea, OverallQual = 4,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=4")) +
stat_function(fun = function(GrLivArea, OverallQual = 5,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=5")) +
stat_function(fun = function(GrLivArea, OverallQual = 6,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=6")) +
stat_function(fun = function(GrLivArea, OverallQual = 7,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=7")) +
stat_function(fun = function(GrLivArea, OverallQual = 8,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=8")) +
stat_function(fun = function(GrLivArea, OverallQual = 9,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQual=9")) +
stat_function(fun = function(GrLivArea, OverallQual = 10,GarageCars = 2, YearBuilt = 2000, TotalBsmtSF = 1000, KitchenQualFa = 0, KitchenQualGd = 0, KitchenQualTA = 1, SaleCond = 1, Cond = 1) exp(b[1] + b[2]*GrLivArea + b[3]*OverallQual + b[4]*GrLivArea^2 + b[5]*GarageCars + b[6]*KitchenQualFa + b[7]*KitchenQualGd + b[8]*KitchenQualTA + b[9]*YearBuilt + b[10]*YearBuilt^2 + b[11]*TotalBsmtSF + b[12]*SaleCond + b[13]*OverallQual*Cond + b[14]*OverallQual*SaleCond + b[15]*OverallQual*GrLivArea + b[16]*OverallQual*YearBuilt), aes(color="OverallQuality=10")) +
labs(
title = "Overall Quality 1 - 10",
x = "Above Ground Living Area",
y = "Sale Price (log)"
)This graph shows how a 1-10 rating in OverallQual changes the slope dramatically with each jump in quality. No other variables were adjusted in the graph. The most dramatic is of course a 9 to a 10. The least happens between 1 and 2. We can see from the facet wrap that the least values exist in the 1 and 2 groups. The dots with both the highest sale price and most above ground living area exist in the 10 group. All high sale price values are in groups 8, 9, and 10.
From the previous graph we can see how this was the most dramatic effect of any of the variables. If you want to sell your house for the most moola then do whatever it takes to get the quality up, a 10 is the best.
: )