Package {spefa}


Type: Package
Title: Spatial Stochastic Frontier with Fixed Effects and Endogeneity
Version: 0.1.0
Description: Maximum-likelihood estimation of the spatial autoregressive stochastic frontier model with individual fixed effects (removed by first differencing) and endogenous regressors handled through a Gaussian control function, as in Giannini (2025) <doi:10.1080/17421772.2024.2414962>. Returns coefficient estimates and standard errors, spatially-corrected technical (in)efficiency scores, and direct, indirect and total marginal impacts. Depends only on base R.
License: GPL-3
Encoding: UTF-8
Depends: R (≥ 3.5.0)
Imports: stats
LazyData: true
Suggests: knitr, rmarkdown
VignetteBuilder: knitr
RoxygenNote: 7.2.3
NeedsCompilation: no
Packaged: 2026-05-21 06:32:07 UTC; root
Author: Massimo Giannini [aut, cre] (University of Rome Tor Vergata, Department of Enterprise Engineering)
Maintainer: Massimo Giannini <massimo.giannini@uniroma2.it>
Repository: CRAN
Date/Publication: 2026-05-28 11:10:17 UTC

Technical (in)efficiency scores

Description

Conditional-mean (JLMS) inefficiency estimates with optional spatial rescaling by (I-\lambda W)^{-1}.

Usage

efficiency(object, spatial = TRUE)

Arguments

object

a fitted spefa object.

spatial

logical; apply the spatial multiplier.

Value

A list with the inefficiency matrix u (N x T), efficiency eff = exp(-u), and per-unit Eu_i.

Examples

data(spefademo)
fit <- spefa(y ~ x1 + q1, data = spefademo, index = c("id", "time"),
             W = spefaW, endogenous = list(q1 = ~ z1, q2 = ~ z2),
             scaling = ~ x2 + q2)
ef <- efficiency(fit)
summary(as.vector(ef$eff))

Direct, indirect and total marginal impacts (with inference)

Description

LeSage-Pace decomposition of frontier marginal effects through the spatial multiplier (I-\lambda W)^{-1}. Standard errors, z-statistics and p-values are obtained by simulation from the asymptotic distribution of (\beta,\lambda).

Usage

impacts(object, ...)

## S3 method for class 'spefa'
impacts(object, R = 1000, seed = NULL, ...)

Arguments

object

a fitted spefa object.

R

number of simulation draws for the standard errors.

seed

optional integer seed for reproducibility.

...

unused.

Value

An object of class impacts.spefa: a list with matrices Direct, Indirect and Total, each with columns Estimate, Std.Error, z value and Pr(>|z|).

Examples

data(spefademo)
fit <- spefa(y ~ x1 + q1, data = spefademo, index = c("id", "time"),
             W = spefaW, endogenous = list(q1 = ~ z1, q2 = ~ z2),
             scaling = ~ x2 + q2)
impacts(fit, R = 500, seed = 1)

Spatial Stochastic Frontier with Fixed Effects and Endogeneity

Description

Maximum-likelihood estimation of a spatial autoregressive stochastic frontier model with individual fixed effects (removed by first differencing) and endogenous regressors handled by a Gaussian control function.

Usage

spefa(formula, data, index, W, endogenous = NULL, scaling = NULL,
      mu = FALSE, control = list(maxit = 500, reltol = 1e-9))

Arguments

formula

frontier equation, e.g. y ~ x1 + q1. The intercept is removed by first differencing.

data

a balanced panel data.frame.

index

length-2 character vector c(unit, time).

W

an N x N spatial weight matrix, rows/cols ordered by sorted unit id.

endogenous

named list mapping endogenous regressors to instruments, e.g. list(q1 = ~ z1, q2 = ~ z2), or NULL.

scaling

one-sided formula of variables entering the inefficiency scaling h_{it}=\exp(z_{it}'\phi), e.g. ~ x2 + q2.

mu

logical; if TRUE estimate the truncation point (truncated-normal inefficiency), else half-normal.

control

list passed to optim.

Value

An object of class spefa with methods summary, coef, vcov, logLik, efficiency and impacts.

Examples

data(spefademo)
fit <- spefa(y ~ x1 + q1, data = spefademo, index = c("id", "time"),
             W = spefaW, endogenous = list(q1 = ~ z1, q2 = ~ z2),
             scaling = ~ x2 + q2)
summary(fit)

Simulated demo panel for spefa

Description

A small simulated balanced panel and its spatial weight matrix, used in the examples and vignette. Generated from the model in Giannini (2025) with \beta=(0.5,0.5), \delta=(1,1), \phi=(0.3,0.3), \sigma^2_\varepsilon=0.09, \sigma^2_v=0.04, \rho=(0.5,0.5), \sigma^2_u=0.09 and \lambda=0.5; q1 and q2 are endogenous, q1 enters the frontier and q2 the scaling.

Usage

data(spefademo)

Format

spefademo: a data.frame with 480 rows (N = 40 units, T = 12 periods) and columns id, time, y, x1, x2, q1, q2, z1, z2.

spefaW: a 40 x 40 row-normalised spatial weight matrix, ordered by id.

Examples

data(spefademo)
str(spefademo)
dim(spefaW)