Cross-Sectional Model

SW2023Model

class sw2023.SW2023Model(X, Y, direction='mean', method='HMS', h=None, log_transform=True, standardize=True, bandwidth_method='silverman')[source]

Bases: object

Simar & Wilson (2023) nonparametric multiple-output stochastic frontier model.

Parameters:
  • X (array-like (n, p) inputs)

  • Y (array-like (n, q) outputs)

  • direction ('mean' | 'median' | array (p+q,) direction vector)

  • method ('SVKZ' | 'HMS' inefficiency estimation method)

  • h (bandwidth (if None, Silverman rule is applied automatically))

__repr__()[source]

Return repr(self).

fit(verbose=True)[source]

Estimate the SW(2023) nonparametric stochastic frontier model.

Executes Steps 1–10 of Simar & Wilson (2023): data preprocessing, direction-vector rotation, three-moment LLLS regressions with LOO-CV bandwidth selection, sigma_eta estimation (SVKZ or HMS), frontier recovery, and JLMS individual efficiency scoring.

Parameters:

verbose (bool, default True) – If True, print progress messages during estimation.

Returns:

self – Fitted model. Key attributes set after calling fit():

phi_hat_ndarray, shape (n,)

Estimated frontier values at each observation.

efficiency_ndarray, shape (n,)

JLMS efficiency scores exp(-eta_hat) in (0, 1].

sigma_eta_ndarray, shape (n,)

Estimated inefficiency std dev at each observation.

r1_, r2_, r3_ndarray, shape (n,)

Estimated first, second, and third conditional moments.

h_ndarray, shape (n,)

Hat-matrix leverages for r1 regression (used in CI).

Return type:

SW2023Model

summary()[source]

Print a summary of estimation results.

confint_asymptotic(alpha=0.05)[source]

Asymptotic normal confidence intervals (SW 2023 CLT + delta method).

SW(2023) Eq.(3.8) CLT:

(nh^{d-1})^{1/2} (r̂_j(z) − r_j(z)) →^L N(0, s²_j(z))

Hat-matrix based variance estimation:

AVar(r̂_1(z_i)) ≈ h_ii(r1) × r̂_2(z_i) AVar(r̂_3(z_i)) ≈ h_ii(r3) × V̂ar(ε³ | Z=z_i)

φ̂(z) = r̂_1(z) + ||d|| √(2/π) σ̂_η(z) delta method:

∂φ/∂r1 = 1 ∂φ/∂r3 = −||d|| √(2/π) / (3 × A3_PLUS × σ̂²_η) [when r3 ≤ 0]

Note: Asymptotic CI is valid when n is sufficiently large.

For small samples, bootstrap_sw() CI is more appropriate.

Parameters:

alpha (significance level (1-alpha confidence interval))

Returns:

phi_hat_ci : (n, 2) r1_ci : (n, 2) r3_ci : (n, 2) se_phi : (n,) standard error se_r1 : (n,) se_r3 : (n,) alpha : float

Return type:

ConfintResult

predict_at(Z_eval, U_eval=None)[source]

Predict at new evaluation points Z_eval using the fitted model.

Used during bootstrap CI computation: fit on bootstrap sample, then evaluate at the original Z points.

Parameters:
  • Z_eval ((m, d) evaluation points (rotated coordinates, same as training Z))

  • U_eval ((m,) observed directional distances (if provided, efficiency is also computed))

Returns:

dict

Return type:

phi_hat, sigma_eta, sigma_eps, mu_eta, [efficiency, eta_hat]

results_dataframe()[source]

Return estimation results as a DataFrame.

plot_efficiency(bins=30, figsize=(7, 4), ax=None)[source]

Histogram of efficiency scores with mean and median lines.

Parameters:
  • bins (int, default 30)

  • figsize (tuple, default (7, 4))

  • ax (matplotlib Axes or None) – If provided, plot into this axes; otherwise a new figure is created.

Returns:

fig, ax

Return type:

matplotlib Figure and Axes

plot_frontier(dim=0, figsize=(7, 5), ax=None)[source]

Scatter plot of U vs Z[dim] with the estimated frontier phi_hat(Z).

Points are colour-coded by efficiency score (red = inefficient, green = efficient).

Parameters:
  • dim (int, default 0) – Index of the Z dimension to use as the x-axis.

  • figsize (tuple, default (7, 5))

  • ax (matplotlib Axes or None)

Returns:

fig, ax

Return type:

matplotlib Figure and Axes

plot_diagnostics(figsize=(12, 9))[source]

Comprehensive diagnostic panel (2×2 layout).

Panels

(top-left) Efficiency distribution (top-right) Efficiency ranking (caterpillar) (bottom-left) Residual distribution (eps = U − r̂₁) (bottom-right) Wrong-skewness diagnostic (r̂₃ sign)

param figsize:

type figsize:

tuple, default (12, 9)

returns:

fig

rtype:

matplotlib Figure

bootstrap(B=200, alpha=0.05, bandwidth_method='silverman', seed=None, verbose=True)[source]

Pairs bootstrap confidence intervals for this fitted model.

Resamples (X, Y) with replacement, re-estimates the model using the same fixed direction vector and preprocessing, then evaluates each bootstrap estimate at the original data points. Yields per-observation CIs for phi_hat(z), sigma_eta(z), and individual efficiency, as well as a CI for the mean efficiency.

Parameters:
  • B (int, default 200) – Number of bootstrap draws.

  • alpha (float, default 0.05) – Significance level; produces (1 - alpha) confidence intervals.

  • bandwidth_method ({'silverman', 'loocv'}, default 'silverman') – Bandwidth selection for each bootstrap replicate. ‘silverman’ is strongly recommended here — LOO-CV per replicate is very slow.

  • seed (int or None) – Random seed for reproducibility.

  • verbose (bool, default True) – Print progress messages.

Returns:

Object with attributes phi_hat_ci, eff_mean_ci, eff_individual_ci, sigma_eta_ci, and a summary() method.

Return type:

BootstrapResult

See also

confint_asymptotic

faster asymptotic alternative (large n).