Chapter 19 | Section Predicting Elasticity
When building the m3 model, the presented formula is:
sales_i = β0 + β1price_i + β2X_i∗price_i + β3X_i + e_i
but the fitted model in the stats model takes the following formula:
sales ~ price*cost + price*C(weekday) + price*temp
which is missing the individual terms. If my understanding is right, shoudn't the formula be:
sales ~ price + cost + temp + C(weekday) + price*cost + price*C(weekday) + price*temp
or the derative:
δSales/δPrice = β2X_i
?
If this is right, I can submit a PR with the change. I just wanted to check if my reasoning was correct before doing it.
The * operator is a syntactic sugar for including the terms with interaction. : is the interaction only operator. So
y ~ a*b = y ~ a + b + a:b, which translates to a model y_i = β0 + β1 * a + β2 * b + β3 * a * b
Here is the documentation
https://patsy.readthedocs.io/en/latest/formulas.html#operators
I see, nice! I didn't know that... Thanks, man.