npscoefbw {np} | R Documentation |
npscoefbw
computes a bandwidth object for a smooth
coefficient kernel regression estimate of a one (1) dimensional
dependent variable on
p+q-variate explanatory data, using the model
Y_i = t(W_i) * gamma(Z_i) +
u_i where t(W_i) = (1,t(X_i))
given training points (consisting of explanatory data and dependent
data), and a bandwidth specification, which can be a rbandwidth
object, or a bandwidth vector, bandwidth type and kernel type.
npscoefbw(...) ## S3 method for class 'formula': npscoefbw(formula, data, subset, na.action,...) ## S3 method for class 'NULL': npscoefbw(xdat = stop("invoked without data 'xdat'"), ydat = stop("invoked without data 'ydat'"), zdat = NULL, bws, ...) ## Default S3 method: npscoefbw(xdat = stop("invoked without data 'xdat'"), ydat = stop("invoked without data 'ydat'"), zdat = NULL, bws, nmulti, cv.iterate, cv.num.iterations, backfit.iterate, backfit.maxiter, backfit.tol, ftol, tol, bandwidth.compute = TRUE, bwmethod, bwscaling, bwtype, ckertype, ckerorder, ...) ## S3 method for class 'scbandwidth': npscoefbw(xdat = stop("invoked without data 'xdat'"), ydat = stop("invoked without data 'ydat'"), zdat = NULL, bws, nmulti, cv.iterate = FALSE, cv.num.iterations = 1, backfit.iterate = FALSE, backfit.maxiter = 100, backfit.tol = .Machine$double.eps, ftol = .Machine$double.eps, tol = sqrt(.Machine$double.eps), bandwidth.compute = TRUE, ...)
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),
which, by default, populates the columns 2 through p+1
of W in the model equation, and in the
absence of zdat , will also correspond to
Z from the model equation.
|
ydat |
a one (1) dimensional numeric or integer vector of dependent data, each
element i corresponding to each observation (row) i of
xdat .
|
zdat |
an optionally specified q-variate data frame of explanatory
data (training data), which corresponds to Z
in the model equation. Defaults to be the same as xdat .
|
bws |
a bandwidth specification. This can be set as a scbandwidth
object returned from a previous invocation, or as a vector of
bandwidths, with each element i corresponding to the bandwidth
for column i in xdat . In either case, the bandwidth
supplied will serve as a starting point in the numerical search for
optimal bandwidths. If specified as a vector, then additional
arguments will need to be supplied as necessary to specify the
bandwidth type, kernel types, selection methods, and so on. This can
be left unset.
|
... |
additional arguments supplied to specify the regression type, bandwidth type, kernel types, selection methods, and so on, detailed below. |
bandwidth.compute |
a logical value which specifies whether to do a numerical search for
bandwidths or not. If set to FALSE , a scbandwidth object
will be returned with bandwidths set to those specified
in bws . Defaults to TRUE .
|
bwmethod |
which method was used to select bandwidths. cv.ls
specifies least-squares cross-validation, which is all that is
currently supported. Defaults to cv.ls .
|
bwscaling |
a logical value that when set to TRUE the supplied
bandwidths are interpreted as `scale factors' (c[j]),
otherwise when the value is FALSE they are interpreted as `raw
bandwidths' (h[j] for continuous datatypes,
lambda[j] for discrete datatypes). For continuous
datatypes, c[j] and h[j] are related by the
formula h[j] =
c[j]*sigma[j]*n^(-1/(2*P+l)), where sigma[j]
is the standard deviation of continuous variable j,
n the number of observations, P the order of the kernel,
and l the number of continuous variables. For discrete
datatypes, c[j] and h[j] are related by the
formula h[j] = c[j]*n^(-2/(2*P+l)),
where here [j] denotes discrete variable j.
Defaults to FALSE .
|
bwtype |
character string used for the continuous variable bandwidth type,
specifying the type of bandwidth provided. Defaults to
fixed . Option summary:fixed : fixed bandwidths or scale factors generalized_nn : generalized nearest neighbors adaptive_nn : adaptive nearest neighbors
|
ckertype |
character string used to specify the continuous kernel type.
Can be set as gaussian , epanechnikov , or
uniform . Defaults to gaussian .
|
ckerorder |
numeric value specifying kernel order (one of
(2,4,6,8) ). Kernel order specified along with a
uniform continuous kernel type will be ignored. Defaults to
2 .
|
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) .
|
ftol |
tolerance on the value of the cross-validation function
evaluated at located minima. Defaults to 1.19e-07
(FLT_EPSILON)
|
tol |
tolerance on the position of located minima of the
cross-validation function. Defaults to 1.49e-08
(sqrt(DBL_EPSILON))
|
cv.iterate |
boolean value specifying whether or not to perform iterative,
cross-validated backfitting on the data. See details for limitations
of the backfitting procedure. Defaults to FALSE .
|
cv.num.iterations |
integer specifying the number of times to iterate the backfitting
process over all covariates. Defaults to 1 .
|
backfit.iterate |
boolean value specifying whether or not to iterate evaluations of
the smooth coefficient estimator, for extra accuracy, during the
cross-validated backfitting procedure. Defaults to FALSE .
|
backfit.maxiter |
integer specifying the maximum number of times to iterate the
evaluation of the smooth coefficient estimator in the attempt to
obtain the desired accuracy. Defaults to 100 .
|
backfit.tol |
tolerance to determine convergence of iterated evaluations of the
smooth coefficient estimator. Defaults to .Machine$double.eps .
|
npscoefbw
implements a variety of methods for semiparametric regression on
multivariate (p+q-variate) explanatory data defined over a set of possibly
continuous data. The approach is
based on Li and Racine (2003) who employ ‘generalized product kernels’
that admit a mix of continuous and discrete datatypes.
Three classes of kernel estimators for the continuous datatypes are available: fixed, adaptive nearest-neighbor, and generalized nearest-neighbor. Adaptive nearest-neighbor bandwidths change with each sample realization in the set, x[i], when estimating the density at the point x. Generalized nearest-neighbor bandwidths change with the point at which the density is estimated, x. Fixed bandwidths are constant over the support of x.
npscoefbw
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
, ydat
, and
zdat
parameters. Use of these two interfaces is mutually exclusive.
Data contained in the data frame xdat
may be continuous and
in zdat
may be of mixed type. Data can be entered in an
arbitrary order
and data
types will be detected automatically by the routine (see np
for
details).
Data for which bandwidths are to be estimated may be specified
symbolically. A typical description has the form dependent
data
~
parametric
explanatory
data
|
nonparametric
explanatory
data
,
where dependent
data
is a univariate response, and
parametric
explanatory
data
and
nonparametric
explanatory
data
are both series of variables specified by name, separated by
the separation character '+'. For example, y1 ~ x1 + x2 | z1
specifies that the bandwidth object for the smooth coefficient model
with response y1
, linear parametric regressors x1
and
x2
, and nonparametric regressor (that is, the slope-changing
variable) z1
is to be estimated. See below for further examples.
In the case where the nonparametric (slope-changing) variable is not
specified, it is assumed to be the same as the parametric variable.
A variety of kernels may be specified by the user. Kernels implemented for continuous datatypes include the second, fourth, sixth, and eighth order Gaussian and Epanechnikov kernels, and the uniform kernel. Unordered discrete datatypes use a variation on Aitchison and Aitken's (1976) kernel, while ordered datatypes use a variation of the Wang and van Ryzin (1981) kernel.
if bwtype
is set to fixed
, an object containing bandwidths
(or scale factors if bwscaling = TRUE
) is returned. If it is set to
generalized_nn
or adaptive_nn
, then instead the kth nearest
neighbors are returned for the continuous variables while the discrete
kernel bandwidths are returned for the discrete variables. Bandwidths
are stored in a vector under the component name bw
. Backfitted
bandwidths are stored under the component name bw.fitted
.
The functions 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(zdat)
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.
Support for backfitted bandwidths is experimental and is limited in functionality. The code does not support asymptotic standard errors or out of sample estimates with backfitting.
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.
Cai Z. (2007), “Trending time-varying coefficient time series models with serially correlated errors,” Journal of Econometrics, 136, 163-188.
Hastie, T. and R. Tibshirani (1993), “Varying-coefficient models,” Journal of the Royal Statistical Society, B 55, 757-796.
Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.
Li, Q. and J.S. Racine (2007), “Smooth varying-coefficient nonparametric models for qualitative and quantitative data,” manuscript.
Pagan, A. and A. Ullah (1999), Nonparametric Econometrics, Cambridge University Press.
Racine, J.S. and D. Ouyang and Q. Li (2007), “Nonparametric multilevel models: a smoothing approach,” manuscript.
Wang, M.C. and J. van Ryzin (1981), “A class of smooth estimators for discrete distributions,” Biometrika, 68, 301-309.
# EXAMPLE 1 (INTERFACE=FORMULA): For this example, we compute a # smooth coefficient model with differing X and Z data n <- 100 x <- runif(n) z <- runif(n, min=-2, max=2) y <- x*exp(z)*(1.0+rnorm(n,sd = 0.2)) bw <- npscoefbw(formula=y~x|z) summary(bw) # EXAMPLE 1 (INTERFACE=DATAFRAME): For this example, we compute a # smooth coefficient model with differing X and Z data n <- 100 x <- runif(n) z <- runif(n, min=-2, max=2) y <- x*exp(z)*(1.0+rnorm(n,sd = 0.2)) bw <- npscoefbw(xdat=x, ydat=y, zdat=z) summary(bw)