Inference after selection¶
The post-double-selection, double machine learning and debiased lasso
results are hdfe-stream results: summary(), tidy(), confint(),
wald_test() and hdfe-stream’s etable work on them as on a regression.
- penalized_stream.double_selection_stream(fml, data, *, controls, unpenalized=None, penalty='rigorous', vcov='hetero', cluster=None, weights=None, weights_type='aweights', n_folds=5, fold_by=None, seed=0, standardize=True, tol=1e-07, rigorous_options=None, groups=None, **options)[source]¶
Post-double-selection: the effect of the treatments in
fml, controlling for the controls a lasso selects.- Parameters:
fml (str) –
"y ~ d | fe1 + fe2": the outcome, the treatment(s) whose effects are estimated (never penalized) and the fixed effects (partialled out).data (str, Path, polars.LazyFrame or polars.DataFrame)
controls (str) – The candidate controls, as a right-hand side (
"x1 + x2 + i(region)").unpenalized (str or list of str, optional) – Controls always included (and never penalized in the lassos), as a right-hand side or names: hdm’s
I3, the “amelioration set”.penalty (str or float, default "rigorous") – The lassos’ penalty:
"rigorous"(the plug-in penalty, for which the method’s guarantees hold; hdm’s and Stata’s pdslasso’s default),"cv","cv_1se", a criterion, or a value.vcov (default "hetero") – The final regression’s vcov, as for hdfe-stream:
"iid","hetero",{"CRV1": "state"}…cluster (str, optional) – The plug-in penalty’s loadings are clustered by this column; default: the vcov’s cluster, if it is one-way.
weights – As for
lasso_stream(the folds are used only bypenalty="cv").weights_type – As for
lasso_stream(the folds are used only bypenalty="cv").n_folds – As for
lasso_stream(the folds are used only bypenalty="cv").fold_by – As for
lasso_stream(the folds are used only bypenalty="cv").seed – As for
lasso_stream(the folds are used only bypenalty="cv").standardize – As for
lasso_stream(the folds are used only bypenalty="cv").tol – As for
lasso_stream(the folds are used only bypenalty="cv").rigorous_options (dict, optional) – As for
lasso_stream.groups ("factors" or dict, optional) – Group lassos in place of the lassos: each factor of
controls("factors"), or each named group of controls, is selected or left out as a block, as inlasso_stream. Not withpenalty="rigorous".**options – hdfe-stream’s options, for the pass and the final regression.
- Returns:
HDFEResult – The final regression, with
double_selection(aDoubleSelection) saying what was selected for what.
- penalized_stream.double_selection_iv_stream(fml, data, *, controls, unpenalized=None, select_instruments=False, method='union', penalty='rigorous', vcov='hetero', cluster=None, weights=None, weights_type='aweights', n_folds=5, fold_by=None, seed=0, standardize=True, tol=1e-07, rigorous_options=None, groups=None, sup_score=False, sup_score_options=None, **options)[source]¶
Post-double-selection with instruments: the 2SLS effect of an endogenous treatment, controlling for the controls lassos select.
- Parameters:
fml (str) – An IV formula,
"y ~ w + [d ~ z1 + z2] | fe1 + fe2": the outcome, any exogenous regressors w (always included and never penalized;1if none), the endogenous treatment d and its excluded instruments, and the fixed effects (partialled out).data (str, Path, polars.LazyFrame or polars.DataFrame)
controls (str) – The candidate controls, as a right-hand side (
"x1 + x2 + i(region)").unpenalized (str or list of str, optional) – Controls always included (and never penalized in the lassos), as a right-hand side or names.
select_instruments (bool, default False) – False: every instrument is used, and the controls are those selected for the outcome, the treatment or any instrument (hdm’s
rlassoIVselectX). True: a lasso of the treatment on the instruments and the controls selects the instruments (hdm’srlassoIV), for when there are many.method ({"union", "partialling_out"}, default "union") –
"union": the 2SLS regression of the outcome on the treatment and the union of the selected controls, instrumented by the instruments (and the union), as Stata’sivlassoreports under “PDS”."partialling_out": the outcome, the treatment and the instruments are each replaced by their residual from the post-lasso fit on their own selected controls, and the result is the 2SLS regression of the residuals (hdm’s estimate,ivlasso’s “CHS”). Withselect_instruments, the single instrument is the residual of the first-stage fit, and the treatment’s residual uses the controls selected for that fit, as in hdm’srlassoIV.penalty (str or float, default "rigorous") – The lassos’ penalty:
"rigorous"(the plug-in penalty),"cv","cv_1se", a criterion, or a value.vcov (default "hetero") – The 2SLS regression’s vcov, as for hdfe-stream:
"iid","hetero",{"CRV1": "state"}…cluster (str, optional) – The plug-in penalty’s loadings are clustered by this column; default: the vcov’s cluster, if it is one-way.
weights – As for
lasso_stream(the folds are used only bypenalty="cv").weights_type – As for
lasso_stream(the folds are used only bypenalty="cv").n_folds – As for
lasso_stream(the folds are used only bypenalty="cv").fold_by – As for
lasso_stream(the folds are used only bypenalty="cv").seed – As for
lasso_stream(the folds are used only bypenalty="cv").standardize – As for
lasso_stream(the folds are used only bypenalty="cv").tol – As for
lasso_stream(the folds are used only bypenalty="cv").rigorous_options (dict, optional) – As for
lasso_stream.groups ("factors" or dict, optional) – Group lassos, as in
double_selection_stream: each factor of the controls (and, withselect_instruments, of the instruments) is selected or left out as a block. Not withpenalty="rigorous".sup_score (bool, default False) – Also run the sup-score test (Belloni, Chen, Chernozhukov and Hansen 2012; Chernozhukov, Hansen and Spindler 2015), whose test of the treatment’s effect and confidence set stay valid however weak the instruments are (
result.double_selection.sup_score, aSupScoreTest). It takes one more pass over the data.sup_score_options (dict, optional) –
null(the effect tested; default 0),method("bound", the default: the critical value c Phi^-1(1 - (1 - level) / (2p)) for p instruments, as lassopack’sivlasso, with the confidence set solved exactly; or"bootstrap", the multiplier bootstrap’s p-value, with the set read off the grid),level(0.95),c(1.1),draws(500, for the bootstrap),grid((low, high, points)or a list of values; default the 2SLS estimate plus or minus 20 standard errors, 101 points) andseed(for the bootstrap; defaultseed).**options – hdfe-stream’s options, for the pass and the final regression.
- Returns:
HDFEResult – The 2SLS regression (with
method="partialling_out", of the residuals, so it has the treatment’s coefficient and, without fixed effects, an intercept), with its first stage (first_stage,f_stat_1st_stage) anddouble_selection(aDoubleSelectionIV) saying what was selected for what.
- penalized_stream.double_selection_logit_stream(fml, data, *, controls, unpenalized=None, penalty='rigorous', vcov='hetero', weights=None, weights_type='aweights', standardize=True, tol=1e-07, rigorous_options=None, **options)[source]¶
Post-double-selection for a binary outcome: the logit coefficients of the treatments in
fml, controlling for the controls the lassos select (Belloni, Chernozhukov and Wei 2016; see the module docstring).- Parameters:
fml (str) –
"y ~ d"or"y ~ d | fe": a 0/1 outcome, the treatment(s) and at most one fixed effect.data (str, Path, polars.LazyFrame or polars.DataFrame)
controls (str) – The candidate controls, as a right-hand side.
unpenalized (str or list of str, optional) – Controls always included, as for
double_selection_stream.penalty (str or float, default "rigorous") – The lassos’ penalty:
"rigorous"(the plug-in penalties), an information criterion ("aic","bic","ebic","aicc") or a value (for both the lasso logit and the weighted lassos, on their own scales). Cross-validation is not available here.vcov (default "hetero") – The final logit’s vcov, as for
hdfe_stream.feglm_stream.weights – As for
lasso_logit_stream.weights_type – As for
lasso_logit_stream.standardize – As for
lasso_logit_stream.tol – As for
lasso_logit_stream.rigorous_options (dict, optional) –
candgammaof the lasso logit’s plug-in penalty.**options – Options for the stored rows (
workdir,verbose, …) andn_threads.
- Returns:
hdfe_stream.HDFEResult – The final logit, with
double_selection(aDoubleSelection).
- penalized_stream.double_ml_stream(fml, data, *, controls, unpenalized=None, penalty='cv', l1_ratio=1.0, groups=None, vcov='hetero', n_folds=5, n_repeats=1, fold_by=None, seed=0, weights=None, weights_type='aweights', standardize=True, tol=1e-07, cluster=None, rigorous_options=None, **options)[source]¶
Double/debiased machine learning for the partially linear model, with lasso (or elastic-net) nuisances.
- Parameters:
fml (str) –
"y ~ d | fe1 + fe2": the outcome, the treatment(s) and the fixed effects (partialled out of everything).data (str, Path, polars.LazyFrame or polars.DataFrame)
controls (str) – The controls X, a right-hand side (
"x1 + x2 + i(region)").unpenalized (str or list of str, optional) – Controls left unpenalized in every nuisance lasso.
penalty (default "cv") – The nuisance lassos’ penalty, chosen for each fold on that fold’s training rows:
"cv"(cross-validated over the other folds),"cv_1se", a criterion,"rigorous"(the plug-in penalty) or a value.l1_ratio (float, default 1) – 1 for lasso nuisances; below 1, elastic-net ones.
groups (optional) – As for
lasso_stream(not withpenalty="rigorous").vcov (default "hetero") –
"hetero"or{"CRV1": "cluster"}(one-way; the folds are then made of whole clusters unlessfold_bysays otherwise).n_folds (int, default 5) – Folds of the cross-fitting.
n_repeats (int, default 1) – Repetitions of the cross-fitting with new folds, combined by medians (one more pass over the data each).
fold_by – As for
lasso_stream.seed – As for
lasso_stream.weights – As for
lasso_stream.weights_type – As for
lasso_stream.standardize – As for
lasso_stream.tol – As for
lasso_stream.rigorous_options – As for
lasso_stream.cluster (str, optional) – With
penalty="rigorous": cluster the loadings by this column; default the vcov’s cluster.**options – hdfe-stream’s options.
- Returns:
DoubleMLResult
- penalized_stream.debiased_lasso_stream(fml, data, *, penalty='cv_1se', node_penalty='cv', coefficients=None, vcov='iid', unpenalized=None, weights=None, weights_type='aweights', n_folds=5, fold_by=None, seed=0, standardize=True, tol=1e-07, n_threads=None, **options)[source]¶
The debiased lasso: confidence intervals for a lasso’s coefficients.
- Parameters:
fml (str) – A pyfixest formula, as for
lasso_stream(fixed effects partialled out).data (str, Path, polars.LazyFrame or polars.DataFrame)
penalty (default "cv_1se") – The initial lasso’s penalty:
"cv_1se"(hdi’s default),"cv", an information criterion,"rigorous"or a value.node_penalty (default "cv") – Each nodewise lasso’s penalty, chosen separately for each covariate:
"cv"(lambda_min),"cv_1se", a criterion or a value.coefficients (list of str, optional) – The coefficients to debias; default all the covariates. Each costs one nodewise lasso (on the cross-products, in memory).
vcov (default "iid") –
"iid"(from the cross-products),"hetero"(the robust variance of hdi’srobust=TRUE) or{"CRV1": "cluster"}(one-way); the last two take one more pass over the rows.unpenalized – As for
lasso_stream.weights – As for
lasso_stream.weights_type – As for
lasso_stream.n_folds – As for
lasso_stream.fold_by – As for
lasso_stream.seed – As for
lasso_stream.standardize – As for
lasso_stream.tol – As for
lasso_stream.n_threads (int, optional) – Threads for the nodewise lassos.
**options – hdfe-stream’s options (
workdir,max_memory_gb, …).
- Returns:
DebiasedLassoResult
- penalized_stream.stability_selection_stream(fml, data, *, cutoff=0.75, pfer=1.0, q=None, assumption='unimodal', n_pairs=50, n_shards=20, l1_ratio=1.0, groups=None, unpenalized=None, weights=None, weights_type='aweights', fold_by=None, seed=0, standardize=True, n_lambdas=100, lambda_min_ratio=None, tol=1e-07, n_threads=None, **options)[source]¶
Stability selection with complementary pairs, as stabs computes it.
- Parameters:
fml (str) – A pyfixest formula, as for
lasso_stream.data (str, Path, polars.LazyFrame or polars.DataFrame)
cutoff (float, default 0.75) – A candidate is stable when at least this share of the subsamples select it.
pfer (float, default 1) – The bound on the expected number of false selections; with
cutoff, it sets q. Giveqinstead (andpfer=None) to fix q.q (int, optional) – The candidates selected on each subsample (at most).
assumption ({"unimodal", "none"}, default "unimodal") – Shah and Samworth’s bound under unimodality (stabs’ default), or the bound that needs no assumption, q^2 / ((2 cutoff - 1) p).
n_pairs (int, default 50) – Complementary pairs of half-samples (100 subsamples).
n_shards (int, default 20) – The pieces the rows are split into in the pass (an even number); each half-sample is half of them. By row, or by
fold_by’s groups.l1_ratio – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.groups – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.unpenalized – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.weights – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.weights_type – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.fold_by – As for
lasso_stream. Unpenalized covariates are always kept and are not candidates; withgroups, the candidates are the groups.seed – As for
lasso_stream.standardize – As for
lasso_stream.n_lambdas – As for
lasso_stream.lambda_min_ratio – As for
lasso_stream.tol – As for
lasso_stream.n_threads (int, optional) – Threads for the subsamples’ fits.
**options – hdfe-stream’s options.
- Returns:
StabilityResult