python-causality-handbook icon indicating copy to clipboard operation
python-causality-handbook copied to clipboard

Chapter 19 | Section Predicting Elasticity

Open viniciusmsousa opened this issue 5 years ago • 2 comments

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.

viniciusmsousa avatar Jun 30 '21 13:06 viniciusmsousa

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

matheusfacure avatar Jun 30 '21 14:06 matheusfacure

I see, nice! I didn't know that... Thanks, man.

viniciusmsousa avatar Jun 30 '21 14:06 viniciusmsousa