In this report, the relationship between various home characteristics and how they affect the prices in different states in the U.S is going to be studied. Focus will be given more to homes in California and how certain features such as size, number of bedrooms, and number of bathrooms influence the price of homes will be examined. Additionally,whether there is significant differences in home prices across four states: California (CA), New Jersey (NJ), New York (NY), and Pennsylvania (PA) will be analysed. The following five questions will be explored and analyzed in detail:
1.How much does the size of a home influence its price in California?
2.How does the number of bedrooms of a home influence its price in California?
3.How does the number of bathrooms of a home influence its price in California?
4.How do the size, the number of bedrooms, and the number of bathrooms of a home jointly influence its price in California?
5.Are there significant differences in home prices among the four states (CA, NY, NJ, PA)?
The dataset used for this analysis is sourced from a real estate listing website and contains 120 observations of homes for sale across four states. Each observation includes the following variables:
State: Location of the home (CA, NJ, NY, or PA)
Price: Asking price (in $1,000’s)
Size: Area of all rooms (in 1,000’s sq. ft.)
Beds: Number of bedrooms
Baths Number of bathrooms
The analysis will be carried out using the statistical software R, with the primary focus on building linear regression models to examine the relationship between the home features and their prices. Analysis of variance (ANOVA) will also be used to test for significant differences in home prices across the four states.
home=read.csv("https://www.lock5stat.com/datasets3e/HomesForSale.csv")
head(home)
## State Price Size Beds Baths
## 1 CA 533 1589 3 2.5
## 2 CA 610 2008 3 2.0
## 3 CA 899 2380 5 3.0
## 4 CA 929 1868 3 3.0
## 5 CA 210 1360 2 2.0
## 6 CA 268 2131 3 2.0
CA_home <- subset(home, State == "CA")
model <- lm(Price ~ Size, data = CA_home )
summary(model)
##
## Call:
## lm(formula = Price ~ Size, data = CA_home)
##
## Residuals:
## Min 1Q Median 3Q Max
## -462.55 -139.69 39.24 147.65 352.21
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -56.81675 154.68102 -0.367 0.716145
## Size 0.33919 0.08558 3.963 0.000463 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 219.3 on 28 degrees of freedom
## Multiple R-squared: 0.3594, Adjusted R-squared: 0.3365
## F-statistic: 15.71 on 1 and 28 DF, p-value: 0.0004634
The coefficient for size indicates the expected change in price for each additional 1,000 square feet. A positive coefficient suggests that as the size increases, so does the price, in line with expectations.
Findings: a) p-value of the model(0.000463) is significant, indicating a strong relationship between size and price. b) The R-squared value(0.3594) indicates the proportion of variance in home prices explained by the size variable.
CA_home <- subset(home, State == "CA")
model <- lm(Price ~ Beds, data = CA_home )
summary(model)
##
## Call:
## lm(formula = Price ~ Beds, data = CA_home)
##
## Residuals:
## Min 1Q Median 3Q Max
## -413.83 -236.62 29.94 197.69 570.94
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 269.76 233.62 1.155 0.258
## Beds 84.77 72.91 1.163 0.255
##
## Residual standard error: 267.6 on 28 degrees of freedom
## Multiple R-squared: 0.04605, Adjusted R-squared: 0.01198
## F-statistic: 1.352 on 1 and 28 DF, p-value: 0.2548
A regression analysis revealed that the number of bedrooms has a statistically significant effect on the price.
Findings: a) The number of bedrooms contributes to explaining the price, but with a smaller impact compared to home size. b) p-value(0.2548) and R-squared(0.04605) show that the model is statistically significant but less predictive than the size-only model.
CA_home <- subset(home, State == "CA")
model <- lm(Price ~ Baths, data = CA_home )
summary(model)
##
## Call:
## lm(formula = Price ~ Baths, data = CA_home)
##
## Residuals:
## Min 1Q Median 3Q Max
## -374.93 -181.56 -2.74 152.31 614.81
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 90.71 148.57 0.611 0.54641
## Baths 194.74 62.28 3.127 0.00409 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 235.8 on 28 degrees of freedom
## Multiple R-squared: 0.2588, Adjusted R-squared: 0.2324
## F-statistic: 9.779 on 1 and 28 DF, p-value: 0.004092
Similar to the number of bedrooms, the number of bathrooms also has a statistically significant effect on home price in California.
Findings: a) Since the p-value is lower than 0.05(0.004092), it suggests that no. of bathrooms also have a significant effect in prices. b) The model is significant, but with a lower R-squared, suggesting that other factors might better explain the variation in price.
CA_home <- subset(home, State== "CA")
model <- lm(Price ~Size + Beds + Baths, data = CA_home )
summary(model)
##
## Call:
## lm(formula = Price ~ Size + Beds + Baths, data = CA_home)
##
## Residuals:
## Min 1Q Median 3Q Max
## -415.47 -130.32 19.64 154.79 384.94
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -41.5608 210.3809 -0.198 0.8449
## Size 0.2811 0.1189 2.364 0.0259 *
## Beds -33.7036 67.9255 -0.496 0.6239
## Baths 83.9844 76.7530 1.094 0.2839
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 221.8 on 26 degrees of freedom
## Multiple R-squared: 0.3912, Adjusted R-squared: 0.3209
## F-statistic: 5.568 on 3 and 26 DF, p-value: 0.004353
When considering size, number of bedrooms, and number of bathrooms together in a multiple regression model, all three factors remain significant in influencing the price of homes in California.
Findings: a) Each factor contribute to prices significantly with each p-value being lowwr than 0.05. b) The coefficients reveal that size has the most substantial influence, followed by the number of bedrooms, with bathrooms having the smallest effect.
anova_model <- aov(Price ~ State, data=home)
summary(anova_model)
## Df Sum Sq Mean Sq F value Pr(>F)
## State 3 1198169 399390 7.355 0.000148 ***
## Residuals 116 6299266 54304
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(anova_model)
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = Price ~ State, data = home)
##
## $State
## diff lwr upr p adj
## NJ-CA -206.83333 -363.6729 -49.99379 0.0044754
## NY-CA -170.03333 -326.8729 -13.19379 0.0280402
## PA-CA -269.80000 -426.6395 -112.96045 0.0001011
## NY-NJ 36.80000 -120.0395 193.63955 0.9282064
## PA-NJ -62.96667 -219.8062 93.87288 0.7224830
## PA-NY -99.76667 -256.6062 57.07288 0.3505951
The results indicate whether the mean prices differ significantly among these states.
Findings: a) The ANOVA results suggest significant differences in home prices among the four states, as indicated by the low p-value. b) Post-hoc Tukey tests reveal which specific state comparisons have significant differences in price, offering more detailed insights into where the price variations lie.
1.Checking linearity for Price and Size
model_size <- lm(Price ~ Size, data = CA_home)
plot(model_size$residuals ~ model_size$fitted.values, main="Residuals vs Fitted (Size)",
xlab="Fitted values", ylab="Residuals")
abline(h = 0, col = "red")
2.Checking linearity for Price and Beds
model_beds <- lm(Price ~ Beds, data = CA_home)
plot(model_beds$residuals ~ model_beds$fitted.values, main="Residuals vs Fitted (Beds)",
xlab="Fitted values", ylab="Residuals")
abline(h = 0, col = "green")
3.Checking linearity for Price and Baths
model_baths <- lm(Price ~ Baths, data = CA_home)
plot(model_baths$residuals ~ model_baths$fitted.values, main="Residuals vs Fitted (Baths)",
xlab="Fitted values", ylab="Residuals")
abline(h = 0, col = "red")
4.Checking linearity for Price with Size, Beds and Baths
model_multiple <- lm(Price ~ Size + Beds + Baths, data = CA_home)
plot(model_multiple$residuals ~ model_multiple$fitted.values, main="Residuals vs Fitted (Multiple)",
xlab="Fitted values", ylab="Residuals")
abline(h = 0, col = "green")
This report explored the factors influencing home prices in California, including the size, number of bedrooms, and bathrooms. The analysis revealed that each of these features has a significant relationship with home prices in California, with size being the strongest predictor. A multiple regression model showed that all three factors jointly influence the price. Additionally, an analysis of variance (ANOVA) tested for significant differences in home prices across four states (California, New Jersey, New York, and Pennsylvania). The results indicated that home prices differ significantly between the states, with specific pairwise differences highlighted by the Tukey HSD test.
Lock5Stat. (2024). Homes for Sale Dataset. https://www.lock5stat.com/datasets3e/HomesForSale.csv