# Example 6.2, Effects of Pollution on Housing Prices
# Data set: hprice2
# Function for result reporting
source("_report.R")
# Load the data and estimate the model in the background
load("hprice2.Rdata")
data$ldist=log(data$dist) # There is a variable missing in the
desc=rbind(desc,data.frame(variable="ldist",label="log(dist)")) # data set. These lines create it.
data$roomssq=(data$rooms)^2
model=lm(lprice~lnox+ldist+rooms+roomssq+stratio, data=data)
dig=c(2,3,3,3,3,3,3)
# Describe the model
cat("This example use the housing price data set that was used in Example 4.5. In the previous example, we estimated the model: lprice = beta0 + beta1 * lnox + beta2 * ldist + beta3 * rooms + beta4 * stratio + u",
"\nwhere lprice is ", paste(desc[desc[,1]=="lprice",2]), " (price: ", paste(desc[desc[,1]=="price",2]), ")",
"\nlnox is ", paste(desc[desc[,1]=="lnox",2]), " (nox: ", paste(desc[desc[,1]=="nox",2]), ")",
"\nldist is ", paste(desc[desc[,1]=="ldist",2]), " (dist: ", paste(desc[desc[,1]=="dist",2]), ")",
"\nrooms is ", paste(desc[desc[,1]=="rooms",2]),
"\nand stratio is ", paste(desc[desc[,1]=="stratio",2]),
"\nHere, we further add an independent variable, roomssq, which is a quadratic term in rooms. Hence the new model to estimate becomes:",
"\nlprice = beta0 + beta1 * lnox + beta2 * ldist + beta3 * rooms + beta4 * roomssq + beta5 * stratio + u",
sep="")
# Report results
{
cat("The estimated regression line is")
reportreg(model,dig)
}
# Interpretation
turnaround=round(as.numeric(printabscoef(model,4,dig[4]))/(2*as.numeric(printcoef(model,5,dig[5]))),1)
cat("The quadratic term roomssq has a t statistic of ", printt(model,5,dig[5]),
", so it is very statistically significant",
"\nThe equation implies that when rooms increase by 1, lprice is predicted to change by ",
printcoef(model,4,dig[4]), " + 2 * ", printcoef(model,5,dig[5]), " rooms. Thus, the equation itself implies that at low values of rooms, an additional room has a NEGATIVE effect on lprice; the effect becomes positive as rooms go beyond a point, which is computed as ",
printabscoef(model,4,dig[4]), "/(2 * ", printcoef(model,5,dig[5]), ") = ", turnaround,
". However, this does not mean that we can conclude that when the number of rooms is less than ", turnaround,
" more rooms will really cause a decrease in the housing price. In fact, among all the ",
nrow(data), " communities in the data set, only ", nrow(data[data$rooms ", turnaround,
", adding another room has an increasing effect on the percentage change in price. For example, an increase in rooms from 5 to 6 increases predicted price by ",
100*as.numeric(printcoef(model,4,dig[4])), " + 2 * ", 100*as.numeric(printcoef(model,5,dig[5])), "(5) = ",
round(100*as.numeric(printcoef(model,4,dig[4]))+2*100*as.numeric(printcoef(model,5,dig[5]))*5,1),
" per cent. When the increase in rooms is from 6 to 7, the predicted price becomes ",
100*as.numeric(printcoef(model,4,dig[4])), " + 2 * ", 100*as.numeric(printcoef(model,5,dig[5])), "(6) = ",
round(100*as.numeric(printcoef(model,4,dig[4]))+2*100*as.numeric(printcoef(model,5,dig[5]))*6,1),
" per cent, a considerable increase. While the coefficient on the quadratic term seems to have a small magnitude, it actually implies a large effect",
sep="")