Results¶
The result classes subclass hdfe-stream’s RegressionResult, so the
reporting methods (summary, tidy, confint, wald_test, with_vcov,
summary_dict, summary_json, to_pyfixest) are hdfe-stream’s own and
behave identically. The binary logit returns hdfe-stream’s HDFEResult
(its reference).
- class logit_stream.MultinomialLogitResult[source]¶
The result of
mlogit_stream.The coefficients are those of each non-base level against the base level (the first of
levels), named"<level>:<covariate>"; the base level’s are zero. With an absorbed fixed effect, each of its levels has an effect for every outcome level but its reference, seefixef.- Attributes:
levels (list) – The outcome’s levels, base first.
base (object) – The base level.
(and those of `LogitResult`)
- summary(logger=None, level=20)[source]¶
Print the report, or write it to
logger(one record, atlevel).
- summary_dict(coefficients=False)[source]¶
The model-level information of summary() as a dict of plain Python types (JSON-ready; nan is None). Fit statistics not defined for the model (e.g. r2 for a GLM) are absent.
coefficients=Trueadds thetidy()table as a list of row dicts.
- summary_json(path=None, indent=2, coefficients=False)[source]¶
The model-level information of summary() as a JSON string (see
summary_dict); withpath, also written there as UTF-8. Reload withjson.loadsorjson.load.
- tidy()[source]¶
Coefficient table. p-values use the t distribution with
df_tdegrees of freedom, or the normal for GLMs, as in pyfixest.
- coef_matrix()[source]¶
The coefficients as a table: a row per covariate, a column per non-base level.
- confint(alpha=0.05, keep=None, drop=None, exact_match=False, joint=False, reps=10000, seed=None)[source]¶
Confidence intervals, one coefficient at a time or simultaneous.
Pointwise intervals use the t distribution with
df_tdegrees of freedom, or the normal for GLMs, astidydoes. Withjoint=True, the intervals cover all the selected coefficients at once with probability 1 - alpha: the critical value is the 1 - alpha quantile of the largest absolute t statistic, simulated from the normal with the coefficients’ correlation (the multiplier bootstrap of pyfixest’sconfint(joint=True); Chernozhukov et al., Applied Causal Inference Powered by ML and AI, remark 4.4.1).- Parameters:
alpha (float, default 0.05) – One minus the coverage.
keep (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a
keeppattern, in the order of the patterns (all, by default), less those matching adroppattern. A joint interval covers exactly these.drop (str or list of str, optional) – Regular expressions selecting coefficients by name, as in pyfixest: those matching a
keeppattern, in the order of the patterns (all, by default), less those matching adroppattern. A joint interval covers exactly these.exact_match (bool, default False) – Match names exactly instead of as regular expressions.
joint (bool, default False) – Simultaneous intervals.
reps (int, default 10000) – Draws for the joint critical value.
seed (int, optional) – Seed for those draws.
- Returns:
polars.DataFrame –
Coefficientand the lower and upper bounds, in columns named by their percentiles ("2.5%","97.5%").
- wald_test(R=None, q=None, distribution=None, keep=None, drop=None, exact_match=False)[source]¶
Wald test of the linear hypothesis R beta = q, under the current vcov (see
with_vcov).By default the hypothesis is that every coefficient is zero;
keepanddropnarrow it to some of them (the coefficients of an event study’s leads, say), andRandqstate any other.The statistic is W = (R b - q)’ (R V R’)^+ (R b - q), and F = W / m for m restrictions. F is referred to the F distribution with m and
df_tdegrees of freedom, so that for one coefficient the p-value is the onetidyreports; W, to the chi-squared with m. Two differences from pyfixest’swald_test: it reports chi-squared whenever R is not the identity or q is not zero, where this test reports what is asked for; and its F’s denominator degrees of freedom, without clustering, subtract every fixed-effect level, including the redundant ones thatdf_tdoes not.- Parameters:
R (array-like, optional) – m x k, one row per restriction, one column per coefficient in the order of
coefnames; a 1-d array is one restriction.q (float or array-like, optional) – The m right-hand sides; zero by default.
distribution ({"F", "chi2"}, optional) – Default “F” for OLS and “chi2” for GLMs, whose
tidyp-values are normal.keep – Without
R: test that the coefficients they select are zero (orq), as inconfint.drop – Without
R: test that the coefficients they select are zero (orq), as inconfint.exact_match – Without
R: test that the coefficients they select are zero (orq), as inconfint.
- Returns:
dict –
statistic(F or W),pvalue,df1(m),df2(df_tfor F, None for chi-squared) anddistribution.
- with_vcov(vcov)[source]¶
A copy of this result with another of the vcovs computed at fit time:
"iid","hetero", or a clustering given as{"CRV1": var}or"CRV1:var"(likewise CRV3, when it was the fit’s vcov). Ask for clusterings at fit time withvcov=orcluster=.
- predict(newdata=None, type='response', prefix=None)[source]¶
Predictions as a lazy frame:
newdata(default: the fit’s source, every row) with columns added.- type=”response”
The probability of each level,
prob_<level>.- type=”link”
The linear predictor of each non-base level,
xb_<level>(with its fixed effect).- type=”class”
The most probable level,
predicted.
A row with a null or non-finite covariate, or a fixed-effect level the fit did not estimate, gets nulls.
prefixrenames the columns’ prefix (or, for “class”, the column).
- resid()[source]¶
The estimation sample, lazily:
row_id(the row’s position in the source), the outcome, each level’s probabilityprob_<level>, and each level’s response residualresid_<level>= 1[y = level] - prob. Computed from the source when collected (nothing is stored).
- fixef(name=None)[source]¶
The absorbed fixed effects: one row per level of the dimension, with its effects (see the subclass) and its number of observations. The table is held in memory; this is a lazy view of it.
- ranef(name=None)[source]¶
A random grouping’s predicted intercepts (their modes given the data, the conditional means’ Laplace approximation): one row per group, with one column per outcome level (the base level’s 0) for the multinomial logit, one for the ordered logit, and the group’s number of observations.
predictadds every grouping’s to the linear predictor, using 0 for a group the fit did not see.name: the grouping, needed when there are several.
- varcorr()[source]¶
The random intercepts’ standard deviations and correlations, one row each per grouping, with their standard errors and 95% Wald intervals on the scales that respect their bounds (log sd, Fisher’s z of a correlation).
- sample(check=True)[source]¶
The source, lazily, with
row_id(the row’s position) first and two columns added:in_sample, anddropped_because(null for the rows used;"missing"for a null or non-finite value in a column the model uses,"incomplete set"for the other alternatives of a choice set with such a row (conditional logit, withoutaltwise=True),"separation"for a fixed-effect level whose outcome never varies).
- to_pyfixest()[source]¶
A pyfixest
Feols(Feivfor IV) view of this result, forpf.etable,pf.summary,pf.coefplotandpf.iplot. Only the stored results are available; methods that need the data (recomputing the vcov, the wild bootstrap) are not, andpredictis this result’s ownpredict.
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, levels, base=None)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.OrderedLogitResult[source]¶
The result of
ologit_stream.P(y <= level j) = F(cut_j - x’b), F the logistic distribution: positive coefficients move probability toward the higher levels. The cutpoints are the last coefficients,
cut1…cut{J-1},cut_jbetween levels j and j + 1. With an absorbed fixed effect,cut1is normalized to zero (the effects carry the location) and is not reported.- Attributes:
levels (list) – The outcome’s levels, lowest first.
(and those of `LogitResult`)
- property cutpoints¶
All J - 1 cutpoints (with a fixed effect, the first is 0).
- predict(newdata=None, type='response', prefix=None)[source]¶
Predictions as a lazy frame, as
MultinomialLogitResult.predict:type="response"the probability of each level (prob_<level>),"link"the linear predictor x’b (with the fixed effect),"class"the most probable level.
- resid()[source]¶
The estimation sample, lazily:
row_id, the outcome,xb, each level’s probability and response residual (1[y = level] - prob), and two residuals for the ordered outcome as a whole:resid_prob, the probability-scale residual P(Y < y) - P(Y > y) (Li and Shepherd 2012; statsmodels’resid_prob), in [-1, 1] and mean zero; andresid_gen, the generalized residual d log P(y) / d xb (Stata’spredict, scores), positive when the outcome is higher than the fit expects. For the logit the two are equal (both are F(cut_{y-1} - xb) + F(cut_y - xb) - 1, since the logistic density is F (1 - F)); for the probit they differ.
- fixef(name=None)[source]¶
The absorbed fixed effects: one row per level of the dimension, with its effects (see the subclass) and its number of observations. The table is held in memory; this is a lazy view of it.
- ranef(name=None)[source]¶
A random grouping’s predicted intercepts (their modes given the data, the conditional means’ Laplace approximation): one row per group, with one column per outcome level (the base level’s 0) for the multinomial logit, one for the ordered logit, and the group’s number of observations.
predictadds every grouping’s to the linear predictor, using 0 for a group the fit did not see.name: the grouping, needed when there are several.
- varcorr()[source]¶
The random intercepts’ standard deviations and correlations, one row each per grouping, with their standard errors and 95% Wald intervals on the scales that respect their bounds (log sd, Fisher’s z of a correlation).
- sample(check=True)[source]¶
The source, lazily, with
row_id(the row’s position) first and two columns added:in_sample, anddropped_because(null for the rows used;"missing"for a null or non-finite value in a column the model uses,"incomplete set"for the other alternatives of a choice set with such a row (conditional logit, withoutaltwise=True),"separation"for a fixed-effect level whose outcome never varies).
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, levels)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.OrderedProbitResult[source]¶
The result of
oprobit_stream: asOrderedLogitResult, with F the standard normal distribution.- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, levels)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.ConditionalLogitResult[source]¶
The result of
clogit_stream: McFadden’s conditional logit on long-format data, one row per alternative in each choice set.- Attributes:
case (list of str) – The columns that identify a choice set.
n_cases (int) – Choice sets used.
n_obsis the same number (the sum of the weights with frequency weights);diagnostics["n_rows"]counts the rows (alternatives).(and those of `LogitResult`)
- predict(newdata=None, type='response', prefix=None, case=None)[source]¶
Predictions as a lazy frame, one per row (alternative):
type="response"the choice probability within the row’s choice set (prob),"link"the utility x’b (xb). The choice sets are identified bycase(default: the fit’s). The probabilities are a window over each set, which Polars evaluates set by set.
- resid()[source]¶
The estimation sample, lazily, a row per alternative:
row_id, the case columns, the outcome,xb,proband the response residualresid= y - prob.
- sample(check=True)[source]¶
The source, lazily, with
row_id(the row’s position) first and two columns added:in_sample, anddropped_because(null for the rows used;"missing"for a null or non-finite value in a column the model uses,"incomplete set"for the other alternatives of a choice set with such a row (conditional logit, withoutaltwise=True),"separation"for a fixed-effect level whose outcome never varies).
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, case, n_cases=0)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.ConditionalFELogitResult[source]¶
The result of
cfelogit_stream: Chamberlain’s conditional fixed-effects logit. The unit effects are conditioned out, not estimated, so there are none to report or predict with:predictgives the linear predictor x’b only (the probabilities need the unit’s effect), andloglikis the conditional log-likelihood (its null: every arrangement of a unit’s 1s equally likely).- Attributes:
unit (list of str) – The columns that identify a unit (the formula’s fixed effect).
n_units (int) – Units whose outcome varies, the ones the likelihood uses;
n_obsis the same number (the sum of their weights with frequency weights).n_units_dropped (int) – Units whose outcome is all 0 or all 1, which carry no information.
n_rows (int) – The rows of the units used.
(and those of `LogitResult`)
- predict(newdata=None, type='link', prefix=None)[source]¶
The linear predictor x’b (
xb), lazily; onlytype="link": the unit effects were conditioned out, so probabilities cannot be formed.
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, unit, n_units=0, n_units_dropped=0, n_rows=0)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.MixedLogitResult[source]¶
The result of
mixlogit_stream(prototype).The coefficients are the fixed coefficients and the means of the random ones (named as the covariates; for a lognormal coefficient, the mean of its log), then the standard deviations of the random ones,
"sd.<name>"(of the log, for a lognormal one). The sign of a standard deviation is not identified, so its absolute value is reported (the signed estimates are indiagnostics["sd_signed"]; the standard errors are the same).n_obsis the number of choosers (panels), the unit of the likelihood; the robust variance is clustered by them,"CRV1:<panel>"("hetero"withoutpanel, each choice set its own chooser).- Attributes:
case, panel (list of str) – The columns identifying the choice sets and the choosers.
n_cases, n_panels (int) – Their numbers.
random (dict) – Each random coefficient’s distribution.
draws, halton, seed, drop – The simulation: draws per chooser, Halton or pseudo-random, the pseudo-random seed, the Halton points discarded at the start.
loglik_clogit (float) – The conditional logit’s log-likelihood (the starting point).
(and those of `LogitResult`)
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, case, panel, n_cases=0, n_panels=0, random=<factory>, draws=0, halton=True, seed=0, drop=100, loglik_clogit=nan)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.NestedLogitResult[source]¶
The result of
nlogit_stream(prototype).The coefficients are those of the utilities, then each nest’s dissimilarity parameter,
"lambda.<nest>", in the order ofnests=(RU2: the model is the conditional logit when they are all 1; nests of one child have none).n_obsis the number of choice sets (their weight, with frequency weights).- Attributes:
case (list of str) – The columns identifying the choice sets.
alt (str) – The column naming the alternatives.
nests (dict) – Each nest’s alternatives (all of them, for a nest of nests).
n_cases (int) – The number of choice sets.
loglik_clogit (float) – The conditional logit’s log-likelihood (the starting point).
(and those of `LogitResult`)
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None, case, n_cases=0, alt, nests=<factory>, loglik_clogit=nan)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.LogitResult[source]¶
What every logit result has; see the subclasses.
- Attributes:
fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs, n_clusters, collin_vars, diagnostics, weights, weights_type – As in
hdfe_stream.HDFEResult.df_tis used only bywald_testwithdistribution="F"; p-values and intervals are normal.model (str) –
"multinomial logit","ordered logit"or"conditional logit".loglik (float) – The log-likelihood at the estimates (without the L2 or Firth penalty).
loglik_null (float) – The null model’s: the outcome’s sample shares (multinomial, ordered), or equal probabilities within each choice set (conditional).
pseudo_r2 (float) – McFadden’s, 1 - loglik / loglik_null: with a fixed effect, it credits the covariates and the fixed effect together.
loglik_fe_null (float) – With an absorbed fixed effect, the log-likelihood of the model with it and no covariates: each level’s outcome shares (multinomial), or a location per level and common cutpoints (ordered); computed from the outcome counts per level, without reading the data. Else nan.
pseudo_r2_within (float) – 1 - loglik / loglik_fe_null: what the covariates add beyond the fixed effect (fixest’s “within pseudo R2”); nan without one.
aic, bic (float) – -2 loglik + 2 k and -2 loglik + k log N, with k the estimated parameters, fixed effects included.
n_params (int) –
fe_names (list of str) – The absorbed fixed-effect dimension, if any.
random_effects (dict) – With random intercepts (
random=): the grouping (group), its number of groups, the covariance of the intercepts (Sigma, over the non-base outcome levels; 1 x 1 for the ordered logit), its form (cov), the outcome levels it is over, the method, and Sigma’s standard errors:Sigma_se(each element’s),sdandsd_se,corrandcorr_se(delta method), andvcov_Sigmawith itsSigma_params(the (j, l) elements it is over). Empty otherwise.n_levels (dict) – Its number of levels.
l2 (float) – The L2 penalty (0: maximum likelihood).
firth (bool) – Whether the estimates maximize Firth’s penalized likelihood (
firth=True).converged (bool) – Whether Newton’s method met its tolerance.
- __init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', model, loglik, loglik_null, pseudo_r2, aic, bic, n_params, converged, fe_names=<factory>, n_levels=<factory>, random_effects=<factory>, l2=0.0, loglik_fe_null=nan, pseudo_r2_within=nan, firth=False, _spec=None)¶
- classmethod __new__(*args, **kwargs)¶
- class logit_stream.LogitMulti[source]¶
Results of a formula that expands to several models (several outcomes,
sw(),csw(), …): iterate over it, or take one withfetch_model;len()counts them.- summary(logger=None, level=20, per_model=False)[source]¶
Print all reports, or write them to
logger: one record in total, or one per model with per_model=True.
- summary_json(path=None, indent=2, coefficients=False)[source]¶
JSON object keyed by formula, each value as
HDFEResult.summary_json; withpath, also written there.
- classmethod __new__(*args, **kwargs)¶