Skip to contents

npregivderiv uses the approach of Florens, Racine and Centorrino (2018) to compute the partial derivative of a nonparametric estimation of an instrumental regression function \(\varphi\) defined by conditional moment restrictions stemming from a structural econometric model: \(E [Y - \varphi (Z,X) | W ] = 0\), and involving endogenous variables \(Y\) and \(Z\) and exogenous variables \(X\) and instruments \(W\). The derivative function \(\varphi'\) is the solution of an ill-posed inverse problem, and is computed using Landweber-Fridman regularization.

Usage

npregivderiv(y, ...)

# Default S3 method
npregivderiv(y,
             z,
             w,
             x = NULL,
             zeval = NULL,
             weval = NULL,
             xeval = NULL,
             constant = 0.5,
             iterate.break = TRUE,
             iterate.max = 1000,
             nmulti = NULL,
             random.seed = 42,
             smooth.residuals = TRUE,
             start.from = c("Eyz","EEywz"),
             starting.values = NULL,
             stop.on.increase = TRUE,
             regtype = c("ll","lc","lp"),
             degree = NULL,
             nomad = FALSE,
             ...)

# S3 method for class 'formula'
npregivderiv(y,
             data = NULL,
             subset,
             na.action,
             newdata = NULL,
             zeval = NULL,
             weval = NULL,
             xeval = NULL,
             ...)

# S3 method for class 'npregivderiv'
plot(x, gradients = TRUE,
             data.overlay = TRUE, data.rug = FALSE, ...)

Arguments

Data, Bandwidth Inputs And Formula Interface

These arguments identify the response, endogenous variables, instruments, exogenous covariates, and evaluation data.

data

This argument belongs to the formula interface (including supported formula-bearing bandwidth-object refits). Native calls must supply their vectors, matrices or data frames directly, or use with(data, ...). Supplying data, including explicit data = NULL, to a native route that does not consume it is an error; see np-data-interfaces.

an optional data frame used with the formula interface. This estimator accepts y ~ z | w. The shared parser recognizes the optional | x partition but this univariate derivative operator rejects it explicitly; see Details.

subset

an optional expression selecting training rows in the formula interface.

na.action

a function specifying missing-value handling for the formula model frame.

newdata

an optional data frame supplying fit-time values of formula variable z at which to evaluate the structural derivative. It may contain any positive number of rows. Explicit zeval takes precedence.

w

a \(q\)-variate data frame of instruments. The data types may be continuous, discrete (unordered and ordered factors), or some combination thereof.

weval

retained for compatibility. The inverse problem is defined on the training instruments, so a supplied value must equal w; use zeval to request derivative evaluation.

x

for npregivderiv.default, reserved for interface compatibility. The present derivative estimator supports one univariate endogenous z and does not yet support a separate exogenous x; a non-NULL value fails explicitly. For plot.npregivderiv, an npregivderiv object.

xeval

reserved with x; it is not available until the derivative operator supports separate exogenous regressors.

y

a one (1) dimensional numeric or integer vector of dependent data, or a formula using the explicit IV grammar described under data. Each response element \(i\) corresponds to row \(i\) of z.

z

one finite continuous numeric endogenous regressor with at least two distinct support points.

zeval

finite values of the endogenous regressor at which to evaluate the structural derivative. The training inverse problem, residuals, centering, stopping rule, and selected state remain based on z and w. By default no separate evaluation surface is stored.

gradients

logical; display the structural derivative when TRUE, the default, or the reconstructed training structural function when FALSE. Derivative displays use zeval and phi.prime.eval when a separate evaluation grid was supplied.

data.overlay

logical; overlay the training response on a structural-function display. The default is TRUE, as for plot.npregression. It is ignored when gradients=TRUE because response values and derivatives do not share a common vertical scale. When limits are not supplied, the structural curve and response are both included in the displayed range.

data.rug

logical; add a rug showing the training z support. The default is FALSE, and it applies to both derivative and structural-function displays.

Iteration Controls

These arguments control derivative iteration and reproducibility settings.

constant

the constant to use for Landweber-Fridman iteration.

iterate.break

a logical value indicating whether to compute all objects up to iterate.max or to break when a potential optimum arises (useful for inspecting full stopping rule profile up to iterate.max)

iterate.max

an integer indicating the maximum number of complete positive Landweber-Fridman states to evaluate. The initialization state is numbered zero and does not consume this budget.

nmulti

integer number of times to restart the process of finding extrema of the cross-validation function from different (random) initial points.

random.seed

an integer used to seed R's random number generator. This ensures replicability of the numerical search. Defaults to 42.

Residual Smoothing And Starting Values

These arguments control residual smoothing and the initial derivative path.

smooth.residuals

a logical value (defaults to TRUE) indicating whether to optimize bandwidths for the regression of \(y-\varphi(z)\) on \(w\) or for the regression of \(\varphi(z)\) on \(w\) during Landweber-Fridman iteration.

start.from

a character string indicating whether to start from \(E(Y|z)\) (default, "Eyz") or from \(E(E(Y|w)|z)\) (this can be overridden by providing starting.values below)

starting.values

an optional vector supplying the derivative immediately before the first reported Landweber-Fridman update. When omitted, the initialization derivative is obtained from start.from (see details below). A separate zeval grid is not accepted with a supplied initialization because no interpolation rule for the externally supplied derivative has been declared. Repeated training values of z must have identical supplied derivative values; conflicting values do not define a single-valued function and are rejected before bandwidth preparation.

stop.on.increase

a logical value (defaults to TRUE) indicating whether to halt iteration if the stopping criterion (see below) increases over the course of one iteration (i.e. it may be above the iteration tolerance but increased).

Regression Smoothing Controls

These arguments control all internal npreg stages consistently.

regtype

a fixed regression type: "ll" (the default), "lc", or "lp". The default applies local-linear, degree-one smoothing to every internal stage containing continuous predictors, matching the default polynomial order of npregiv. A categorical-only internal stage uses local constant because no continuous polynomial term exists. Supply regtype="lc" to recover the former omitted-default computation.

degree

one nonnegative integer required with regtype="lp". It is expanded only across the continuous coordinates of each internal regression stage; vectors are not recycled across heterogeneous stages, and a categorical-only stage uses local constant.

nomad

logical or "auto". Only FALSE is currently supported for the multi-stage derivative estimator. Other values fail explicitly until the stage-wise search/state contract is validated.

Additional Arguments

Further arguments are passed to npreg and npksum.

...

Only fixed bandwidths are currently supported. Supplying bwtype="generalized_nn" or bwtype="adaptive_nn" raises an informative error; use bwtype="fixed" (the default). Additional arguments supplied to npreg and npksum. The private integral kernel sum in the empirical adjoint always uses bandwidth.divide = TRUE, as required for the ordinary CDF normalization; a bandwidth.divide value in ... continues to be supplied to npreg but does not override this internal normalization. Likewise, ukertype and okertype in ... control applicable internal regressions, while the private adjoint retains its required ukertype = "liracine" and okertype = "liracine". For the plot method, graphical arguments control the fitted curve and base-graphics frame as applicable. Explicit xlim and ylim are honored; automatic limits include every active curve, overlay, and rug layer.

Details

Formula variables of class ts, including lagged variables, are aligned on their common time support before fitting. Other variables must already have the length of that intersection. Supply explicitly aligned rows when using native data arguments instead of a formula.

Local-polynomial nuisance fits may use numerical diagonal ridging. For its Seifert–Gasser motivation, see npreg. This is distinct from regularization of the instrumental-variable inverse problem and does not apply the ordinary-regression residual uncertainty correction to IV inference.

Documentation guide: see np.kernels for kernels, np.options for global options, and plot for plotting options.

The formula interface uses explicit role order: y ~ z | w and y ~ z | w | x. Additive transformations and factors are retained through model.frame. Dot expansion and formula interaction operators are rejected because they do not identify a unique mixed-data kernel role; create an explicit transformed variable (for example with I(a * b)) instead. Native vector/data-frame calls remain supported unchanged.

The current derivative operator is univariate in z. Consequently, although the shared parser recognizes the package-wide optional | x partition, npregivderiv rejects it explicitly rather than silently changing the derivative target. Post-fit predict() is not available; use fit-time newdata or the native evaluation arguments.

Fit-time evaluation is output-only. Conditional regressions, the empirical adjoint, fitted-residual centering, structural integration, stopping values, and state selection are always computed on aligned training rows. A separate zeval accumulates the derivative corrections from those same training states into phi.prime.eval and phi.prime.eval.mat; it cannot change phi, phi.prime, their training paths, or norm.stop. Structural levels at arbitrary new points are not returned because this derivative estimator's integration and centering normalization is defined on the training support.

Let \(\varphi'_0\) denote the initialization derivative, obtained from start.from or supplied directly through starting.values. Its integrated and centered curve is \(\varphi_0\). This state is retained in starting.values.phi.prime and starting.values.phi; it is not a column of the positive-iteration matrices. For \(N=1,2,\ldots\), iteration \(N\) means exactly \(N\) completed residual-correction updates after this initialization. Column \(N\) of phi.prime.mat and phi.mat therefore contains the coherent pair \((\varphi'_N,\varphi_N)\), and norm.stop[N] is evaluated at that same state using the multiplier \(N\). Check the stopping vector for anomalies such as an immediate increase.

Landweber-Fridman iteration uses an optimal stopping rule based upon \(||E(y|w)-E(\varphi_k(z,x)|w)||^2 \). However, if local rather than global optima are encountered the resulting estimates can be overly noisy. To best guard against this eventuality set nmulti to a larger number than the default nmulti=min(2,p) for the first iteration, where p is the dimension of the current smoothing problem.

Note that for subsequent Landweber-Fridman iterations, a “warm start” strategy is employed. The optimal bandwidths from the previous iteration are used as starting values for the current iteration. The user-supplied nmulti is respected for all iterations. For iterations after the first successful one, these optimal bandwidths serve as the first of the multiple initial points (a warm start), while any remaining restarts are cold starts. If nmulti is not explicitly supplied by the user, it defaults to min(2,p) for the first iteration and to 1 for all subsequent iterations. This strategy provides a balance between computational efficiency and robustness, allowing the numerical optimizer to refine the structural bandwidths as the residuals evolve incrementally while still guarding against local optima.

With iterate.break=TRUE, iteration can stop after the stopping rule turns upward once the initial guard interval has passed; otherwise all states through iterate.max are evaluated. The selected state is then obtained from the computed stopping profile.

Value

npregivderiv returns a npregivderiv object. The generic functions print, summary, plot, fitted, residuals, and gradients support objects of this type. fitted returns the reconstructed training structural function while gradients returns the training derivative estimate. Residuals use the aligned training structural curve even when a separate evaluation grid was supplied. For formula fits using an exclusion-style na.action, these accessors restore omitted rows. summary returns a structured summary.npregivderiv object with a dedicated print method. The printed smoothing description reports the effective continuous-stage policy using the same Kernel Regression Estimator: labels as npreg: Local-Constant, Local-Linear, or, for regtype="lp", the local-polynomial degree and basis details.

The plot method displays the derivative by default, preserving the estimator family's primary target. Set gradients=FALSE to display the reconstructed training structural function. The training response is overlaid only on that level display; data.rug=TRUE adds the training support without replacing an available derivative evaluation curve.

npregivderiv returns a list with components phi.prime, phi, phi.prime.mat, phi.mat, and, when a separate evaluation grid was supplied, phi.prime.eval and phi.prime.eval.mat, num.iterations, norm.stop, convergence, and the initialization components starting.values.phi.prime and starting.values.phi. num.iterations is the selected state returned in phi.prime and phi; the number of states evaluated, including any stopping-rule overshoot, is length(norm.stop). The compact bws, smoothing.spec, and stage.specs components record stage bandwidth payloads and requested/effective fixed-degree smoothing state without replacing the legacy bandwidth fields.

References

Carrasco, M. and J.P. Florens and E. Renault (2007), “Linear Inverse Problems in Structural Econometrics Estimation Based on Spectral Decomposition and Regularization,” In: James J. Heckman and Edward E. Leamer, Editor(s), Handbook of Econometrics, Elsevier, 2007, Volume 6, Part 2, Chapter 77, Pages 5633-5751

Darolles, S. and Y. Fan and J.P. Florens and E. Renault (2011), “Nonparametric instrumental regression,” Econometrica, 79, 1541-1565.

Feve, F. and J.P. Florens (2010), “The practice of non-parametric estimation by solving inverse problems: the example of transformation models,” Econometrics Journal, 13, S1-S27.

Florens, J.P. and J.S. Racine and S. Centorrino (2018), “Nonparametric instrumental derivatives,” Journal of Nonparametric Statistics, 30 (2), 368-391.

Fridman, V. M. (1956), “A method of successive approximations for Fredholm integral equations of the first kind,” Uspeskhi, Math. Nauk., 11, 233-334, in Russian.

Horowitz, J.L. (2011), “Applied nonparametric instrumental variables estimation,” Econometrica, 79, 347-394.

Landweber, L. (1951), “An iterative formula for Fredholm integral equations of the first kind,” American Journal of Mathematics, 73, 615-24.

Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.

Li, Q. and J.S. Racine (2004), “Cross-validated Local Linear Nonparametric Regression,” Statistica Sinica, 14, 485-512.

Author

Jeffrey S. Racine racinej@mcmaster.ca

Note

This function currently supports univariate z only. This function should be considered to be in ‘beta test’ status until further notice.

Examples

if (FALSE) { # \dontrun{
## This illustration was made possible by Samuele Centorrino
## <samuele.centorrino@univ-tlse1.fr>

set.seed(42)
n <- 500
trim <- 0.005

## Endogenous-regressor DGP:
##
## y = phi(z) + u
## E(u | z) != 0
## z = 0.2 w + v
## E(u | w) = 0

v <- rnorm(n, mean = 0, sd = 0.27)
eps <- rnorm(n, mean = 0, sd = 0.05)
u <- -0.5 * v + eps
w <- rnorm(n)

phi <- function(z) z^2
phi.prime <- function(z) 2 * z

z <- 0.2 * w + v
y <- phi(z) + u

ivdata <- data.frame(y, z, w)
ivdata <- ivdata[order(ivdata$z), ]

model.ivderiv <- npregivderiv(y ~ z | w, data = ivdata)
deriv.iv <- gradients(model.ivderiv)

## Restrict the display to the central 99 percent of the z observations.

zlim <- quantile(ivdata$z, c(trim, 1 - trim))
keep <- ivdata$z >= zlim[1L] & ivdata$z <= zlim[2L]

plot(ivdata$z[keep], deriv.iv[keep],
     main = "",
     xlab = "Z",
     ylab = "Derivative",
     type = "l",
     lwd = 2)

curve(phi.prime(x), add = TRUE, col = 2, lty = 2, lwd = 2)
rug(ivdata$z[keep])
} # }