Utilities

logit_stream.etable(models, **kwargs)[source]

pf.etable for streaming results: a regression table of HDFEResult and HDFEMulti models, 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.etable itself matches rows on the literal text). With type="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.etable returns for the type asked 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 = 0 across models.

Each p-value, from HDFEResult.tidy, is multiplied by the number of hypotheses (models times parameters), capped at 1. As pyfixest’s bonferroni, which takes one parameter.

Parameters:
  • models (HDFEResult, HDFEMulti, or a list of them) – The models.

  • param (str or list of str) – The coefficient(s) tested in every model; each must be in every model.

Returns:

polars.DataFrame – One row per model and parameter: model (its position), fml, the tidy columns, and Bonferroni Pr(>|t|).

logit_stream.holm(models, param)[source]

Holm’s step-down adjusted p-values for param = 0 across 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:
Returns:

polars.DataFrame – As in bonferroni, with Holm 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 n people.

Columns: person_id, state, puma (nested in state; n_states * pumas_per_state of 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 outcomes hispanic (0/1), race (one of RACES) and education (an Enum of EDUCATION, ordered).

Each outcome follows a logit model of the covariates (truth_people) plus PUMA effects with standard deviation puma_sd (one per race equation, one each for education and Hispanic origin).

logit_stream.simulate.truth_people()[source]

The coefficients simulate_people draws 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, cost and time (in 100s, as Swissmetro’s are usually scaled), income (of the chooser), and chosen (1 for the alternative chosen). Each alternative but the first is unavailable with probability p_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, as nlogit_stream takes 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: person is case // tasks, and income is 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 to periods), x1, x2 and y, with P(y = 1) = logistic(a_unit + beta[0] x1 + beta[1] x2). The unit effects a are normal with sd unit_sd, and x1 is corr times 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; x2 is independent of them.