Skip to main content

A Stochastic Frontier Analysis (SFA) library featuring MLE and Bayesian (PyMC) estimations.

Project description

Depp_sfa: Stochastic Frontier Analysis (SFA)

Documentation Status

Depp_sfa is a Python library dedicated to the estimation of Stochastic Frontier Analysis (SFA) models. It is specifically designed to provide high robustness against numerical convergence issues—such as "boundary effects"—frequently encountered in applied econometrics.


Key Features

  • Hybrid Inference: Primarily relies on Maximum Likelihood Estimation (MLE), featuring an automatic fallback to Bayesian estimation (MCMC via PyMC) if the optimization fails to converge.
  • Advanced Panel Data: Implements the dynamic Battese & Coelli (1992) model for time-varying inefficiency and Greene (2005) True Fixed/Random Effects.
  • Functional Flexibility: Supports Linear, Cobb-Douglas, and Translog specifications with automatic handling of log-transformations, interaction terms, and dummy variables.
  • Built-in Standardization: Includes an internal preprocessing option (standardize=True) to center and scale continuous variables, ensuring stable solver convergence.

Installation

Install the library directly from the repository:

pip install depp_sfa

Quick Start

The library can automatically handle data scaling and functional form transformations (logs, interactions, and squares).

import pandas as pd
import numpy as np
from depp_sfa import SFA, FUN_COST

# 1. Load your data
df = pd.read_csv("utility_data.csv")

# 2. Instantiate the model
# Using 'standardize=True' is highly recommended for Translog forms
model = SFA(
    y=df["total_cost"].values,
    x=df[["output", "labor_price", "capital_price"]].values,
    fun=FUN_COST,
    form='translog',
    standardize=True,
    inference_method='mle' # Falls back to 'pymc' automatically if MLE fails
)

# 3. Estimate and display results
model.summary()

# 4. Retrieve Efficiency Scores (TE)
te_scores = model.get_technical_efficiency()

API Reference: SFA Class

Constructor Parameters

Parameter Type Description
y array Dependent variable (Output for production, Cost for cost frontier).
x array Independent variables (Inputs or Price/Output mix).
z array (Optional) Determinants of inefficiency (BC95 model).
id_var array Individual identifiers (Required for panel models).
time_var array Time/Year variable (Required for BC92 model).
fun int FUN_PROD (0) or FUN_COST (1).
form str Functional form: 'linear', 'cobb_douglas', or 'translog'.
standardize bool If True, centers and scales continuous variables automatically.
draws int Number of MCMC draws if using PyMC (default: 2000).

Core Methods

Calling these methods will automatically trigger the optimize() routine if the model hasn't been estimated yet.

  • summary(): Prints a detailed results table including Coefficients, Std. Errors, z-values, and P-values.
  • get_technical_efficiency(): Returns technical efficiency scores (bounded between 0 and 1).
  • get_beta(): Returns the estimated frontier coefficients.
  • get_residuals(): Returns the composite error terms (v_i +/- u_i).
  • get_lambda(): Returns the signal-to-noise ratio (sigma_u / sigma_v).

MLE vs. PyMC

  • MLE (Maximum Likelihood): Fast and standard. Best for large, balanced cross-sections. It may suffer from "boundary failures" (where inefficiency variance collapses to zero) on small or unbalanced panels.
  • PyMC (Bayesian Inference): Highly robust. By using prior distributions, it prevents variance collapse and successfully separates noise from inefficiency even in datasets with many singletons (unbalanced panels). It provides full posterior distributions for all parameters.

Credits & License

Distributed under the MIT License.

  • Base architecture and likelihood derivations inspired by Sheng Dai (2023).
  • Bayesian integration, numerical stabilization, and panel model extensions developed for the Depp project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depp_sfa-0.1.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

depp_sfa-0.1.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file depp_sfa-0.1.2.tar.gz.

File metadata

  • Download URL: depp_sfa-0.1.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for depp_sfa-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fc43a9a1f7ba0b351c8c18f1bc313c4a55716e2951f72d544d8bbe00bd5e2c44
MD5 ed8ab9f986b2f88645694598edb1cff3
BLAKE2b-256 d915c4c56f9cad749236f2baf6853d447d66586dfe7ea722d7753ceeab0e600e

See more details on using hashes here.

File details

Details for the file depp_sfa-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: depp_sfa-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for depp_sfa-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de80c15e2c89ea43c563b8c38f0799fd21ae22a418e8c3108f20ade4ad5c8fc2
MD5 4141043778581076d83c9b094040c1c2
BLAKE2b-256 d5993a5a2f50550d71317f317e7a2521998dfb38b8f242ebc3f502aa3aca2ed9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page