summary(homeprice)
##       list            sale            full            half       
##  Min.   : 43.0   Min.   : 48.0   Min.   :1.000   Min.   :0.0000  
##  1st Qu.:189.0   1st Qu.:185.0   1st Qu.:1.000   1st Qu.:0.0000  
##  Median :275.0   Median :272.5   Median :2.000   Median :1.0000  
##  Mean   :274.8   Mean   :273.5   Mean   :1.724   Mean   :0.6552  
##  3rd Qu.:339.0   3rd Qu.:340.0   3rd Qu.:2.000   3rd Qu.:1.0000  
##  Max.   :599.0   Max.   :613.0   Max.   :3.000   Max.   :2.0000  
##     bedrooms         rooms         neighborhood  
##  Min.   :1.000   Min.   : 3.000   Min.   :1.000  
##  1st Qu.:3.000   1st Qu.: 7.000   1st Qu.:2.000  
##  Median :3.000   Median : 7.000   Median :3.000  
##  Mean   :3.172   Mean   : 7.207   Mean   :2.897  
##  3rd Qu.:4.000   3rd Qu.: 8.000   3rd Qu.:3.000  
##  Max.   :5.000   Max.   :11.000   Max.   :5.000
cor(homeprice)
##                   list      sale       full       half  bedrooms     rooms
## list         1.0000000 0.9942086  0.6462615  0.3921774 0.4829463 0.6289836
## sale         0.9942086 1.0000000  0.6271649  0.3941621 0.4864766 0.6283765
## full         0.6462615 0.6271649  1.0000000 -0.1249070 0.3178330 0.3957178
## half         0.3921774 0.3941621 -0.1249070  1.0000000 0.2468199 0.3531705
## bedrooms     0.4829463 0.4864766  0.3178330  0.2468199 1.0000000 0.8451594
## rooms        0.6289836 0.6283765  0.3957178  0.3531705 0.8451594 1.0000000
## neighborhood 0.8810091 0.8770245  0.6188266  0.1562738 0.2418608 0.4088005
##              neighborhood
## list            0.8810091
## sale            0.8770245
## full            0.6188266
## half            0.1562738
## bedrooms        0.2418608
## rooms           0.4088005
## neighborhood    1.0000000
ggplot(homeprice, aes(x = list, y = sale)) + 
  geom_point() + 
  ggtitle("List Price vs Sale Price")

The scatter plot shows a nearly perfect linear relationship between list price and sale price, indicating that the list price is a strong predictor of the sale price.

ggplot(homeprice, aes(x = full, y = sale)) + 
  geom_point() + 
  ggtitle("Full Bathrooms vs Sale Price")

There is a positive trend indicating that houses with more full bathrooms tend to have higher sale prices.

ggplot(homeprice, aes(x = half, y = sale)) + 
  geom_point() + 
  ggtitle("Half Bathrooms vs Sale Price")

There is a positive trend indicating that houses with more full bathrooms tend to have higher sale prices.

ggplot(homeprice, aes(x = bedrooms, y = sale)) + 
  geom_point() + 
  ggtitle("Bedrooms vs Sale Price")

There is a positive trend indicating that houses with more full bathrooms tend to have higher sale prices.

ggplot(homeprice, aes(x = rooms, y = sale)) + 
  geom_point() + 
  ggtitle("Non-bedrooms vs Sale Price")

There is a positive trend indicating that houses with more full bathrooms tend to have higher sale prices.

ggplot(homeprice, aes(x = neighborhood, y = sale)) + 
  geom_point() + 
  ggtitle("Neighborhood Rank vs Sale Price")

There is a strong positive trend indicating that higher neighborhood ranks correspond to higher sale prices.

model_sale <- lm(sale ~ list + full + half + bedrooms + rooms + neighborhood, data = homeprice)
summary(model_sale)
## 
## Call:
## lm(formula = sale ~ list + full + half + bedrooms + rooms + neighborhood, 
##     data = homeprice)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -28.807  -6.626  -0.270   5.580  32.933 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   5.13359   17.15496   0.299    0.768    
## list          0.97131    0.07616  12.754 1.22e-11 ***
## full         -4.97759    5.48033  -0.908    0.374    
## half         -1.00644    5.70418  -0.176    0.862    
## bedrooms      2.49224    6.43616   0.387    0.702    
## rooms        -0.43411    3.70424  -0.117    0.908    
## neighborhood  2.03434    6.88609   0.295    0.770    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 13.87 on 22 degrees of freedom
## Multiple R-squared:  0.989,  Adjusted R-squared:  0.986 
## F-statistic: 330.5 on 6 and 22 DF,  p-value: < 2.2e-16

The summary output shows the coefficients, standard errors, t-values, and p-values for each predictor in the model. The R-squared value indicates the goodness-of-fit of the model.

anova(model_sale)
## Analysis of Variance Table
## 
## Response: sale
##              Df Sum Sq Mean Sq   F value Pr(>F)    
## list          1 381050  381050 1981.6252 <2e-16 ***
## full          1    156     156    0.8116 0.3774    
## half          1     21      21    0.1092 0.7441    
## bedrooms      1     25      25    0.1314 0.7204    
## rooms         1      3       3    0.0141 0.9065    
## neighborhood  1     17      17    0.0873 0.7704    
## Residuals    22   4230     192                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The ANOVA output helps identify which variables have the greatest effect on the sale price. Variables with lower p-values have a more significant impact.

model_list <- lm(list ~ full + half + bedrooms + rooms + neighborhood, data = homeprice)
summary(model_list)
## 
## Call:
## lm(formula = list ~ full + half + bedrooms + rooms + neighborhood, 
##     data = homeprice)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -60.788 -28.776   4.351  23.859  62.720 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -144.544     36.026  -4.012 0.000546 ***
## full           32.125     13.427   2.392 0.025293 *  
## half           45.556     12.397   3.675 0.001257 ** 
## bedrooms       18.446     17.197   1.073 0.294572    
## rooms           7.126     10.033   0.710 0.484661    
## neighborhood   77.430      9.737   7.952 4.75e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 37.97 on 23 degrees of freedom
## Multiple R-squared:  0.9183, Adjusted R-squared:  0.9006 
## F-statistic: 51.74 on 5 and 23 DF,  p-value: 9.358e-12

The summary output shows the coefficients, standard errors, t-values, and p-values for each predictor in the model explaining the list price.

plot(model_sale$residuals)

The residuals plot helps assess the distribution of residuals. Ideally, residuals should be randomly distributed without any clear pattern.

anova(model_list)
## Analysis of Variance Table
## 
## Response: list
##              Df Sum Sq Mean Sq  F value    Pr(>F)    
## full          1 169594  169594 117.6457 1.615e-10 ***
## half          1  92249   92249  63.9922 4.294e-08 ***
## bedrooms      1   9745    9745   6.7597   0.01601 *  
## rooms         1  10162   10162   7.0494   0.01415 *  
## neighborhood  1  91158   91158  63.2352 4.754e-08 ***
## Residuals    23  33156    1442                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The ANOVA output helps identify which variables have the greatest effect on the list price. Comparing this with the sale price model, we can see if different variables influence the list price more than the sale price.

homeprice$difference <- homeprice$sale - homeprice$list
ggplot(homeprice, aes(x = factor(neighborhood), y = difference)) + 
  geom_boxplot() + 
  ggtitle("Neighborhood Effect on Price Difference")

The box plot shows the effect of neighborhood rank on the difference between sale price and list price. It helps determine if richer neighborhoods are more likely to have houses sell over the asking price.

STEPS TAKEN:

Data Loading: Load libraries and data set.

Descriptive Statistics: Generate summary statistics.

Correlation Analysis: Create correlation matrix.

Visualizations:

Scatter plots for key variables vs. Sale Price.

Multiple Linear Regression Model: Sale Price:

Summary and ANOVA output.

Multiple Linear Regression Model: List Price:

Effect of Neighborhood on Price Difference: