\(~\)
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"))
\(~\)
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 builtBelow 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:
ac is “No”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:
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.
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.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)?style and
area.living. Which style tends to have larger living
areas?style and area.living to predict
sale.amount. Interpret the coefficient of
style2 Story Frame in this model.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.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\(~\)
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:
area.living and assessedThe 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:
area.living suggests that among
homes with the same assessed value, additional living area is actually
associated with a small decrease in expected sale priceQuestion #2: For this question you will use the
predictors bedrooms and area.living, and the
outcome sale.amount.
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).bedrooms and
area.living. Describe the strength, form, and direction of
the relationship you see.bedrooms to be larger or smaller than the adjusted effect
after adjusting for area.living? Briefly explain your
reasoning.bedrooms and area.living to
predict sale.amount. Interpret the coefficient estimate of
bedrooms in this model.\(~\)
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:
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,100atticFully 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.
ac and style to predict
sale.amount. Interpret the intercept of this model, being
careful to correctly identify the reference categories of each
predictor.acYes in
the fitted model. Be careful to recognize that this is an adjusted
effect.style and ac?