Skip to content
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

Glm docs #779

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ quartodoc:
contents:
- estimation.estimation.feols
- estimation.estimation.fepois
- estimation.estimation.feglm
- did.estimation.did2s
- did.estimation.lpdid
- did.estimation.event_study
Expand All @@ -71,6 +72,10 @@ quartodoc:
- estimation.feols_.Feols
- estimation.fepois_.Fepois
- estimation.feiv_.Feiv
- estimation.feglm_.Feglm
- estimation.felogit_.Felogit
- estimation.feprobit_.Feprobit
- estimation.fegaussian_.Fegaussian
- estimation.feols_compressed_.FeolsCompressed
#- did.did.DID
#- did.did2s.DID2s
Expand Down
5 changes: 5 additions & 0 deletions docs/_sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ website:
- contents:
- reference/estimation.estimation.feols.qmd
- reference/estimation.estimation.fepois.qmd
- reference/estimation.estimation.feglm.qmd
- reference/did.estimation.did2s.qmd
- reference/did.estimation.lpdid.qmd
- reference/did.estimation.event_study.qmd
Expand All @@ -15,6 +16,10 @@ website:
- reference/estimation.feols_.Feols.qmd
- reference/estimation.fepois_.Fepois.qmd
- reference/estimation.feiv_.Feiv.qmd
- reference/estimation.feglm_.Feglm.qmd
- reference/estimation.felogit_.Felogit.qmd
- reference/estimation.feprobit_.Feprobit.qmd
- reference/estimation.fegaussian_.Fegaussian.qmd
- reference/estimation.feols_compressed_.FeolsCompressed.qmd
section: Estimation Classes
- contents:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## PyFixest 0.28.0 (In Development, can be installed from github)

- Adds a `pf.feglm()` function that supports GLMs with normal and binomial families (gaussian, logit, probit) without fixed effects. Fixed effects support is work in progress.
- Adds a function argument `context`, that allows to pass information / context to the `formulaic.Formulaic.get_model_matrix()` call that creates the model matrix.
- Fix a bug that caused reindexing of `LPDID._coeftable` when calling `LPDID.iplot()`. As a result, a second call of `LPDID.iplot()` would fail.

## PyFixest 0.27.0
Expand Down
41 changes: 34 additions & 7 deletions pyfixest/estimation/estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ def fepois(
fit = pf.fepois("Y ~ X1 + X2 | f1 + f2", data)
fit.summary()
```
For more examples, please take a look at the documentation of the `feols()`
function.

For more examples on the use of other function arguments, please take a look at the documentation of the [feols()](https://py-econometrics.github.io/pyfixest/reference/estimation.estimation.feols.html#pyfixest.estimation.estimation.feols) function.
"""
if separation_check is None:
separation_check = ["fe"]
Expand Down Expand Up @@ -745,7 +745,7 @@ def feglm(
fsplit: Optional[str] = None,
) -> Union[Feols, Fepois, FixestMulti]:
"""
Estimate GLM regression model with fixed effects.
Estimate GLM regression models (currently without fixed effects, this is work in progress).

Parameters
----------
Expand Down Expand Up @@ -859,13 +859,40 @@ def feglm(

```{python}
import pyfixest as pf
import numpy as np

data = pf.get_data(model = "Fepois")
fit = pf.fepois("Y ~ X1 + X2 | f1 + f2", data)
fit.summary()
data = pf.get_data()
data["Y"] = np.where(data["Y"] > 0, 1, 0)
data["f1"] = np.where(data["f1"] > data["f1"].median(), "group1", "group2")

fit_probit = pf.feglm("Y ~ X1*f1", data, family = "probit")
fit_logit = pf.feglm("Y ~ X1*f1", data, family = "logit")
fit_gaussian = pf.feglm("Y ~ X1*f1", data, family = "gaussian")

pf.etable([fit_probit, fit_logit, fit_gaussian])
```

`PyFixest` integrates with the [marginaleffects](https://marginaleffects.com/bonus/python.html) package. For example, to compute average marginal effects
for the probit model above, you can use the following code:

```{python}
# we load polars as marginaleffects outputs pl.DataFrame's
import polars as pl
from marginaleffects import avg_slopes
pl.concat([avg_slopes(model, variables = "X1") for model in [fit_probit, fit_logit, fit_gaussian]])
```

We can also compute marginal effects by group (group average marginal effects):

```{python}
avg_slopes(fit_probit, variables = "X1", by = "f1")
```
For more examples, please take a look at the documentation of the `feols()`

We find homogeneous effects by "f1" in the probit model.

For more examples of other function arguments, please take a look at the documentation of the [feols()](https://py-econometrics.github.io/pyfixest/reference/estimation.estimation.feols.html#pyfixest.estimation.estimation.feols)
function.

"""
if family not in ["logit", "probit", "gaussian"]:
raise ValueError(
Expand Down
Loading