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.3.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.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: depp_sfa-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 f25c96449402a7c555682229e3c39a04331d2c90ee3b188da29164f4330cbc0f
MD5 9584dc4e48777999865d5a6f5ca4f65b
BLAKE2b-256 417e57dd7cedc829e59218b3ac4db117aed3d985989ade6c50784495dd4f5b83

See more details on using hashes here.

File details

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

File metadata

  • Download URL: depp_sfa-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f3d2605731c3157e2b2f4fc9b456a9b9286d10e7a1f77b513029a3ef147c1b1
MD5 e9a97af11e799a0d873e311c0ed5c31c
BLAKE2b-256 5f07b9e4da7b052fd56c815ffa8aecb54e8269af0dbf2208d189b7b0719c46bc

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