Skip to content

Quantile Regression #908

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
1,744 changes: 1,744 additions & 0 deletions docs/changelog.html

Large diffs are not rendered by default.

1,811 changes: 1,811 additions & 0 deletions docs/compare-fixest-pyfixest.html

Large diffs are not rendered by default.

779 changes: 779 additions & 0 deletions docs/contributing.html

Large diffs are not rendered by default.

2,472 changes: 2,472 additions & 0 deletions docs/difference-in-differences.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
903 changes: 903 additions & 0 deletions docs/marginaleffects.html

Large diffs are not rendered by default.

2,681 changes: 2,681 additions & 0 deletions docs/multiple_testing.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
830 changes: 830 additions & 0 deletions docs/pyfixest.html

Large diffs are not rendered by default.

627 changes: 627 additions & 0 deletions docs/pyfixest_gpu.html

Large diffs are not rendered by default.

Binary file added docs/quarto_example/QuartoExample.pdf
Binary file not shown.
3,846 changes: 3,846 additions & 0 deletions docs/quickstart.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion pyfixest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
feglm,
feols,
fepois,
quantreg,
rwolf,
wyoung,
)
from pyfixest.report import coefplot, dtable, etable, iplot, make_table, summary
from pyfixest.report import coefplot, dtable, etable, iplot, make_table, qplot, summary
from pyfixest.utils import (
get_data,
get_ssc,
Expand All @@ -50,6 +51,8 @@
"lpdid",
"make_table",
"panelview",
"qplot",
"quantreg",
"report",
"rwolf",
"ssc",
Expand Down
38 changes: 29 additions & 9 deletions pyfixest/estimation/FixestMulti_.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from pyfixest.estimation.fepois_ import Fepois
from pyfixest.estimation.feprobit_ import Feprobit
from pyfixest.estimation.FormulaParser import FixestFormulaParser
from pyfixest.estimation.literals import (
QuantregMethodOptions,
SolverOptions,
)
from pyfixest.estimation.quantreg_ import Quantreg
from pyfixest.estimation.vcov_utils import _get_vcov_type
from pyfixest.utils.dev_utils import DataFrameType, _narwhals_to_pandas
from pyfixest.utils.utils import capture_context
Expand All @@ -36,6 +41,7 @@ def __init__(
fsplit: Optional[str],
separation_check: Optional[list[str]] = None,
context: Union[int, Mapping[str, Any]] = 0,
quantreg_method: QuantregMethodOptions = "fn",
) -> None:
"""
Initialize a class for multiple fixed effect estimations.
Expand Down Expand Up @@ -73,6 +79,9 @@ def __init__(
formulaic during the creation of the model matrix. This can include
custom factorization functions, transformations, or any other
variables that need to be available in the formula environment.
quantreg_method: QuantregMethodOptions, optional
The method to use for the quantile regression. Can be either "fn" or "pfn".
Defaults to "fn". See `quantreg` for more details.

Returns
-------
Expand All @@ -88,6 +97,7 @@ def __init__(
self._seed = seed if use_compression else None
self._separation_check = separation_check
self._context = capture_context(context)
self._quantreg_method = quantreg_method

self._run_split = split is not None or fsplit is not None
self._run_full = not (split and not fsplit)
Expand Down Expand Up @@ -200,18 +210,13 @@ def _prepare_estimation(
def _estimate_all_models(
self,
vcov: Union[str, dict[str, str], None],
solver: Literal[
"np.linalg.lstsq",
"np.linalg.solve",
"scipy.linalg.solve",
"scipy.sparse.linalg.lsqr",
"jax",
],
solver: SolverOptions,
demeaner_backend: Literal["numba", "jax"] = "numba",
collin_tol: float = 1e-6,
iwls_maxiter: int = 25,
iwls_tol: float = 1e-08,
separation_check: Optional[list[str]] = None,
quantile: Optional[float] = None,
) -> None:
"""
Estimate multiple regression models.
Expand All @@ -224,8 +229,8 @@ def _estimate_all_models(
- If a string, can be one of "iid", "hetero", "HC1", "HC2", "HC3".
- If a dictionary, it should have the format {"CRV1": "clustervar"}
for CRV1 inference or {"CRV3": "clustervar"} for CRV3 inference.
solver: Literal["np.linalg.lstsq", "np.linalg.solve", "scipy.sparse.linalg.lsqr", "jax"],
default is 'np.linalg.solve'. Solver to use for the estimation.
solver: SolverOptions
Solver to use for the estimation.
demeaner_backend: Literal["numba", "jax"], optional
The backend to use for demeaning. Can be either "numba" or "jax".
Defaults to "numba".
Expand All @@ -240,6 +245,9 @@ def _estimate_all_models(
separation_check: list[str], optional
Only used in "fepois". Methods to identify and drop separated observations.
Either "fe" or "ir". Executes both by default.
quantile: float
The quantile to use for quantile regression. Default is None.
Only relevant for "quantreg" estimation.

Returns
-------
Expand All @@ -261,6 +269,8 @@ def _estimate_all_models(
_run_full = self._run_full
_splitvar = self._splitvar
_context = self._context
_quantreg_method = self._quantreg_method
self._quantiles = quantile

FixestFormulaDict = self.FixestFormulaDict
_fixef_keys = list(FixestFormulaDict.keys())
Expand Down Expand Up @@ -289,6 +299,7 @@ def _estimate_all_models(
Felogit,
Feprobit,
FeolsCompressed,
Quantreg,
]

model_kwargs = {
Expand Down Expand Up @@ -332,6 +343,14 @@ def _estimate_all_models(
}
)

if _method == "quantreg":
model_kwargs.update(
{
"quantile": self._quantiles,
"method": _quantreg_method,
}
)

model_map = {
("feols", False): Feols,
("feols", True): Feiv,
Expand All @@ -340,6 +359,7 @@ def _estimate_all_models(
("feglm-probit", None): Feprobit,
("feglm-gaussian", None): Fegaussian,
("compression", None): FeolsCompressed,
("quantreg", None): Quantreg,
}

if _method == "compression":
Expand Down
2 changes: 2 additions & 0 deletions pyfixest/estimation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
feglm,
feols,
fepois,
quantreg,
)
from pyfixest.estimation.fegaussian_ import Fegaussian
from pyfixest.estimation.feiv_ import (
Expand Down Expand Up @@ -50,6 +51,7 @@
"fepois",
"literals",
"model_matrix_fixest",
"quantreg",
"rwolf",
"wyoung",
]
Loading
Loading