Estimation of cross-sectional and panel stochastic frontier models
Project description
Stochastic Frontier Analysis
A Python package for estimating cross-sectional and panel-data stochastic frontier models using maximum-likelihood and Bayesian methods.
Features
The package currently supports:
- classical normal linear regression;
- cross-sectional normal-exponential stochastic frontier models;
- cross-sectional normal-half-normal stochastic frontier models;
- panel normal-exponential stochastic frontier models;
- panel normal-half-normal stochastic frontier models;
- panel Gaussian random-effects models;
- maximum-likelihood estimation;
- Bayesian posterior estimation;
- marginal data density calculations;
- technical inefficiency and efficiency estimation.
The current release focuses on estimating individual stochastic frontier models. Model-search and Bayesian model-averaging procedures may be added in future versions.
Installation
Install the package from PyPI with:
pip install stochastic-frontier-analysis
For local development, clone the repository and install it in editable mode from the project root:
python -m pip install -e .
To install the optional dependencies used by the examples:
python -m pip install -e ".[examples]"
Although the distribution name is stochastic-frontier-analysis, the Python import package is NAMED short: sfa.
Package Structure
The main public modules are:
sf_model— model estimation and presentation of estimation results;inefficiency— estimation of inefficiency and technical-efficiency scores.
They can be imported with:
from sfa import sf_model, inefficiency
The estimation and efficiency calculations are kept separate. This allows users to estimate and compare alternative model specifications before computing efficiency scores for the preferred model.
Available Models
The argument sfa_opt selects the model specification:
| Value | Model |
|---|---|
0 |
Classical normal linear regression |
1 |
Cross-sectional normal-exponential stochastic frontier |
2 |
Cross-sectional normal-half-normal stochastic frontier |
3 |
Panel normal-exponential stochastic frontier |
4 |
Panel normal-half-normal stochastic frontier |
5 |
Panel Gaussian random-effects model |
Estimating a Model
The main estimation function is:
model = sf_model.fit(X, y, n, T, sfa_opt, dec_crit, if_mdd)
It returns a results object containing parameter estimates, standard errors, model-fit measures, and other diagnostics.
Depending on the selected options, the returned object may include:
- maximum-likelihood estimates;
- Bayesian posterior estimates;
- Akaike information criterion;
- Bayesian information criterion;
- maximized log-likelihood;
- maximized log-posterior;
- marginal data density;
- confidence or credible intervals;
- additional summary statistics.
Display the estimation results with:
model.summary()
Because summary() prints the results directly, it should not be wrapped in print().
Function Arguments
X
The regressor matrix.
When an intercept is required, X must already contain a column of ones. It is recommended to place the intercept in the first column:
X = np.column_stack((np.ones(len(y)), regressors))
y
The dependent variable. Its observations must be ordered consistently with the rows of X.
n
The number of cross-sectional units.
For a cross-sectional model, this usually equals the total number of observations. For a panel model, it is the number of units.
T
The number of time periods.
For cross-sectional models:
T = 1
For panel models, observations should be ordered by unit and then by time:
unit 1: period 1, ..., period T
unit 2: period 1, ..., period T
...
unit n: period 1, ..., period T
dec_crit
The principal model-fit criterion:
dec_crit = 1
uses the marginal data density, whereas:
dec_crit = 0
uses the Bayesian information criterion.
The marginal data density provides a fully Bayesian measure of model fit, while BIC is faster to compute.
if_mdd
Controls whether Bayesian calculations and the marginal data density are computed:
if_mdd = 1
enables Bayesian inference and marginal data density calculations.
if_mdd = 0
uses maximum-likelihood estimation without calculating the marginal data density.
For a fully Bayesian analysis:
dec_crit = 1
if_mdd = 1
For faster estimation based on BIC:
dec_crit = 0
if_mdd = 0
Basic Example
import numpy as np
from sfa import sf_model, inefficiency
# Dependent variable
y = np.asarray(y, dtype=float).reshape(-1)
# Regressor matrix with the intercept in the first column
X = np.column_stack((np.ones(len(y)), x1, x2, x3))
# Cross-sectional normal-exponential stochastic frontier
n = len(y)
T = 1
sfa_opt = 1
# Fully Bayesian model evaluation
dec_crit = 1
if_mdd = 1
model = sf_model.fit(X, y, n, T, sfa_opt, dec_crit, if_mdd)
model.summary()
# Efficiency scores based on Bayesian estimates
bayes = 1
u, te = inefficiency.jondrow(model, X, y, bayes)
Set:
bayes = 0
to calculate scores using the maximum-likelihood estimates.
Example Data
Example scripts and datasets are stored in the examples directory. Just copy-paste them (with data folder) into your working directory and run there, or run them directly from the package directory.
A portable way to load an Excel file from examples/data is:
import os
import pandas as pd
my_dir = os.path.dirname(os.path.abspath(__file__))
data_path = os.path.join(my_dir, 'data', 'dane.xlsx')
data = pd.read_excel(data_path, header=None, sheet_name=sf_label)
This works on Windows, macOS, and Linux.
Complete Examples
The repository includes complete examples based on simulated and empirical data, including data preparation, model estimation, result summaries, and efficiency-score calculations.
See the files in:
examples/
Project Background
This Python implementation is based on code developed for a broader MATLAB project on stochastic frontier Bayesian model averaging. The MATLAB implementation includes the full model-search and Bayesian model-averaging procedures, whereas this Python package currently focuses on single-model estimation.
MATLAB package:
https://github.com/KamilMakiela/SF-BMA
Python package:
https://github.com/KamilMakiela/Python-SFA
Development Status
The package is under active development. The current version supports individual cross-sectional and panel stochastic frontier models. Additional model-search and Bayesian model-averaging procedures may be introduced in future releases.
References
Jondrow, J., Lovell, C. A. K., Materov, I. S., and Schmidt, P. (1982). On the estimation of technical inefficiency in the stochastic frontier production function model. Journal of Econometrics, 19(2–3), 233–238. https://doi.org/10.1016/0304-4076(82)90004-5
Makieła, K. (2026). Model uncertainty under non-Gaussian errors: Bayesian model averaging and selection in stochastic frontier models. Available on arXiv.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stochastic_frontier_analysis-1.0.0.tar.gz.
File metadata
- Download URL: stochastic_frontier_analysis-1.0.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22adcbed2d64e8fc21dfe34346cf58be320c3416cfa0c22c71d43445711f93de
|
|
| MD5 |
0824e6e731d2b4aeaa98eb67581401f1
|
|
| BLAKE2b-256 |
0ed2d2036aa82e81a8b10db43eed313e5fb9d12126c61cb8db22c0d8aa822a0a
|
Provenance
The following attestation bundles were made for stochastic_frontier_analysis-1.0.0.tar.gz:
Publisher:
publish-to-pypi.yml on KamilMakiela/Python-SFA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochastic_frontier_analysis-1.0.0.tar.gz -
Subject digest:
22adcbed2d64e8fc21dfe34346cf58be320c3416cfa0c22c71d43445711f93de - Sigstore transparency entry: 2182329568
- Sigstore integration time:
-
Permalink:
KamilMakiela/Python-SFA@f313c6e3a0ec3390cfd62a4b2c931bf71c34e198 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/KamilMakiela
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@f313c6e3a0ec3390cfd62a4b2c931bf71c34e198 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file stochastic_frontier_analysis-1.0.0-py3-none-any.whl.
File metadata
- Download URL: stochastic_frontier_analysis-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93d479c47c86d52ad0e6d88d378381b35a2a7413aa26c8d68d5ec0cea35bb445
|
|
| MD5 |
5c0823117c1c60fa90aa012d619e5163
|
|
| BLAKE2b-256 |
60bb8174783decd1acb724a465629ca286f784a82b8610662cb3ffaa579db2a6
|
Provenance
The following attestation bundles were made for stochastic_frontier_analysis-1.0.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on KamilMakiela/Python-SFA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochastic_frontier_analysis-1.0.0-py3-none-any.whl -
Subject digest:
93d479c47c86d52ad0e6d88d378381b35a2a7413aa26c8d68d5ec0cea35bb445 - Sigstore transparency entry: 2182329745
- Sigstore integration time:
-
Permalink:
KamilMakiela/Python-SFA@f313c6e3a0ec3390cfd62a4b2c931bf71c34e198 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/KamilMakiela
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@f313c6e3a0ec3390cfd62a4b2c931bf71c34e198 -
Trigger Event:
workflow_dispatch
-
Statement type: