### Linear models with interaction effects ###
# load data on flats
flats <- read.csv("http://math-info.hse.ru/f/2018-19/pep/flats.csv")
str(flats)
# run a model
# suppose that price depends on the distance from metro station (metrdist),
# and on the possibility to get on foot (walk)
# taking into account the fact that the effect of metrdist is not the same
# for blocks of flats that are reachable by foot and non-reachable by foot (walk)
# so we add an interaction effect metrdist:walk (to consider the fact above
# in our model) and run a linear model
model <- lm(data = flats, price ~ metrdist + walk + metrdist:walk)
summary(model)
# the interaction effect is statistically significant,
# so distance from metro station affects price differently
# for flats that are reachable and non-reachable by foot
# if walk=1 (reachable by foot), this effect of metrdist is lower by
# 1.41 (look at the coefficient) all else equal