Getting Started with spscsfa
Kai Sun
Overview
The spscsfa package estimates semiparametric smooth-coefficient stochastic frontier models. The coefficients on the parametric regressors can vary with nonparametric covariates. The package also reports technical efficiency scores and Jondrow et al.'s (1982) inefficiency estimates.
A model can be written as
yᵢ = α(Zᵢ) + Xᵢ′β(Zᵢ) + vᵢ − u(Zᵢ),
where the intercept and slope coefficients are smooth functions of the nonparametric variables Zᵢ. vᵢ is statistical noise, and u(Zᵢ) is nonnegative inefficiency. In the package specification, u(Zᵢ) = exp(δ₀ + δ₁′Zᵢ)ηᵢ, with a standard half-normal random variable ηᵢ. This vignette demonstrates the main workflow with simulated data. It is an illustration of the package interface.
Simulated data
The following data-generating process has one parametric regressor, x, and one nonparametric variable, z. The smooth intercept and slope vary with z, and the scale of inefficiency also depends on z.
library(spscsfa)
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)
head(dat)
#> y x z
#> 1 0.6892312 -0.6264538 0.2675082
#> 2 0.5542328 0.1836433 0.2186453
#> 3 0.3436538 -0.8356286 0.5167968
#> 4 1.0138391 1.5952808 0.2689506
#> 5 0.1115023 0.3295078 0.1811683
#> 6 -0.9798571 -0.8204684 0.5185761
Estimate a local-constant model
The basic formula is y ~ x | z:
the response is y;
x is the parametric regressor whose coefficient is allowed to vary;
z is the nonparametric variable that indexes the smooth coefficients.
When the third part of the formula is omitted, the z variables also enter the inefficiency equation as determinants. The local-constant estimator is the default. When bandwidth = NULL (also the default), the package selects the bandwidth by least-squares cross-validation (LSCV).
fit_lc <- spscsfa(
y ~ x | z,
data = dat,
spscreg = "lc",
gradients = TRUE,
verbose = FALSE
)
The fitted object contains the smooth-coefficient estimates, maximum-likelihood results from the second step, technical-efficiency estimates, and JLMS inefficiency estimates. Use summary() to obtain a compact model summary.
summary(fit_lc)
#>
#> ==================== SPSC-SFA RESULTS ====================
#>
#> Formula: y ~ x | z
#> Number of observations: 100
#>
#> --- Data Information ---
#> Data frame supplied: YES
#> Rows used: 100 out of 100
#> Variables from data: y, x, z
#>
#> Data source: from formula and data
#>
#> --- Parametric variables (x) ---
#> Count: 1
#> x
#>
#> --- Nonparametric variables (z) ---
#> Count: 1
#> z (continuous)
#>
#> --- STEP 1: SMOOTH COEFFICIENTS ---
#> Smooth-coefficient estimator: local-constant (LC)
#> Bandwidth source: LSCV
#> Training observations: 100
#> Evaluation observations: 100
#> Coefficients estimated on: training data
#>
#> Smooth Coefficients Summary (over the training observations):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> Intercept (theta) -0.36797 -0.2504 -0.0453 -0.0289 0.2196 0.2386
#> x 0.05916 0.2010 0.3735 0.3853 0.4290 0.9168
#>
#> --- STEP 2: MLE RESULTS ---
#> Inefficiency variables: ALL z variables from formula's z part (no third part)
#> Number of inefficiency variable slope coefficients, delta_1: 1
#>
#> Intercept (alpha) Summary (over the training observations):
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> Intercept (alpha) 0.387 0.5732 0.682 0.7058 0.9025 0.9272
#>
#> Inefficiency determinants (sigma_u = exp(delta_0 + delta_1'z)):
#>
#> Estimate Std. Error z value Pr(>|z|)
#> Intercept -0.1924 0.1446 -1.331 0.183
#> z 0.2471 0.2736 0.903 0.366
#>
#> --- Variance Parameters ---
#> Estimate Std. Error z value Pr(>|z|)
#> sigma2_v 0.04583 0.02096 2.187 0.0288
#>
#> Log-likelihood: -84.57 (optimizer: optim_BFGS )
#>
#> --- TECHNICAL EFFICIENCY (BC Method) ---
#> Confidence level for TE intervals: 95%
#> Mean SD Min Max Median
#> 0.54731 0.22588 0.07281 0.92360 0.60791
#>
#> --- INEFFICIENCY (JLMS Method) ---
#> Mean SD Min Max Median
#> 0.7418 0.5554 0.0821 2.6417 0.5183
#>
#> --- GRADIENTS ---
#>
#> Smooth coefficients, theta (intercept) and beta (local-constant estimates): gradients with respect to each continuous z variable
#> Summary statistics over the training observations.
#>
#> With respect to z:
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> d(Intercept (theta))/d(z) -2.8260 -1.2653 -0.4715 -0.6236 0.1782 1.766
#> d(x)/d(z) -0.6637 0.4109 0.9522 0.8096 1.2525 2.755
#>
#> Summary statistics over the training observations.
#> Intercept alpha: gradients with respect to each continuous z variable
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> d(Intercept (alpha))/d(z) -2.647 -1.089 -0.2838 -0.442 0.3476 1.957
#>
#> JLMS inefficiency: gradients with respect to the inefficiency determinants
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> z 0.0004328 0.007185 0.0135 0.01814 0.02428 0.06493
Extract fitted quantities
smoothcoef() returns the first-step smooth coefficients and the recovered frontier intercept. The first matrix contains the estimated θ(z) and β(z); the second contains α(Zᵢ), where α(Zᵢ)=θ(Zᵢ)+E(uᵢ∣Zᵢ).
sc <- smoothcoef(fit_lc)
head(sc$theta_beta)
#> Intercept (theta) x
#> [1,] 0.1893475 0.3087261
#> [2,] 0.2289645 0.2391713
#> [3,] -0.3523254 0.4024871
#> [4,] 0.1875877 0.3107844
#> [5,] 0.2382369 0.1907523
#> [6,] -0.3538957 0.4014209
head(sc$alpha)
#> Intercept (alpha)
#> [1,] 0.8925878
#> [2,] 0.9237647
#> [3,] 0.3955962
#> [4,] 0.8910786
#> [5,] 0.9266326
#> [6,] 0.3943548
The package provides separate helpers for technical efficiency and inefficiency:
te_scores <- te(fit_lc)
inefficiency_scores <- inefficiency(fit_lc)
head(te_scores)
#> [1] 0.8506948 0.6795523 0.9095329 0.7007637 0.4468568 0.3785828
head(inefficiency_scores)
#> [1] 0.16945529 0.40462615 0.09834005 0.37299006 0.82708904 0.99310194
summary(te_scores)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.07281 0.37832 0.60791 0.54731 0.73262 0.92360
summary(inefficiency_scores)
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.0821 0.3269 0.5183 0.7418 0.9939 2.6417
The technical-efficiency estimates use the Battese-Coelli method, while the inefficiency estimates use the JLMS conditional-mean method.
Plot the smooth coefficients
plot() draws the estimated intercept θ(z) and slope coefficients against each continuous nonparametric variable. It uses the estimator and bandwidths of the fitted model. For this example there is one continuous nonparametric variable, so the method produces one page of plots.
plot(fit_lc, n_grid = 60, rug = TRUE, ask = FALSE)