npindexbw {np} | R Documentation |
npindexbw
computes a npindexbw
bandwidth
specification using the model Y = G(XB)
+ epsilon. 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, ...) ## S3 method for class 'NULL': npindexbw(xdat = stop("training data xdat missing"), ydat = stop("training data ydat missing"), bws, bandwidth.compute = TRUE, ...) ## Default S3 method: npindexbw(xdat = stop("training data xdat missing"), ydat = stop("training data ydat missing"), bws, bandwidth.compute = TRUE, nmulti, ...) ## S3 method for class 'sibandwidth': npindexbw(xdat = stop("training data xdat missing"), ydat = stop("training data ydat missing"), bws, nmulti, random.seed = 42, ...)
formula |
a symbolic description of variables on which bandwidth selection is to be performed. The details of constructing a formula are described below. |
data |
an optional data frame, list or environment (or object
coercible to a data frame by as.data.frame ) containing
the variables
in the model. If not found in data, the variables are taken from
environment(formula) , typically the environment from which the
function is called.
|
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen when the data contain
NA s. The default is set by the
na.action setting of options, and is
na.fail if that is unset. The (recommended) default is
na.omit .
|
xdat |
a p-variate data frame of explanatory data (training data) used to calculate the regression estimators. |
ydat |
a one (1) dimensional numeric or integer vector of dependent data, each
element i corresponding to each observation (row) i of
xdat .
|
bws |
a bandwidth specification. This can be set as a
singleindexbandwidth
object returned from an invocation of npindexbw , or
as a vector of parameters (beta) with each element i
corresponding to the coefficient for column i in xdat
where the first element is normalized to 1, and a scalar bandwidth
(h). If specified as a vector, then additional arguments will need
to be supplied as necessary to specify the bandwidth type, kernel
types, and so on.
|
method |
the single index model method, one of either “ichimura”
(default) (Ichimura (1993)) or “kleinspady” (Klein and Spady
(1993)). Defaults to
ichimura .
|
nmulti |
integer number of times to restart the process of finding extrema of
the cross-validation function from different (random) initial
points. Defaults to ncol(xdat) .
|
random.seed |
an integer used to seed R's random number generator. This ensures replicability of the numerical search. Defaults to 42. |
bandwidth.compute |
a logical value which specifies whether to do a numerical search for
bandwidths or not. If set to FALSE , a bandwidth object
will be returned with bandwidths set to those specified
in bws . Defaults to TRUE .
|
... |
additional arguments supplied to specify the parameters to the
sibandwidth S3 method, which is called during the numerical
search.
|
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 can be applied for any outcome datatype (i.e., continuous or discrete).
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.
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 nlm
nonlinear
minimization routines and npksum
. We have implemented
multistarting and strongly encourage its use in practice (the number
of multistarts defaults to the number of columns in xdat
).
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.
npindexbw
returns a sibandwidth
object, with the
following components:
bw |
bandwidth(s), scale factor(s) or nearest neighbours for the
data, xdat |
beta |
coefficients of the model |
fval |
objective function value at minimum |
If bwtype
is set to fixed
, an object containing
a scalar bandwidth (or scalar scale factor if bwscaling = TRUE
)
for the function G(XB) and an estimate of the
parameter vector B 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.
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 ftol=.01 and tol=.01 and
conduct multistarting (the default is to restart ncol(xdat)
times) as is done for a number of examples. 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 hayfietj@mcmaster.ca, 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.
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.
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.
# 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... Sys.sleep(5) # EXAMPLE 1 (INTERFACE=DATAFRAME): 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... Sys.sleep(5) # EXAMPLE 2 (INTERFACE=DATAFRAME): 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=DATAFRAME): 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)