\(~\)

This lab introduces a key aspect of multivariable regression modeling - the difference between marginal and adjusted effects.

Throughout the lab you will work with the Iowa City Home Sales data, which records information on all single-family homes sold in Iowa City, IA between January 1st, 2005 and mid-September 2008 (when the professor who was assembling the data finally purchased a home). We’ll focus on the two most common styles of home, 1-story frame and 2-story frame:

library(dplyr)
ic_homes <- read.csv("https://remiller1450.github.io/data/IowaCityHomeSales.csv") %>% 
              filter(style %in% c("1 Story Frame", "2 Story Frame"))

\(~\)

Adjusted vs. Marginal Effects

To see the difference between the marginal and adjusted effect of a predictor on an outcome, we’ll begin by considering two models:

  • sale.amount ~ ac - predicting sale price using whether a home has central air conditioning (a binary categorical predictor)
  • sale.amount ~ ac + built - giving us the adjusted effect of a home having central air conditioning after accounting for differences in when a home was built

Below we fit the first model and print its coefficients:

ac_model1 = lm(sale.amount ~ ac, data = ic_homes)
summary(ac_model1)$coefficients
##              Estimate Std. Error  t value     Pr(>|t|)
## (Intercept) 138767.26   11660.59 11.90053 4.218911e-29
## acYes        50204.76   12407.42  4.04635 5.978373e-05

Notice:

  • The reference category of the predictor ac is “No”
  • The marginal effect estimated by this model is that the mean sale price of homes with central air is $50,204 higher than the mean sale price of homes without central air
    • This effect is marginal because it does not consider any other differences between homes with and without central air that might also impact price

Below we fit the second model:

ac_model2 = lm(sale.amount ~ ac + built, data = ic_homes)
summary(ac_model2)$coefficients
##                 Estimate  Std. Error    t value    Pr(>|t|)
## (Intercept) -250635.0320 267351.2066 -0.9374748 0.348942965
## acYes         41823.9159  13662.4684  3.0612269 0.002316516
## built           201.6062    138.2849  1.4579041 0.145461513

Notice:

  • The adjusted effect estimated by this model is that the mean sale price of homes with central air is only $41,823 higher than the mean sale price of homes without central air after adjusting for differences in when a home was built
    • The adjusted effect is smaller than the marginal effect because newer homes are more likely to have central air, and newer homes also sell for higher prices, thus the marginal effect of ac was reflecting some of the effect of built, which is why adjusting for built decreases the estimated coefficient of acYes.

Question #1: For this question you will use the predictors style and area.living, and the outcome sale.amount.

  • Part A: Fit a regression model that uses style as the only predictor of sale.amount. Print a summary of the coefficients of this model, and use those coefficients to find the mean sale price of each style of home.
  • Part B: Fit a simple linear regression model that uses area.living as the only predictor of sale.amount. What is the marginal effect estimated by this model (ie: an interpretation of the slope coefficient estimate)?
  • Part C: Create an appropriate data visualization to explore the relationship between style and area.living. Which style tends to have larger living areas?
  • Part D: Consider the relationships you found in Parts A-C. Based upon these relationships, do you expect the adjusted difference in mean sale price (adjusting for difference in living) between these two styles to be larger or smaller than the marginal difference? Explain your reasoning without fitting the adjusted model.
  • Part E: Now fit a regression model using both style and area.living to predict sale.amount. Interpret the coefficient of style2 Story Frame in this model.
  • Part F: Explain why the adjusted effect of style in the model you fit in Part E seems to suggest that 2-story homes sell for less than 1-story homes, but the model in Part A suggests 2-story homes sell for more.
  • Part G: Explain why the adjusted effect of area.living in the model you fit in Part E is larger than the marginal effect of area.living in the model from Part B. Hint: think about whether larger homes tend to be 1-story or 2-story
  • Part H: Suppose you’re a prospective home buyer wanting to decide whether to focus on 1-story or 2-story homes, and you are only concerned about the total price you’ll need to pay without any concern for size (you don’t care at all about the home’s size). Which of the three models you’ve fit in earlier parts of this question is most useful in this scenario?
  • Part I: Suppose you are a current home owner looking to build a 160 square-foot addition onto your existing home. You’d like to know how much to spend on this addition to break even in terms of your home’s expected sale price. Which of the three models you’ve fit in earlier parts of this question is most useful in this scenario?

\(~\)

Multiple Quantitative Predictors

The same concepts of adjusted and marginal effects introduced in the previous section also apply to models involving multiple quantitative variables. However, a key difference is the visual form of the model:

  • One categorical and one quantitative predictor gave us two parallel lines, with a different intercept for each group
  • Two quantitative predictors gives us a single plane of best fit, which is shown below for the predictors area.living and assessed

The fact that the plane of best fit must consider both variables when minimizing the squared residuals explains how the adjusted effect is determined.

Using these two predictors as an example, let’s compare the following two models:

## Model 1 - showing marginal effect of living area
living_model1 = lm(sale.amount ~ area.living, data = ic_homes)
summary(living_model1)$coefficients
##               Estimate  Std. Error  t value      Pr(>|t|)
## (Intercept) -9207.5175 6224.280078 -1.47929  1.396580e-01
## area.living   138.5583    4.166612 33.25442 1.030755e-131
## Model 2 - showing adjusted effect of living area, adjusting for assessed value
living_model2 = lm(sale.amount ~ area.living + assessed, data = ic_homes)
summary(living_model2)$coefficients
##                Estimate   Std. Error   t value      Pr(>|t|)
## (Intercept) 5564.304185 2.406436e+03  2.312260  2.114715e-02
## area.living  -14.037475 3.191316e+00 -4.398649  1.318117e-05
## assessed       1.110862 2.009731e-02 55.274151 1.051174e-221

Notice:

  • The adjusted effect of area.living suggests that among homes with the same assessed value, additional living area is actually associated with a small decrease in expected sale price
  • The size of a home is one of the main factors that contributes to a home’s assessed value
  • Thus, since assessed value already captures the benefits of a home’s size, a larger home with the same assessed value would typically need to be weaker in some other way (such as worse location, lot size, quality, etc) and these weaknesses are likely being reflected in the negative coefficient

Question #2: For this question you will use the predictors bedrooms and area.living, and the outcome sale.amount.

  • Part A: Fit a regression model that uses bedrooms as the only predictor of sale.amount. Use this model to describe the marginal relationship between the number of bedrooms and a home’s sale price (ie: interpret the estimated slope).
  • Part B: Create an appropriate data visualization to explore the relationship between bedrooms and area.living. Describe the strength, form, and direction of the relationship you see.
  • Part C: Based upon your results from Parts A and B, as well as the knowledge that larger living areas are associated with higher sale prices. Do you expect the marginal effect of bedrooms to be larger or smaller than the adjusted effect after adjusting for area.living? Briefly explain your reasoning.
  • Part D: Now fit the regression model using both bedrooms and area.living to predict sale.amount. Interpret the coefficient estimate of bedrooms in this model.

\(~\)

Multiple Categorical Predictors

The final scenario we haven’t explicitly discussed is when a model has multiple categorical predictors. Here, the same principles regarding marginal and adjusted effects apply, with the biggest challenge being that the model’s reference is now determined by a category from each categorical predictor. To illustrate this, consider the following predictors:

  • ac - has two categories: “Yes” and “No”
  • attic - has six categories: “1/2 Finished”, “1/4 Finished”, “3/4 Finished”, “Floor & Stairs”, “Fully Finished”, and “None”

Below are the coefficient estimates from the fitted model:

attic_ac_model = lm(sale.amount ~ ac + attic, data = ic_homes)
summary(attic_ac_model)$coefficients
##                       Estimate Std. Error     t value     Pr(>|t|)
## (Intercept)         149033.274   25195.02  5.91518787 5.987710e-09
## acYes                51100.089   12653.75  4.03833681 6.187902e-05
## attic1/4 Finished    63533.333   58152.86  1.09252302 2.751053e-01
## attic3/4 Finished   -28999.990   38794.06 -0.74753694 4.550748e-01
## atticFloor & Stairs   8916.648   33150.78  0.26897247 7.880567e-01
## atticFully Finished   2226.655   47511.57  0.04686552 9.626383e-01
## atticNone           -12328.292   24284.55 -0.50765995 6.119054e-01

Notice the category “No” from ac was not represented using a dummy variable, and the category “1/2 Finished” from attic also was not represented using a dummy variable.

Using this to interpret some of the model coefficients:

  • The intercept tells us the mean sale price of homes with no central air conditioning and a 1/2 finished attic is $149,033
  • The coefficient of the dummy variable acYes tells us that for homes with the same type of attic, central air conditioning is expected to increase the mean sale price by $51,100
  • Similarly, the the coefficient of the dummy variable atticFully Finished tells us that for homes with the same type of air conditioning, a home with a fully finished attic is expected to sell for $2226.65 more than a home with a 1/2 finished attic.

Question #3: For this question you will use the predictors ac and style, and the outcome sale.amount.

  • Part A: Fit the regression model using both ac and style to predict sale.amount. Interpret the intercept of this model, being careful to correctly identify the reference categories of each predictor.
  • Part B: Use the fitted model to find the expected sale price of a 1-story frame home that has central air conditioning. Show your calculation.
  • Part C: Interpret the effect acYes in the fitted model. Be careful to recognize that this is an adjusted effect.
  • Part D: Recall that the marginal effect of central air conditioning was such that homes with central air sold for an average of $50,205, which is similar to the adjusted effect from the model you fit in Part A. What might this tell you about the relationship between the predictors style and ac?