Issue on page /21-Debiasing-with-Orthogonalization.html
Should m3 be using the debiased values of the training set? I thought the point of this was to be able to train/regress a better model with the debiased values. I think this is used in the 3rd plot, but it is confusing to build up to these debiased values and not show a model that uses them
m3 = smf.ols(f"sales ~ pricecost + priceC(weekday) + price*temp", data=train).fit()
Why does this code use 'price' and 'sales' for predictions instead of price-Mt(X) and sales-My(X)?
These Debiased values are used in the graphs, but I think it would be useful to see them make an individual prediction from the test data.
def predict_elast(model, price_df, h=0.01): return (model.predict(price_df.assign(price=price_df["price"]+h)) - model.predict(price_df)) / h
debiased_test_pred = debiased_test.assign(**{ "m3_pred": predict_elast(m3, debiased_test), })
debiased_test_pred.head()
Thats a good point. I'll include a section using this debiasing in a model.
As for
Why does this code use 'price' and 'sales' for predictions instead of price-Mt(X) and sales-My(X)?
I honestly don't know. I guess one procedure is enough to debias. But I don't have the theory to back me up on this.
@matheusfacure, so the idea of using orthogonalization on the Y and T variables (using the Frisch–Waugh–Lovell Theorem) is to use the price-Mt(X) and sales-My(X) variables to regress on the 'buckets' created from ordering the unit level elasticity m3_pred (predicted from the m3 model, trained on the biased data)?
What I mean is something like this:
- Train/Test Split on dataset;
- Fit model on train data (without debiasing the data);
- Predict the elasticity on test data (without debiasing the data) with the model from step 2 and the derivative approx, resulting in a unit level elasticity (
m3_pred); - Order the unit level elasticity (
m3_pred) from step 3; - Compute the elasticity in the groups that are formed from the ordering os step 4 (and build the evaluation curves). But now using the linear coefficient of
sales-My(X) = b0 + b1*price-Mt(X).
Is this reasoning correct, based on the chapter content?
Chapter 25 will give a better idea about how to use it. https://github.com/matheusfacure/python-causality-handbook/pull/95 I'm wondering if this orthogonalisation technique is well placed in the book. Maybe it should be presented latter... Thats the issue with books in WIP, sorry about that.
I've moved this chapter to the appendix because it was misplaced. Thanks for the feedback!