Building Response Models in R
Kathrin Gruber
Assistant Professor of Econometrics Erasmus University Rotterdam
Carry-over effect
How to lag?
head(cbind(sales.data$PRICE,
lag(sales.data$PRICE, n = 1)))
[,1] [,2]
[1,] 1.090000 NA
[2,] 1.271818 1.090000
[3,] 1.271818 1.271818
[4,] 1.271818 1.271818
[5,] 1.271818 1.271818
[6,] 1.271818 1.271818
Price.lag <- lag(sales.data$PRICE)
lag.model <- lm(log(SALES) ~ PRICE + Price.lag, data = sales.data)
coef(lag.model)
(Intercept) PRICE Price.lag
3.906 -4.579 4.935
Coupon.lag <- lag(sales.data$COUPON)
lm(update(lag.model, . ~ . + COUPON + Coupon.lag), data = sales.data)
Call:
lm(formula = update(lag.model, . ~ . + COUPON + Coupon.lag), data = sales.data)
Coefficients:
(Intercept) PRICE Price.lag COUPON Coupon.lag
3.8327 -4.5050 4.8426 0.9697 0.3840
lag.model <- lm(log(SALES) ~ PRICE + Price.lag + DISPLAY + Display.lag + COUPON + Coupon.lag + DISPLAYCOUPON + DisplayCoupon.lag, data = sales.data)
plot(log(SALES) ~ 1, data = sales.data) lines(c(NA, fitted.values(lag.model)) ~ 1)
Building Response Models in R