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 = W_{i}^{\prime} \gamma (Z_i) + u_i$ where $W_i'=(1,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, call, \dots)
## S3 method for class 'NULL':
npscoefbw(xdat = stop("invoked without data 'xdat'"),
          ydat = stop("invoked without data 'ydat'"),
          zdat = NULL,
          bws,
          ...)
## S3 method for class 'default':
npscoefbw(xdat = stop("invoked without data 'xdat'"),
          ydat = stop("invoked without data 'ydat'"),
          zdat = NULL,
          bws,
          nmulti,
          random.seed,
          cv.iterate,
          cv.num.iterations,
          backfit.iterate,
          backfit.maxiter,
          backfit.tol,
          bandwidth.compute = TRUE,
          bwmethod,
          bwscaling,
          bwtype,
          ckertype,
          ckerorder,
          ukertype,
          okertype,
          optim.method,
          optim.maxattempts,
          optim.reltol,
          optim.abstol,
          optim.maxit,
          ...)
## S3 method for class 'scbandwidth':
npscoefbw(xdat = stop("invoked without data 'xdat'"),
          ydat = stop("invoked without data 'ydat'"),
          zdat = NULL,
          bws,
          nmulti,
          random.seed = 42,
          cv.iterate = FALSE,
          cv.num.iterations = 1,
          backfit.iterate = FALSE,
          backfit.maxiter = 100,
          backfit.tol = .Machine$double.eps,
          bandwidth.compute = TRUE,
          optim.method = c("Nelder-Mead", "BFGS", "CG"),
          optim.maxattempts = 10,
          optim.reltol = sqrt(.Machine$double.eps),
          optim.abstol = .Machine$double.eps,
          optim.maxit = 500,
          ...)
as.data.frame) containing the variables
    in the model. If not found in data, the variables are taken from
   np when a bandwidth search has been implied by a call to
    another function. It is not recommended that the user set this.zdat, will also correspond to 
    $Z$ from the model eqxdat.xdat.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 eitFALSE, a scbandwidth object
    will be returned with bandwidths set to those specified
    in bws. Defaults to cv.ls
    specifies least-squares cross-validation, which is all that is
    currently supported. Defaults to cv.ls.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 data
    typesfixed. Option summary:
fixed: fixed bandwidths or scale factors 
generalized_nn: generagaussian, epanechnikov, or
    uniform. Defaults to gaussian.(2,4,6,8)). Kernel order specified along with a
  uniform continuous kernel type will be ignored. Defaults to
  2.aitchisonaitken or liracine. Defaults to
    aitchisonaitken.wangvanryzin or liracine. Defaults to
    wangvanryzin.min(5,ncol(xdat)).optim for minimization of
    the objective function. See ?optim for references. Defaults
    to "Nelder-Mead".the default method is an implementation of that of
optim. Defaults to 100.optim. Only useful
    for non-negative functions, as a tolerance for reaching
    zero. Defaults to .Machine$double.eps.optim.  The algorithm
    stops if it is unable to reduce the value by a factor of 'reltol *
    (abs(val) + reltol)' at a step.  Defaults to
    sqrt(.Machine$douoptim. Defaults
     to 500.FALSE.1.FALSE.100..Machine$double.eps.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 $k$th 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.
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 $i$th 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(5,ncol(zdat)) 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.
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.
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 Three classes of kernel estimators for the continuous data types 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 data types include the second, fourth, sixth, and eighth order Gaussian and Epanechnikov kernels, and the uniform kernel. Unordered discrete data types use a variation on Aitchison and Aitken's (1976) kernel, while ordered data types use a variation of the Wang and van Ryzin (1981) kernel.
 Cai Z. (2007), 
 Hastie, T. and R. Tibshirani (1993), 
Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.
  Li, Q. and J.S. Racine (2010), 
  Pagan, A. and A. Ullah (1999), Nonparametric Econometrics,
 Cambridge University Press.
 
 Racine, J.S. and D. Ouyang and Q. Li (2010), 
 Wang, M.C. and J. van Ryzin (1981), 
npregbw, npreg# EXAMPLE 1 (INTERFACE=FORMULA):
set.seed(42)
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=DATA FRAME): 
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)Run the code above in your browser using DataLab