t_raw <- read.csv("ames.csv")
t <- t_raw %>%
clean_names() %>%
filter(complete.cases(.)) %>%
mutate(at_least_2_stories = ifelse(house_style == "One_Story" | house_style == "One_and_Half_Fin" | house_style == "One_and_Half_Unf", 0, 1))
t_train <- t %>%
filter(year_sold <= 2009)
t_test <- t %>%
filter(year_sold == 2010)
##
## 0 1
## 1814 1116
##
## Call:
## lm(formula = sale_price ~ gr_liv_area + full_bath + garage_area +
## bedroom_abv_gr + at_least_2_stories, data = t_train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -523983 -21213 -74 20500 272704
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 15608.706 3907.713 3.994 6.67e-05 ***
## gr_liv_area 95.888 2.833 33.847 < 2e-16 ***
## full_bath 20662.191 2179.553 9.480 < 2e-16 ***
## garage_area 114.236 5.096 22.415 < 2e-16 ***
## bedroom_abv_gr -20950.145 1341.886 -15.612 < 2e-16 ***
## at_least_2_stories -13086.688 2085.276 -6.276 4.07e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 46780 on 2583 degrees of freedom
## Multiple R-squared: 0.6629, Adjusted R-squared: 0.6623
## F-statistic: 1016 on 5 and 2583 DF, p-value: < 2.2e-16
## [1] "Mean t_test$residual" "1685.7602688377"
## [1] "Rsme of test" "43206.7101451084"
## [1] "Rsme of train" "46730.0378130818"
ggplot() +
geom_point(data = t_train, mapping = aes(predicted, sale_price), alpha = 0.2, color = "blue") +
geom_point(data = t_test, mapping = aes(predicted, sale_price), alpha = 0.2, color = "green") +
geom_abline(intercept = 0, slope = 1) +
scale_x_continuous(labels = scales::label_dollar()) +
scale_y_continuous(labels = scales::label_dollar())
hist(t_train$residual)
hist(t_test$residual)
## [1] "r-squared for train" "0.662932032477308"
## [1] "r-squared for test" "0.663849068321803"
In this project, several key factors were identified that impact the sale price of homes. Living area, number of full bathrooms, garage area, number of bedrooms, and the number of stories to the house play crucial roles in determining house value.
After running the ggcorplot, all the variables used were shown to have a relationship with the sale price of the home. The extremely low p-values of the variables from the model summary also show significance.
Living Area (gr_liv_area):
For every additional square foot of living area, the predicted sale price increases by approximately $95.88.
Larger living areas tend to correlate with higher prices.
Number of Full Bathrooms (full_bath):
Each additional full bathroom adds approximately $20662.19 to the predicted sale price.
Houses with more bathrooms tend to be more valuable.
Garage Area (garage_area:
For every additional square foot of garage area, the predicted sale price increases by approximately $114.24.
Larger garages contribute positively to the house price.
Bedrooms Above Ground (bedroom_abv_gr):
Each additional bedroom above ground reduces the predicted sale price by approximately $20950.15.
More bedrooms may decrease the overall value.
At Least 2 Stories (at_least_2_stories):
Houses with at least 2 stories have a predicted sale price approximately $13086.69 lower than single-story houses.
Single-story homes tend to be more valuable.