Utilities¶
- logit_stream.etable(models, **kwargs)[source]¶
pf.etablefor streaming results: a regression table ofHDFEResultandHDFEMultimodels, mixed freely with ordinary pyfixest models.A multi-model result expands into one column per model. The spacing of the fixed-effect side is normalized, so
"a + b"and"a+b"share a row (pf.etableitself matches rows on the literal text). Withtype="tex", labels are escaped for LaTeX.- Parameters:
models (HDFEResult, HDFEMulti, or a list of them and pyfixest models) – The models, one column each.
**kwargs – Passed to
pf.etable:type,model_stats,labels,felabels,file_name, …
- Returns:
object – What
pf.etablereturns for thetypeasked for.
Examples
>>> etable([fit1, fit2], type="df", model_stats=["N", "se_type", "r2"])
- logit_stream.bonferroni(models, param)[source]¶
Bonferroni-adjusted p-values for
param = 0across models.Each p-value, from
HDFEResult.tidy, is multiplied by the number of hypotheses (models times parameters), capped at 1. As pyfixest’sbonferroni, which takes one parameter.- Parameters:
- Returns:
polars.DataFrame – One row per model and parameter:
model(its position),fml, thetidycolumns, andBonferroni Pr(>|t|).
- logit_stream.holm(models, param)[source]¶
Holm’s step-down adjusted p-values for
param = 0across models.The p-values are sorted from smallest to largest, the j-th of m is multiplied by m - j + 1, and each adjusted p-value is the running maximum of those, capped at 1. Like Bonferroni’s, the adjustment controls the familywise error rate under any dependence between the tests, and no adjusted p-value is larger than Bonferroni’s, so it rejects at least as often (Holm, 1979).
- Parameters:
models – As in
bonferroni.param – As in
bonferroni.
- Returns:
polars.DataFrame – As in
bonferroni, withHolm Pr(>|t|).
- logit_stream.simulate.simulate_people(n=100000, n_states=51, pumas_per_state=20, puma_sd=0.5, seed=0)[source]¶
A simulated population of
npeople.Columns:
person_id,state,puma(nested in state;n_states * pumas_per_stateof them, with Zipf-like sizes),age(18-90),age10(age / 10),female(0/1),log_income,owner(0/1),urban(0/1),weight(a survey-style weight), and the outcomeshispanic(0/1),race(one ofRACES) andeducation(an Enum ofEDUCATION, ordered).Each outcome follows a logit model of the covariates (
truth_people) plus PUMA effects with standard deviationpuma_sd(one per race equation, one each for education and Hispanic origin).
- logit_stream.simulate.truth_people()[source]¶
The coefficients
simulate_peopledraws from (before the PUMA effects).
- logit_stream.simulate.simulate_choices(n_cases=10000, alternatives=('train', 'metro', 'car'), beta_cost=-1.1, beta_time=-1.3, p_unavailable=0.15, seed=0, *, nests=None, lambdas=0.5, tasks=1, sd_time=0.0)[source]¶
Long-format mode-choice data for the conditional, nested and mixed logit.
One row per available alternative of each choice set:
case,person(the chooser),alt,costandtime(in 100s, as Swissmetro’s are usually scaled),income(of the chooser), andchosen(1 for the alternative chosen). Each alternative but the first is unavailable with probabilityp_unavailable. Utilities: beta_cost cost + beta_time time + an alternative-specific constant (0 for the first alternative, then evenly from 0.4 to -0.3) + 0.3 income for the last alternative, plus Gumbel noise: the conditional logit.- Parameters:
nests (dict, optional) –
{nest: [alternatives]}, or with nests of nests as dicts, asnlogit_streamtakes it, every alternative in one nest: the choices are drawn from that nested logit (RU2) instead.lambdas (float or dict, default 0.5) – The nests’ dissimilarity parameters, one for all or
{nest: lambda}(a nest of one child has none).tasks (int, default 1) – Choice sets per chooser:
personiscase // tasks, andincomeis the chooser’s.sd_time (float, default 0) – The standard deviation of the time coefficient across choosers: each draws beta_time + sd_time z, z standard normal, for all their choice sets (the mixed logit with a panel). Not with
nests.
- logit_stream.simulate.simulate_panel(n_units=10000, periods=5, beta=(1.0, -0.5), unit_sd=1.0, corr=0.5, seed=0)[source]¶
A balanced panel with a binary outcome and unit effects, for the fixed-effects logit.
Columns:
unit,period(1 toperiods),x1,x2andy, with P(y = 1) = logistic(a_unit + beta[0] x1 + beta[1] x2). The unit effects a are normal with sdunit_sd, andx1iscorrtimes the unit’s effect plus standard normal noise, so a model that ignores the effects, or treats them as independent of the covariates (random effects), is biased;x2is independent of them.