Make sure to include the unit of the values whenever appropriate.

Q1 Build a regression model to predict home prices using the following predictors: 1) bedrooms and 2) water front.

Hint: The variables are available in the SaratogaHouses data set from the mosaicData package.

library(tidyverse)

data(SaratogaHouses, package="mosaicData")
wages_lm <- lm(price~ bedrooms + waterfront,
                data = SaratogaHouses)
summary(wages_lm)
## 
## Call:
## lm(formula = price ~ bedrooms + waterfront, data = SaratogaHouses)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -270743  -54861  -15794   32876  502206 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    247858      23774  10.426   <2e-16 ***
## bedrooms        49790       2610  19.074   <2e-16 ***
## waterfrontNo  -194643      22994  -8.465   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 88440 on 1725 degrees of freedom
## Multiple R-squared:  0.1938, Adjusted R-squared:  0.1928 
## F-statistic: 207.3 on 2 and 1725 DF,  p-value: < 2.2e-16

Q2 Is the coefficient of bedrooms statistically significant at 5%?

Since the p-value is smaller than .05, the coefficient of bedrooms is statistically significant at 5%.

Q3 Interpret the coefficient of bedrooms.

Hint: Discuss both its sign and magnitude.

For every bedroom a house in Saratoga, New York has, the price of the house increases by $49,790.

Q4 Are waterfront homes more expensive? Make your argument using the relevant test results.

Hint: Discuss all three aspects of the relevant predictor: 1) statistical significance, 2) sign, and 3) magnitude.

  1. The coefficient of waterfront homes is statistically significant at 5% because the p-value is less than .05.

  2. The negative sign of the coefficient indicates that the waterfront homes are less expensive than the mean price of homes in Saratoga, New York.

  3. The magnitude of the coefficient of waterfront homes is -194643, meaning that waterfront homes are on average $194,643 less expensive than the median home price in Saratoga, New York.

Q5 Predict the price for a home with three bedrooms on waterfront.

$202,585

Q6 Interpret the Intercept.

Hint: Provide a technical interpretation.

The technical interpretation of the intercept is that a home in Saratoga, New York without a waterfront location or any bedrooms costs $247,858 on average. This technically is not possible and is only a reference point for comparing the coeffficients waterfront and number of bedrooms.

Q7 Build another model by adding a predictor to the model above. The additional predictor is age. Which of the two models is better?

Hint: Discuss in terms of both residual standard error and reported adjusted R squared.

wages_lm <- lm(price~ bedrooms + waterfront + age,
                data = SaratogaHouses)
summary(wages_lm)
## 
## Call:
## lm(formula = price ~ bedrooms + waterfront + age, data = SaratogaHouses)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -214067  -53391  -16214   32639  521759 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   270418.82   23271.97  11.620   <2e-16 ***
## bedrooms       50503.63    2543.58  19.855   <2e-16 ***
## waterfrontNo -200250.85   22403.23  -8.938   <2e-16 ***
## age             -689.71      71.01  -9.712   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 86140 on 1724 degrees of freedom
## Multiple R-squared:  0.2356, Adjusted R-squared:  0.2343 
## F-statistic: 177.1 on 3 and 1724 DF,  p-value: < 2.2e-16

The second model is a better predictor of home price because it has a lower residual standard error and higher asjusted r-squared.

Q8 Hide the messages, but display the code and its results on the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.