#Creating a ggcorrplot to see if they are statistically significant
ggcorrplot::ggcorrplot(cor(t_numeric))
#Creating a model
model <- lm(sale_price ~ mas_vnr_area + attached_garage + full_bath + total_sqft + year_built, data = t_train)
summary(model)
##
## Call:
## lm(formula = sale_price ~ mas_vnr_area + attached_garage + full_bath +
## total_sqft + year_built, data = t_train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -639381 -20269 -3011 16945 283482
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.352e+06 6.853e+04 -19.730 < 2e-16 ***
## mas_vnr_area 5.578e+01 5.434e+00 10.266 < 2e-16 ***
## attached_garage -2.633e+02 1.974e+03 -0.133 0.893920
## full_bath 7.024e+03 2.008e+03 3.498 0.000476 ***
## total_sqft 5.987e+01 1.422e+00 42.118 < 2e-16 ***
## year_built 6.920e+02 3.556e+01 19.462 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 43150 on 2583 degrees of freedom
## Multiple R-squared: 0.7132, Adjusted R-squared: 0.7127
## F-statistic: 1285 on 5 and 2583 DF, p-value: < 2.2e-16
#Test viz
ggplot(data = t_test) +
geom_point(aes(x = predicted, y = sale_price))
ggplot() +
geom_point(data = t_test, mapping = aes(x = predicted, y = sale_price), color = 'blue', alpha = 1) +
geom_point(data = t_train, mapping = aes(x = predicted, y = sale_price), color = 'gold', alpha = 0.5) +
labs(title = "Sale Price: Test vs Train Models", x = "Predicted", y = "Sale Price") +
xlim(0, 500000) +
ylim(0, 700000) +
scale_x_continuous(labels = scales::label_dollar()) +
scale_y_continuous(labels = scales::label_dollar()) +
geom_abline(intercept = 0, slope = 1, color = 'black') +
theme_minimal()
## Scale for x is already present.
## Adding another scale for x, which will replace the existing scale.
## Scale for y is already present.
## Adding another scale for y, which will replace the existing scale.
Analysis
I believe that the sale price of a house can be accurately predicted by using the independent variables; The area in square feet of masonry veneer, if the house has an attatched garage, how many full baths are in the house, the total square footage of the house, and the year the house was built in. Below I will describe the impact of each variable on my model.
Variables
mas_vnr_area = Masonry veneer area in square feet. * A type of building material like brick, stone, or manufactured stone * Less expensive than full brick masonry * Positively increases the value on a house
attached_garage = If the garage_type is classified as attached * Having an attached garage a very good quality in a house * I believe that this is directly correlated with the sale price of the house
full_bath = The amount of full baths in the house * Having more bathrooms in a house is more desirable * This is why the more full bathrooms in a house, the higher the sale price will be
total_sqft = total basement sqft + total 1st floor sqft + total 2nd floor sqft * The more square footage in the house, the more desireable it is * This is also why the higher the total square footage, the higher the sale price will be
year_built = The year the house was built in * Generally speaking, the more recent the house was built, the higher the sale price will be
I have used a correlation test to ensure that all of my independent variables are statistically significant. This means that the strength of the relationship between my variables are strong. My model also has an R-squared value of 0.7127, meaning that the independent variables explain my dependent variable. As I clarified before, I picked independent variables that would increase the sale price of a house, like having more square footage, more full bathrooms, or the year built. This will help my model be more statistically significant and better predict the sale price of a house.
Potential Errors and Residuals
A potential error in my model may come from the attached_garage variable. The p value for this one is significantly higher than the others, meaning that it may be due to random chance. The errors are showing themselves in my r2 and rsme testing, where the numbers are quite high. However, this can also be due to the large amount of observations and the high sale prices of the houses.