| npindexbw | R Documentation |
npindexbw computes a npindexbw bandwidth specification
using the model Y = G(X\beta) + \epsilon. For continuous Y, the approach is that of Hardle, Hall
and Ichimura (1993) which jointly minimizes a least-squares
cross-validation function with respect to the parameters and
bandwidth. For binary Y, a likelihood-based cross-validation
approach is employed which jointly maximizes a likelihood
cross-validation function with respect to the parameters and
bandwidth. The bandwidth object contains parameters for the single
index model and the (scalar) bandwidth for the index function.
npindexbw(...)
## S3 method for class 'formula'
npindexbw(formula,
data,
subset,
na.action,
call,
...)
## Default S3 method:
npindexbw(xdat = stop("training data xdat missing"),
ydat = stop("training data ydat missing"),
bws,
bandwidth.compute = TRUE,
basis = c("glp", "additive", "tensor"),
bernstein.basis = FALSE,
degree = NULL,
degree.select = c("manual", "coordinate", "exhaustive"),
search.engine = c("nomad+powell", "cell", "nomad"),
nomad = FALSE,
nomad.nmulti = 0L,
degree.min = NULL,
degree.max = NULL,
degree.start = NULL,
degree.restarts = 0L,
degree.max.cycles = 20L,
degree.verify = FALSE,
nmulti,
nomad.remin = FALSE,
powell.remin = TRUE,
only.optimize.beta,
optim.abstol,
optim.maxattempts,
optim.maxit,
optim.method,
optim.reltol,
random.seed,
regtype = c("lc", "ll", "lp"),
scale.factor.init.lower = 0.1,
scale.factor.init.upper = 2.0,
scale.factor.init = 0.5,
scale.factor.search.lower = NULL,
...,
nomad.opts = list())
## S3 method for class 'sibandwidth'
npindexbw(xdat = stop("training data xdat missing"),
ydat = stop("training data ydat missing"),
bws,
bandwidth.compute = TRUE,
.certify.selected = TRUE,
nmulti,
only.optimize.beta = FALSE,
optim.abstol = .Machine$double.eps,
optim.maxattempts = 10,
optim.maxit = 500,
optim.method = c("Nelder-Mead", "BFGS", "CG"),
optim.reltol = sqrt(.Machine$double.eps),
random.seed = 42,
scale.factor.init.lower = 0.1,
scale.factor.init.upper = 2.0,
scale.factor.init = 0.5,
scale.factor.search.lower = NULL,
.restore.first.start = TRUE,
...,
.indextest.leaf = NULL,
.fixed.h.lower = NULL)
These arguments identify the data, formula interface, method label, and whether bandwidths are supplied or computed.
bandwidth.compute |
a logical value which specifies whether to do a numerical search for
bandwidths or not. If set to |
.certify.selected |
internal logical control requiring one raw-objective replay of the selected search point. This argument is used by package search owners and is not intended for direct user control. |
.restore.first.start |
internal logical control enabling bounded restoration of eligible automatically generated raw-invalid first optimizer evaluations. It is used by package search owners and is not intended for direct user control. |
.indextest.leaf |
Internal CV objective evaluator prepared by |
.fixed.h.lower |
internal physical-bandwidth floor passed from a NOMAD search to its fixed-degree refinement. The default retains the direct-call scale-factor domain. This argument is not intended for direct user control. |
bws |
a bandwidth specification. This can be set as a
|
call |
the original function call. This is passed internally by
|
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 an optional data frame, list or environment (or object
coercible to a data frame by |
formula |
a symbolic description of variables on which bandwidth selection is to be performed. The details of constructing a formula are described below. |
method |
the single index model method, one of either “ichimura”
(Ichimura (1993)) or “kleinspady” (Klein and Spady
(1993)). Defaults to
|
na.action |
a function which indicates what should happen when the data contain
|
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
xdat |
a |
ydat |
a one (1) dimensional numeric or integer vector of dependent data, each
element |
These arguments control automatic local-polynomial degree search.
degree.max |
optional scalar or integer vector giving upper bounds for automatic
degree search when |
degree.max.cycles |
positive integer giving the maximum number of coordinate-search
sweeps over the degree vector. Ignored for |
degree.min |
optional scalar or integer vector giving lower bounds for automatic
degree search when |
degree.restarts |
non-negative integer giving the number of additional deterministic
restarts used by coordinate search with |
degree.select |
character string controlling local-polynomial degree handling when
|
degree.start |
optional starting degree vector for automatic coordinate search. If
omitted, the search starts from the degree-zero local-constant
baseline for the index smoother.
For cell-based searches, the starting degree and initial baseline are
restricted to the requested |
degree.verify |
logical value indicating whether an automatic degree-search solution
should be exhaustively certified over the admissible degree grid after
the heuristic phase completes. With |
These controls define deterministic and random continuous scale-factor starts and the lower admissibility floor for fixed-bandwidth search.
scale.factor.init |
deterministic initial scale factor for continuous fixed-bandwidth
search. Defaults to |
scale.factor.init.lower |
lower endpoint for random continuous scale-factor starts. Defaults
to |
scale.factor.init.upper |
upper endpoint for random continuous scale-factor starts. Defaults
to |
scale.factor.search.lower |
optional nonnegative scalar giving the hard lower admissibility
bound for continuous fixed-bandwidth search candidates. Defaults to
|
These arguments control the index smoother, local-polynomial basis, and fixed degree specification.
basis |
local polynomial basis selector used when
|
bernstein.basis |
logical flag used when |
degree |
integer degree vector for continuous predictors when
|
regtype |
a character string specifying local smoothing type for the
nonparametric index regression fit used downstream in
|
These arguments control the optional NOMAD direct-search route for local-polynomial degree and bandwidth search.
nomad |
logical or character shortcut for the recommended automatic local-polynomial
NOMAD route. When |
nomad.nmulti |
non-negative integer controlling the inner
the native crs NOMAD C API multistart count used within each outer
NOMAD restart when |
nomad.opts |
optional named list of native NOMAD parameters forwarded to the
crs NOMAD C API for NOMAD-backed bandwidth searches.
|
nomad.remin |
logical flag controlling the optional second NOMAD hot start. When
|
search.engine |
character string controlling the automatic local-polynomial search
backend when |
These controls set search restart behavior.
nmulti |
integer number of times to restart the process of finding extrema of
the cross-validation function from different (random) initial
points. Defaults to |
powell.remin |
compatibility argument shared with bandwidth families that use the Powell
direction-set solver. Single-index fixed-degree and post-NOMAD refinement
use R |
These arguments control outer optimization behavior for the semiparametric search.
only.optimize.beta |
minimizes the objective function with respect to beta while retaining
the existing polynomial degree and bandwidth (or nearest-neighbor count).
Automatic degree search, including NOMAD and cell search, is not run;
|
optim.abstol |
the absolute convergence tolerance used by |
optim.maxattempts |
maximum number of attempts taken trying to achieve successful
convergence in |
optim.maxit |
maximum number of iterations used by |
optim.method |
method used by the default method is an implementation of that of Nelder and Mead (1965), that uses only function values and is robust but relatively slow. It will work reasonably well for non-differentiable functions. method method The default |
optim.reltol |
relative convergence tolerance used by |
random.seed |
Temporary caller-state restoration requires a certifiable initialized state; see np_rng_scope. an integer used to seed R's random number generator. This ensures replicability of the numerical search. Defaults to 42. |
These arguments collect remaining controls passed through S3 methods.
... |
additional arguments supplied to specify the parameters to the
|
Use npindextest to test whether the conditional mean (or binary success probability) depends on the covariates through a single linear index with unknown coefficients and link.
The primary response must be a one-dimensional numeric (integer or double) vector. Factors and ordered factors are not accepted as primary responses, including retained responses used in a new fit or bandwidth search. Categorical predictors retain their existing support. Internal auxiliary responses used to represent predictors retain their established encoding. Klein–Spady retains its stricter numeric 0/1 response requirement.
For newly constructed bandwidth objects, factors enter the linear index
through R model-matrix contrasts. An unordered factor with k observed
levels ordinarily contributes k-1 coefficients. Ordered factors use
their R contrasts (polynomial contrasts by default), including when their
level labels look numeric. To fit a single coefficient on specified scores
instead, supply those scores as a numeric predictor.
For supported additive formulas, coefficient names and predictor columns
follow model.matrix(). The intercept is absorbed into the unknown
link and is not an index coefficient. The first retained design coefficient
is normalized to one; the package does not reorder predictors to choose a
different normalization. Thus a factor listed first can supply the
normalized contrast coefficient. These are relative index coefficients,
not linear-regression slopes. This representation does not add support for
otherwise unsupported formula syntax.
Native data-frame calls use the corresponding additive design. A manually
supplied bws vector contains one beta for each expanded design column,
in model-matrix order, followed by the scalar bandwidth. Automatic start
vectors use the same coordinates. Numeric-only inputs keep their existing
representation. A new factor design with aliased columns or a constant
direction is rejected: for example, y ~ 0 + x + group supplies all
group indicators and has an unidentified constant direction. Use the
ordinary contrast formula y ~ x + group or independent numeric columns.
Factor levels and the actual contrast matrices are retained at construction. Prediction uses this design even if global contrast options change or an evaluation sample omits some training levels. New evaluation levels are an error. Levels absent from the complete training sample do not identify coefficients. Custom contrasts must remain identifiable on that sample.
Older saved bandwidth objects without retained design metadata preserve
their historical single-score factor representation. Reconstruct a bandwidth
object to adopt the contrast design; the package does not silently reinterpret
an existing coefficient vector. The index.design component records the
raw predictor names, retained levels/contrasts, and expanded column mapping;
coefficient names and dimensions refer to the expanded design.
Formula bandwidth objects retain the prepared training sample (after alignment,
subsetting and missing-value handling) and the resolved missing-value policy.
Later refits use that sample even if constructor variables are rebound.
Supplying explicit training data to the estimator replaces the training data;
evaluation via newdata does not. Retention requires storage proportional
to the sample size times the number of variables, not a pairwise weight matrix.
Older saved objects without this retained state still rely on their original
data bindings; rebuild their bandwidth object from the intended data before
changing those bindings. User-defined transformation and missing-value
functions should not rely on subsequently modified closure state.
The scale.factor.* controls are dimensionless search
controls. The package converts scale factors to bandwidths using the
estimator-specific scaling encoded in the bandwidth object, including
kernel order and the number of continuous variables relevant for the
estimator. Users should not pre-multiply these controls by sample-size
or standard-deviation factors.
scale.factor.init controls the deterministic first search
start when that control is exposed. scale.factor.init.lower
and scale.factor.init.upper define the random multistart
interval when exposed. scale.factor.search.lower is the lower
admissibility bound for continuous fixed-bandwidth search candidates.
The effective first start is max(scale.factor.init,
scale.factor.search.lower) when both controls are present, and the
effective random-start lower endpoint is
max(scale.factor.init.lower, scale.factor.search.lower).
scale.factor.init.upper must be at least that effective lower
endpoint; the package errors rather than silently expanding the user's
interval.
When scale.factor.search.lower is NULL, an existing
bandwidth object's stored floor is inherited when available;
otherwise the package default 0.1 is used. Explicit bandwidths
supplied for storage with bandwidth.compute = FALSE are not
rewritten by the search floor.
Categorical search-start controls such as dfac.init,
lbd.init, and hbd.init have separate semantics and are
not affected by scale.factor.search.lower.
Documentation guide: see np.kernels for kernels, np.options for global options, and plot, plot.np for plotting options.
For S3 plotting help, see plot.np. You can list
available plot methods with methods("plot").
We implement Ichimura's (1993) method via joint estimation of the bandwidth and coefficient vector using leave-one-out nonlinear least squares. We implement Klein and Spady's (1993) method maximizing the leave-one-out log likelihood function jointly with respect to the bandwidth and coefficient vector. Note that Klein and Spady's (1993) method is for binary outcomes only, while Ichimura's (1993) method accepts numeric outcomes, whether continuous or discrete-valued.
Invalid outer-search guidance uses the exact declared leave-one-out null: the constant-model least-squares null for Ichimura and the clipped Bernoulli likelihood null for Klein–Spady. Inner regression evaluation remains raw; only terminal invalidity is mapped at the outer boundary. The selected point is replayed once against the raw objective and is rejected if it is not finite and valid.
We impose the identification condition that the first element of the coefficient vector beta is equal to one, while identification also requires that the explanatory variables contain at least one continuous variable.
\beta CoefficientsThe scale of X^\prime\beta and the scale of the unknown link
function are not separately identified, so npindexbw
normalizes the first coefficient to one. The remaining coefficients
should therefore be read relative to the first explanatory variable,
not as standalone linear-model slopes. Holding other variables fixed,
a one-unit increase in X_j changes the index by the same amount
as a \beta_j-unit increase in X_1. Where the link
derivative exists and is nonzero, marginal-effect ratios satisfy
\partial g(X^\prime\beta)/\partial X_j \; /\;
\partial g(X^\prime\beta)/\partial X_1 = \beta_j. Signs and magnitudes are therefore relative to
the chosen first variable and its units; choose the first continuous
regressor deliberately when interpretation is important.
For fixed-bandwidth R optim searches, an automatic raw-invalid
starting bandwidth is doubled while keeping its starting coefficients and
degree fixed. This applies to all supported regression types, kernel orders
and support options, including generated starts in automatic degree-search
children. Each multistart uses its own coefficients' index scale.
Only the first scalar evaluation already
requested by optim is checked. A valid original start continues in
that same optimizer invocation without an additional objective evaluation.
A rejected start does not incur a numerical-gradient stencil.
Restoration permits at most eight doublings (nine starting scalar
evaluations) for each multistart or existing convergence-retry start and
respects the existing search bounds. Each rejected start adds one scalar
evaluation, which can be costly. The random-draw control
scale.factor.init.upper is not a search upper bound, so restoration
may exceed it. Explicit initial bandwidths and bandwidths held by
only.optimize.beta=TRUE are never expanded; a raw-invalid first
evaluation fails with the method, start/retry, attempted bandwidth range,
count and reason. Budget exhaustion also fails the complete call.
This rule does not change subsequent optimizer trials, finite differences, penalties, convergence-retry controls or final exact-point certification. A valid start does not guarantee convergence or a valid final point. Increasing the bandwidth does not guarantee feasibility for higher-order kernels or local-polynomial fits; every attempted start must pass the same raw-objective check. Nearest-neighbour bandwidths and NOMAD's own direct search retain their existing feasibility mechanisms. An explicit NOMAD refinement start is checked but not expanded. No alternative solver or earlier multistart winner is substituted when restoration fails.
optim.methodThe default "Nelder-Mead" search is often a good starting
point for low-dimensional single-index problems because it uses only
objective values and is comparatively tolerant of rough objective
surfaces. When p is larger, especially when many coefficients
enter \beta, "BFGS" may reduce runtime for some
problems, but it is more dependent on local smoothness and on the
quality of numerical gradient information. For important fits, try
both methods with adequate multistarts and compare the final
objective values, convergence messages, and fitted objects.
npindexbw may be invoked either with a formula-like
symbolic description of variables on which bandwidth selection is to
be performed or through a simpler interface whereby data is
passed directly to the function via the xdat and ydat
parameters. Use of these two interfaces is mutually exclusive.
Note that, unlike most other bandwidth methods in the np
package, this implementation uses the R optim nonlinear
minimization routines and npksum. We have implemented
multistarting and strongly encourage its use in practice. For
exploratory purposes, you may wish to override the default search
tolerances, say, setting optim.reltol=.1 and conduct
multistarting (the default is to restart min(2, ncol(xdat)) times) as is done
for a number of examples. See the optimizer guidance above when
choosing between the default "Nelder-Mead" method and
optim.method="BFGS" for higher-dimensional index searches.
Data for which bandwidths are to be estimated may be specified
symbolically. A typical description has the form dependent data
~ explanatory data, where dependent data is a univariate
response, and explanatory data is a series of variables
specified by name, separated by the separation character '+'. For
example y1 ~ x1 + x2 specifies that the bandwidth object for
the regression of response y1 and semiparametric regressors
x1 and x2 are to be estimated. See below for further
examples.
When regtype="lp" and degree.select != "manual",
npindexbw can jointly determine the local-polynomial degree for
the index smoother together with its bandwidth coordinate. With
search.engine="cell", the criterion is profiled over the
admissible degree grid using cached coordinate-wise or exhaustive
search. With search.engine="nomad" or
"nomad+powell", the criterion is optimized directly over the
joint degree/bandwidth space using the native crs NOMAD C API.
For this family, the compatibility value "nomad+powell" then
performs one family-native R optim hot start using
optim.method and retains the better of the direct NOMAD and refined
solutions. For the
index-smoother local-polynomial component, this polynomial-adaptive
joint-search route follows Hall and Racine (2015).
Setting nomad=TRUE is a convenience preset for this automatic
LP route, not a generic optimizer alias. For single-index bandwidth
selection it expands any missing values to the equivalent long-form
call
npindexbw(...,
regtype = "lp",
search.engine = "nomad+powell",
degree.select = "coordinate",
bernstein.basis = TRUE,
degree.min = 0L,
degree.max = 10L,
degree.verify = FALSE,
bwtype = "fixed")
Compatible explicit tuning arguments are respected. Incompatible
explicit settings fail fast so the shortcut never silently changes
user-selected semantics.
The character value nomad="auto" applies the same LP
shortcut but leaves search.engine and degree.select
eligible for data-driven resolution when both were not supplied
explicitly: scalar continuous degree searches use the exhaustive
degree-grid route, while higher-dimensional degree searches keep the
compatibility "nomad+powell" route. Explicit search.engine or
degree.select choices are honored.
npindexbw returns a sibandwidth object, with the
following components:
bw |
bandwidth(s), scale factor(s) or nearest neighbours for the
data, |
beta |
coefficients of the model |
fval |
objective function value at minimum |
If bwtype is set to fixed, an object containing a scalar
bandwidth for the function G(X\beta) and an estimate of
the parameter vector \beta is returned.
If bwtype is set to generalized_nn or
adaptive_nn, then instead the scalar kth nearest neighbor
is returned.
The functions coef, predict,
summary, and plot support
objects of this class.
Local-polynomial index search inherits the numerical-ridging policies
described in npreg; see Seifert and Gasser (2000) there.
npindexbw selects the index direction, bandwidth, and when
requested local-polynomial degree/search metadata for the single-index
model. The continuous-outcome target is typically written
E[Y\mid X]=g(X^\prime\beta), with \beta normalized for
identification; binary outcomes use the Klein-Spady route.
For book-length derivations, see Li and Racine (2007), Chapter 8 Semiparametric Single Index Models, especially Sections 8.1, 8.2.1, 8.4, 8.5, and 8.10, and Racine (2019), Chapter 8.
If you are using data of mixed types, then it is advisable to use the
data.frame function to construct your input data and not
cbind, since cbind will typically not work as
intended on mixed data types and will coerce the data to the same
type.
Caution: multivariate data-driven bandwidth selection methods are, by
their nature, computationally intensive. Virtually all methods
require dropping the ith observation from the data set,
computing an object, repeating this for all observations in the
sample, then averaging each of these leave-one-out estimates for a
given value of the bandwidth vector, and only then repeating
this a large number of times in order to conduct multivariate
numerical minimization/maximization. Furthermore, due to the potential
for local minima/maxima, restarting this procedure a large
number of times may often be necessary. This can be frustrating for
users possessing large datasets. For exploratory purposes, you may
wish to override the default search tolerances, say, setting
optim.reltol=.1 and conduct multistarting (the default is to
restart min(2, ncol(xdat)) times). Once the procedure terminates, you can
restart search with default tolerances using those bandwidths obtained
from the less rigorous search (i.e., set bws=bw on subsequent
calls to this routine where bw is the initial bandwidth
object). A version of this package using the Rmpi wrapper is
under development that allows one to deploy this software in a
clustered computing environment to facilitate computation involving
large datasets.
Tristen Hayfield tristen.hayfield@gmail.com, Jeffrey S. Racine racinej@mcmaster.ca
Aitchison, J. and C.G.G. Aitken (1976), “Multivariate binary discrimination by the kernel method,” Biometrika, 63, 413-420.
Hardle, W. and P. Hall and H. Ichimura (1993), “Optimal Smoothing in Single-Index Models,” The Annals of Statistics, 21, 157-178.
Ichimura, H., (1993), “Semiparametric least squares (SLS) and weighted SLS estimation of single-index models,” Journal of Econometrics, 58, 71-120.
Klein, R. W. and R. H. Spady (1993), “An efficient semiparametric estimator for binary response models,” Econometrica, 61, 387-421.
Hall, P. and J.S. Racine (2015), “Infinite Order Cross-Validated Local Polynomial Regression,” Journal of Econometrics, 185, 510-525.
Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.
Wang, M.C. and J. van Ryzin (1981), “A class of smooth estimators for discrete distributions,” Biometrika, 68, 301-309.
npindextest, npindex
## Not run:
# EXAMPLE 1 (INTERFACE=FORMULA): Generate a simple linear model then
# compute coefficients and the bandwidth using Ichimura's nonlinear
# least squares approach.
set.seed(12345)
n <- 100
x1 <- runif(n, min=-1, max=1)
x2 <- runif(n, min=-1, max=1)
y <- x1 - x2 + rnorm(n)
# Note - this may take a minute or two depending on the speed of your
# computer. Note also that the first element of the vector beta is
# normalized to one for identification purposes, and that X must contain
# at least one continuous variable.
bw <- npindexbw(formula=y~x1+x2, method="ichimura")
summary(bw)
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# EXAMPLE 1 (INTERFACE=DATA FRAME): Generate a simple linear model then
# compute coefficients and the bandwidth using Ichimura's nonlinear
# least squares approach.
set.seed(12345)
n <- 100
x1 <- runif(n, min=-1, max=1)
x2 <- runif(n, min=-1, max=1)
y <- x1 - x2 + rnorm(n)
X <- cbind(x1, x2)
# Note - this may take a minute or two depending on the speed of your
# computer. Note also that the first element of the vector beta is
# normalized to one for identification purposes, and that X must contain
# at least one continuous variable.
bw <- npindexbw(xdat=X, ydat=y, method="ichimura")
summary(bw)
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# EXAMPLE 2 (INTERFACE=DATA FRAME): Generate a simple binary outcome
# model then compute coefficients and the bandwidth using Klein and
# Spady's likelihood-based approach.
n <- 100
x1 <- runif(n, min=-1, max=1)
x2 <- runif(n, min=-1, max=1)
y <- ifelse(x1 + x2 + rnorm(n) > 0, 1, 0)
# Note that the first element of the vector beta is normalized to one
# for identification purposes, and that X must contain at least one
# continuous variable.
bw <- npindexbw(formula=y~x1+x2, method="kleinspady")
summary(bw)
# EXAMPLE 2 (INTERFACE=DATA FRAME): Generate a simple binary outcome
# model then compute coefficients and the bandwidth using Klein and
# Spady's likelihood-based approach.
n <- 100
x1 <- runif(n, min=-1, max=1)
x2 <- runif(n, min=-1, max=1)
y <- ifelse(x1 + x2 + rnorm(n) > 0, 1, 0)
X <- cbind(x1, x2)
# Note that the first element of the vector beta is normalized to one
# for identification purposes, and that X must contain at least one
# continuous variable.
bw <- npindexbw(xdat=X, ydat=y, method="kleinspady")
summary(bw)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.