Skip to main content

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.

Release files for depp-sfa 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for depp-sfa 0.1.3
File Size Uploaded
depp_sfa-0.1.3.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for depp-sfa 0.1.3
File Interpreter ABI Platform
depp_sfa-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.7 kB

Release files / depp_sfa-0.1.3.tar.gz

Download URL depp_sfa-0.1.3.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f25c96449402a7c555682229e3c39a04331d2c90ee3b188da29164f4330cbc0f
BLAKE2b-256 checksum
How to use checksums
417e57dd7cedc829e59218b3ac4db117aed3d985989ade6c50784495dd4f5b83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / depp_sfa-0.1.3-py3-none-any.whl

Download URL depp_sfa-0.1.3-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f3d2605731c3157e2b2f4fc9b456a9b9286d10e7a1f77b513029a3ef147c1b1
BLAKE2b-256 checksum
How to use checksums
5f07b9e4da7b052fd56c815ffa8aecb54e8269af0dbf2208d189b7b0719c46bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page