spscsfa

Semiparametric Smooth-Coefficient Stochastic Frontier Analysis

spscsfa implements semiparametric smooth-coefficient stochastic frontier models. The coefficients on the parametric regressors are allowed to vary smoothly with nonparametric covariates. The R package estimates the smooth coefficients in a first step and estimates the remaining frontier and inefficiency parameters by maximum likelihood in a second step.

The package is a unification of several methodological references listed at the end of this page, centering around Sun and Kumbhakar (2013, Semiparametric smooth-coefficient stochastic frontier model. Economics Letters, 120(2), 305–309.) The package also provides gradients of the smooth coefficients of the chosen type with respect to nonparametric covariates and analytic gradients of the Jondrow et al.'s (1982) (JLMS) inefficiency estimates with respect to inefficiency determinants, in addition to Battese and Coelli's (1988) technical efficiency and JLMS inefficiency estimates. It utilizes the npscoef function of the np package for local-constant smooth-coefficient estimator and its bandwidth selection, and the npksum function of the np package for local-linear smooth-coefficient estimator and its bandwidth selection. 

Installation

Install the CRAN release with:

install.packages("spscsfa")

Load the package with:

library(spscsfa)

Model specification

The basic two-part formula is:

spscsfa(y ~ x | z, data = dat)

Here, y is the dependent variable, x contains the parametric regressors, and z contains the nonparametric variables that index the smooth coefficients. When the third part of the formula is omitted, the z variables also serve as inefficiency determinants.

Use a three-part formula to specify a separate set of inefficiency determinants:

spscsfa(y ~ x | z | q, data = dat)

The optional q variables determine the scale of inefficiency. To specify an intercept-only inefficiency equation, use y ~ x | z | 1.

Quick start

The following example simulates data with one parametric regressor and one nonparametric variable, then estimates a local-constant model. The gradients argument requests derivatives of the smooth coefficients and the JLMS inefficiency estimates.

set.seed(1)

n <- 100

x <- rnorm(n)

z <- runif(n)

v <- rnorm(n, 0, 0.1)

u <- exp(0.1 + 0.1 * z) * abs(rnorm(n, 0, 1))

y <- cos(z) + sin(z) * x + v - u


dat <- data.frame(y = y, x = x, z = z)


fit <- spscsfa(

  y ~ x | z,

  data = dat,

  spscreg = "lc",

  gradients = TRUE,

  verbose = FALSE

)


# Model summary

summary(fit)


# Smooth coefficients and recovered frontier intercept

smoothcoef(fit)


# Technical efficiency and JLMS inefficiency estimates

head(te(fit))

head(inefficiency(fit))


# Gradients with respect to z

g <- grad(fit, zvar = "z")

head(g$theta_beta_grad$z)

head(g$alpha_grad)

head(g$inefficiency_grad)


# Plot the estimated smooth coefficients

plot(fit, n_grid = 60, rug = TRUE, ask = FALSE)

The fitted model uses local-constant estimation by default. Set spscreg = "ll" to use the local-linear estimator.

Estimate a local-linear stochastic frontier model

fit_ll <- spscsfa(

  y ~ x | z,

  data = dat,

  spscreg = "ll",

  gradients = TRUE,

  verbose = FALSE

)

summary(fit_ll)

Internal local-linear estimation and bandwidth selection

The llscoefbw() function selects local-linear bandwidths by least-squares cross-validation (LSCV). Its result can be supplied to llscoef() through its bws argument or directly to spscsfa() through its bandwidth argument:

# Select local-linear bandwidths

bw <- llscoefbw(y ~ x | z, data = dat)

# Selected bandwidths

bw$bw

# LSCV criterion function value at the selected bandwidths

bw$lscv

By default, llscoefbw() uses the scan multipliers 2^c(-2:5) when its coarse scan is used. The grid_scan argument allows users to supply a custom strictly increasing vector of finite positive multipliers. The returned scan_factor identifies the multiplier used to initialize the Nelder–Mead search that produced the selected bandwidths; it is 1 when the search from the original starting values gives the best result.

For direct local-linear smooth-coefficient estimation, use llscoef() with a bandwidth object returned by llscoefbw():

ll_fit <- llscoef(

  bw,

  betas = TRUE,

  residuals = TRUE,

  gradients = TRUE

)


head(coef(ll_fit))

head(residuals(ll_fit))

head(ll_fit$grad)

Main functions

Function Purpose

spscsfa() Estimates the smooth-coefficient stochastic frontier model.

summary() and plot() Summarize a fitted model and plot its smooth coefficients.

smoothcoef() Extracts the estimated smooth coefficients and recovered frontier intercept.

te() Extracts Battese–Coelli technical-efficiency estimates.

inefficiency() Extracts JLMS conditional inefficiency estimates.

grad() Extracts gradients from a model estimated with gradients = TRUE.

lcscoefgrad() Calculates analytic gradients of the local-constant smooth-coefficient estimator.

llscoefbw() Selects local-linear bandwidths by LSCV.

llscoef() Estimates local-linear smooth coefficients and, optionally, their gradients.

▎Further readings

┃For function-level documentation, use (for example):

?spscsfa

?grad

?lcscoefgrad

?llscoefbw

?llscoef

The package also includes the ricephil Philippine rice-farm dataset for illustrating smooth-coefficient stochastic frontier analysis.

Methodological references

License

The package is licensed under the GNU Affero General Public License (AGPL), version 3 or later.