library(tidyverse)
library(tidymodels)
library(knitr)
AE 06: Prediction for MLR
Houses in Levittown
The data set contains the sales price and characteristics of 85 homes in Levittown, NY that sold between June 2010 and May 2011. Levittown was built right after WWII and was the first planned suburban community built using mass production techniques.
<- read_csv("data/homeprices.csv") levittown
The variables used in this analysis are
bedrooms
: Number of bedroomsbathrooms
: Number of bathroomsliving_area
: Total living area of the house (in square feet)lot_size
: Total area of the lot (in square feet)year_built
: Year the house was builtproperty_tax
: Annual property taxes (in USD)sale_price
: Sales price (in USD)
The goal of the analysis is to use the characteristics of a house to understand variability in the sales price.
Linear model
<- linear_reg() |>
price_fit set_engine("lm") |>
fit(sale_price ~ bedrooms + bathrooms + living_area + lot_size +
+ property_tax, data = levittown)
year_built
tidy(price_fit) |>
kable(digits = 3)
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | -7148818.957 | 3820093.694 | -1.871 | 0.065 |
bedrooms | -12291.011 | 9346.727 | -1.315 | 0.192 |
bathrooms | 51699.236 | 13094.170 | 3.948 | 0.000 |
living_area | 65.903 | 15.979 | 4.124 | 0.000 |
lot_size | -0.897 | 4.194 | -0.214 | 0.831 |
year_built | 3760.898 | 1962.504 | 1.916 | 0.059 |
property_tax | 1.476 | 2.832 | 0.521 | 0.604 |
Prediction
What is the predicted sale price for an individual house in Levittown, NY with 4 bedrooms, 2 bathrooms, 1,800 square feet of living area, 6,000 square foot lot size, built in 1947 with $7,403 in property taxes?
Report the predicted value and appropriate interval.
# create tibble for new observation
<- tibble(
new_house bedrooms = ____,
bathrooms = ____,
_____
)
# prediction + interval
prediction(_________)
- Interpret the interval in the context of the data.