Model

model <- lm(sale_price ~  overall_qual_over5 + central_air + heating_qc_above3 + remod_recent + gr_liv_area, data = t_clean)

#splitting into testing and training
t_train <- filter(t_clean, test01 == 0)
t_test <- filter(t_clean, test01 == 1)

t_train <- t_train |>
  mutate(predicted = predict(model, newdata = t_train),
         residual = predicted - sale_price)

t_test <- t_test |> 
  mutate(predicted = predict(model, newdata = t_test),
         residual = predicted - sale_price)

Analysis

#my model is attempting to show a linear relationship between sale price of residential properties against 5 factors; overall quality (above a 5 out of 10), the presence of central air conditioning, heating quality (above a 3 out of 5), above ground living area, & years since last remodel. Logically, the presence of these variables should all positively correlate with a higher price. Since higher ratings typically require more investment, we can assume it would reflect on the sale price.

summary(model)
## 
## Call:
## lm(formula = sale_price ~ overall_qual_over5 + central_air + 
##     heating_qc_above3 + remod_recent + gr_liv_area, data = t_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -401501  -28504   -3785   21278  330568 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)        -24484.720   4298.215  -5.696 1.34e-08 ***
## overall_qual_over5  34713.027   2206.893  15.729  < 2e-16 ***
## central_airY        36026.969   3867.233   9.316  < 2e-16 ***
## heating_qc_above3   22426.109   2145.322  10.453  < 2e-16 ***
## remod_recent        21212.033   2438.981   8.697  < 2e-16 ***
## gr_liv_area            87.348      2.039  42.847  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 49830 on 2924 degrees of freedom
## Multiple R-squared:  0.6116, Adjusted R-squared:  0.611 
## F-statistic: 920.9 on 5 and 2924 DF,  p-value: < 2.2e-16
#the model showed all variables as having positive coefficients, which aligns with our logic considering that the presence of these variables would add value to a house's sale price and the lack of presence would do the opposite.

#the model's variables are all very accurate, with p values far below the .05 threshold across the board.
#when overall quality (over 5) increases by 1 point, the resulting price increases by $34,713  
#when central air conditioning is present, the resulting sale price increases by $36,027 
#when heating quality (above 3) increases by 1 point, the sale price increases by $22,426 
#if there has been a remodel in the last 10 years, the sale price increases by $21,212 
#for each square foot of above ground living area, the sale price increases by $87 

rsme_test <- sqrt(mean(t_test$residual ^ 2))

#the RSME of the testing model was 46,007. This shows the average difference between the price our model predicted & what the price actually was. The test data set was slightly more accurate than our training.

res_sum_sqrs <- sum(t_test$residual ^ 2)

total_var <- mean(t_test$sale_price) - t_test$sale_price

total_sum_sqrs <- sum(total_var ^ 2)

r2 <- 1 - (res_sum_sqrs / total_sum_sqrs)

#the r^2 value calculated for the testing model is .619. This means that the model accounted for 61.9% of the variations in sale price with the variables provided. 

#if there was a source of error that I could identify it is that our model is off by almost 50000, which is a considerable amount in terms of real estate. Another source of error could be from years_since_remod (tied to recent_remod) since it's distribution was not normal nor linear, rather exponential.

Graphing the results