-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update quickstart notebook with corrected typos and WLS #522
base: master
Are you sure you want to change the base?
Conversation
The quickstart guide in the documentation has been updated. New imports, execution code and guide for WLS have been added for better illustration of the library usage.
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
I have created this PR for your review @s3alfisc I mean to also add plot at the end comparing prediction and prediction intervals of OLS and WLS and wanted to check if there's a way these can be generated using the library or will need to be manually computed ? |
Codecov ReportAll modified and coverable lines are covered by tests ✅ |
Thank you @prteek! I'm time constraint tonight but will take a closer look tomorrow evening / Saturday morning. Did you manage to build the docs locally? For some reason, the github action seems to fail :/ |
Hi ! I get the same error in rendering step locally (build step works fine). Seems to be related to quarto-dev/quarto-cli#9255 but I can't quite figure it out for my lack of experience with Quarto. |
…wn cells were re written but are exactly same as earlier.
@s3alfisc able to build and render docs now. Still not clear on why this happened but apparently something in notebook metadata goes wrong when adding a markdown cell using PyCharm. I've re written those cells in Jupyter lab and it seems to fix this issue. |
@s3alfisc this is largely done. If you could please review and approve the workflow that'd be awesome. Also wanted to understand if there is a way in library to get prediction intervals easily ? |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Weighted Lease Squares (WLS)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires that the weights that are passed in are proportional to the inverse of the error variance.
This is technically not true and something that is very confusing in the statsmodels docs. The statsmodels docs discuss Feasible Weighted Least Squares for the purpose of correcting for heteroskedasticity (because the relation between dependent variable and covariates is quadratic, but we fit a linear model, we have homoskedasticity by definition).
But one can simply fit a model with weights being applied to different observations. I.e. from wikipedia, we can simply minimize the following least squares objective function
Optimally, I would like us to start with a very brief section that practically says "you can apply weights, here is how you do it using either frequency weights or precision weights".
Here we could show an example such as this:
import pyfixest as pf
data = pf.get_data(model = "Fepois")[["X1","Y", "f1"]]
data.head()
# data of size N = 1000
print(data.shape)
data_agg = data.groupby(["X1","Y", "f1"]).size().reset_index().rename(columns = {0: "count"})
data_agg.head()
# data of size N << 1000: useful for reducing memory
print(data_agg.shape)
fit_ols = pf.feols("Y ~ X1 | f1", data = data, vcov = "iid")
fit_wls = pf.feols("Y ~ X1 | f1", data = data_agg, vcov = "iid", weights = "count", weights_type = "fweights")
pf.etable([fit_ols, fit_wls])
# identical results and standard errors
And also link to the "Causal Inference for the Brave and True" chapter on WLS.
And then we can go on to motivate Feasible WLS a little bit better than statsmodels
. In this case, I would like to add a sentence below the plot that explains that the conditional Variance
Hi @prteek , please apologize that I've made you wait on a review! It's simply been very busy days for me. I added quite a few comments in the notebook. I hope that all comments are clear - if not, please ask; and if you disagree, complain! =) |
No worries and thanks for the tips there ;-) . I'll give it another go just need a couple more days before I can start. |
The quickstart guide in the documentation has been updated. New imports, execution code and guide for WLS have been added for better illustration of the library usage.