API reference#

The public interface consists of the local-projection estimator, its plotting helper, and the warning emitted for clustering dimensions with few groups.

LocalProjection#

class fastlp.LocalProjection(*, horizons, covariance='cluster', hac_lags=None, hac_kernel='bartlett', hac_debias=True, cluster_correction='cr1', alpha=0.05, demean_tol=1e-10, max_iter=10000, sample='common', response='level', retain_residuals=True, memory_budget=None, demean_acceleration='irons_tuck', few_cluster_threshold=50, singleton_policy='drop', fe_dof='exact', cluster_df='nonnested', cluster_group_adjustment='min', cluster_inference='t')#

Fast local projections estimator class.

Estimate the impulse response at each horizon.

Parameters:
  • horizons (int)

  • covariance (str)

  • hac_lags (int | None)

  • hac_kernel (Kernel)

  • hac_debias (bool)

  • cluster_correction (str)

  • alpha (float)

  • demean_tol (float)

  • max_iter (int)

  • sample (str)

  • response (str)

  • retain_residuals (bool)

  • memory_budget (int | str | None)

  • demean_acceleration (str)

  • few_cluster_threshold (int | None)

  • singleton_policy (str)

  • fe_dof (str)

  • cluster_df (str)

  • cluster_group_adjustment (str)

  • cluster_inference (str)

__init__(*, horizons, covariance='cluster', hac_lags=None, hac_kernel='bartlett', hac_debias=True, cluster_correction='cr1', alpha=0.05, demean_tol=1e-10, max_iter=10000, sample='common', response='level', retain_residuals=True, memory_budget=None, demean_acceleration='irons_tuck', few_cluster_threshold=50, singleton_policy='drop', fe_dof='exact', cluster_df='nonnested', cluster_group_adjustment='min', cluster_inference='t')#
Parameters:
  • horizons (int)

  • covariance (str)

  • hac_lags (int | None)

  • hac_kernel (Literal['bartlett', 'parzen', 'quadratic_spectral'])

  • hac_debias (bool)

  • cluster_correction (str)

  • alpha (float)

  • demean_tol (float)

  • max_iter (int)

  • sample (str)

  • response (str)

  • retain_residuals (bool)

  • memory_budget (int | str | None)

  • demean_acceleration (str)

  • few_cluster_threshold (int | None)

  • singleton_policy (str)

  • fe_dof (str)

  • cluster_df (str)

  • cluster_group_adjustment (str)

  • cluster_inference (str)

Return type:

None

fit(data, *, column_names=None, outcome, shock, controls=(), outcome_lags=0, shock_lags=0, control_lags=0, unit, time, fixed_effects=(), cluster=None, progress=False, progress_callback=None)#

Fit local projections.

NumPy input must be a two-dimensional array accompanied by one unique name per column through column_names. It is converted to pandas at the input boundary; dataframe inputs must not supply column_names.

A scalar lag setting includes all lags from one through that value; sequences select an arbitrary positive lag grid. For shocks and controls, a mapping can assign a separate setting to each column. Lag numbers must fit in signed int64; scalar lag counts are limited to 10,000 to avoid expanding an impractically large feature grid. Lags use exact within-unit calendar matches at time - lag. Rows without every requested lag are not used as LP anchors, but remain available as future outcomes.

memory_budget bounds a conservative allocation plan for owned frames, alignment, results and numerical workspaces. Too-small budgets fail before panel preparation; remaining space determines batch size. It is not a process-RSS limit: caller input, Python/allocator overhead and private library workspaces are excluded.

Parameters:
  • data (Any)

  • column_names (Sequence[str] | None)

  • outcome (str)

  • shock (str | Interaction | Sequence[str | Interaction])

  • controls (Sequence[str | Interaction])

  • outcome_lags (int | Sequence[int])

  • shock_lags (int | Sequence[int] | Mapping[str, int | Sequence[int]])

  • control_lags (int | Sequence[int] | Mapping[str, int | Sequence[int]])

  • unit (str)

  • time (str)

  • fixed_effects (Sequence[str | FixedEffect])

  • cluster (str | tuple[str, ...] | Sequence[str | tuple[str, ...]] | None)

  • progress (bool)

  • progress_callback (Callable[[ProgressEvent], None] | None)

Return type:

LocalProjection

plot_irf(coefficient=None, **kwargs)#

Return a publication-oriented Matplotlib impulse-response plot.

Parameters:
  • coefficient (str | None)

  • kwargs (object)

property irfplot#

Lazily create and cache the default impulse-response plot axes.

to_frame()#

Return coefficient paths in tidy long form.

Return type:

DataFrame

summary()#

Return a compact textual summary.

Return type:

str

Plotting function#

fastlp.plot_irf(fitted, coefficient=None, *, at=None, levels=None, ax=None, figsize=(8.0, 4.8), title=None, xlabel='Horizon', ylabel=None, color='#2563eb', band_color='#bfdbfe', band_alpha=0.55, marker='o', linewidth=2.0, markersize=5.0, show_zero_line=True, show=False)#

Plot one fitted impulse response with its pointwise confidence band.

The estimator’s configured confidence level is used. When a model has multiple shocks and coefficient is omitted, the first supplied shock is plotted. The returned Matplotlib axes can be further customized or exported through ax.figure.savefig(...).

Parameters:
  • fitted (LocalProjection)

  • coefficient (str | None)

  • at (Sequence[float] | None)

  • levels (Sequence[object] | None)

  • ax (Axes | None)

  • figsize (tuple[float, float])

  • title (str | None)

  • xlabel (str)

  • ylabel (str | None)

  • color (str)

  • band_color (str)

  • band_alpha (float)

  • marker (str)

  • linewidth (float)

  • markersize (float)

  • show_zero_line (bool)

  • show (bool)

Return type:

Axes

Warnings#

class fastlp.FewClustersWarning#

Cluster-robust inference may be unreliable with few clusters.