| npplreg | R Documentation |
npplreg computes a partially linear kernel regression estimate
of a one (1) dimensional dependent variable on p+q-variate
explanatory data, using the model Y = X\beta + \Theta (Z) +
\epsilon given a set of estimation
points, 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.
npplreg(bws,
...)
## S3 method for class 'formula'
npplreg(bws,
data = NULL,
newdata = NULL,
y.eval = FALSE,
...,
se = FALSE)
## Default S3 method:
npplreg(bws,
txdat,
tydat,
tzdat,
nomad = FALSE,
...,
se = FALSE)
## S3 method for class 'plbandwidth'
npplreg(bws,
txdat = stop("training data txdat missing"),
tydat = stop("training data tydat missing"),
tzdat = stop("training data tzdat missing"),
exdat,
eydat,
ezdat,
residuals = FALSE,
...,
se = FALSE)
These arguments identify the bandwidth specification, formula/data interface, and partially linear training data.
bws |
a bandwidth specification. This can be set as a |
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 |
txdat |
a |
tydat |
a one (1) dimensional numeric or integer vector of dependent data, each
element |
tzdat |
a |
This argument controls the recommended automatic local-polynomial NOMAD route, which jointly selects continuous polynomial degree and bandwidths when these are computed inside npplreg.
nomad |
logical shortcut passed through to |
These arguments control where the partially linear regression is evaluated and which fitted quantities are returned.
exdat |
a |
eydat |
a one (1) dimensional numeric or integer vector of the true values
of the dependent variable. Optional, and used only to calculate the
true errors. By default,
evaluation takes place on the data provided by |
ezdat |
a |
newdata |
An optional data frame in which to look for evaluation data. If omitted, the training data are used. |
se |
a scalar logical value indicating whether to compute and retain
coefficient standard errors and their asymptotic covariance matrix.
Defaults to |
residuals |
a logical value indicating that you want residuals computed and
returned in the resulting |
y.eval |
If |
Further arguments are passed to npplregbw and its component npregbw searches when bandwidths are computed internally.
... |
additional arguments supplied to |
Use nppltest to test whether the designated parametric regressors enter linearly and additively given the nuisance covariates.
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. The same requirement applies to explicitly selected evaluation responses. Prediction without selected evaluation outcomes does not require a response column. An explicit formula transformation that returns numeric values is accepted; numerical scores are a modeling choice made by the user. Categorical predictors retain their existing support. Internal auxiliary responses used to represent predictors retain their established encoding.
With a formula-derived bandwidth object, supplying only tydat
replaces the evaluated response in retained-training-sample order: one row
per observation retained after the original subset and missing-value selection.
Original excluded rows are not restored; row names or equal lengths do not
imply original-data order. The effective na.action is then applied
jointly to the retained predictors and replacement response; any new omission
indices refer to this retained sample. The selected bandwidths remain fixed,
and the returned object retains the replacement sample for subsequent refits.
Use data for full formula-data replacement, not together with a partial
response replacement. Explicit native training arguments retain their separate
positional contract.
For native (non-formula) objects, named newdata columns are matched
to the retained variable names and reordered as needed. Extra columns are
ignored; missing, duplicate or ambiguous names are errors. An unnamed
matrix or vector remains positional for a single evaluation role.
Explicit native evaluation arguments retain their positional contract and
take precedence over newdata.
For a native bandwidth object, newdata is split into
exdat and ezdat using the retained linear and nonparametric
predictor names. Names must identify both roles unambiguously;
explicitly supplied native evaluation arguments take precedence. This
evaluates at the requested rows without repeating bandwidth selection.
Nuisance regressions inherit numerical ridging from npreg.
Their point fits do not apply its residual uncertainty correction to the
separate partially linear coefficient covariance described below.
Documentation guide: see npplregbw for partially linear
bandwidth selection, npregbw for the component
nonparametric regression search controls, np.kernels
for kernels, np.options for global options, and
plot, plot.np for plotting options.
When bws is omitted, the formula and default methods call
npplregbw first and pass bandwidth-selection arguments
from ... to that call. When bws is already a
plbandwidth object, npplreg estimates with the stored
bandwidth metadata in that object.
Argument groups for bandwidth selection are documented on
npplregbw and, for the component nonparametric
regressions, npregbw. The most common workflow is to
choose the linear X variables and nonparametric Z
variables first, then bandwidth/search controls for the
Z-side nonparametric regressions, and finally
local-polynomial/NOMAD controls when using polynomial-adaptive fits.
For S3 plotting help, see plot.np. You can list
available plot methods with methods("plot").
npplreg uses a combination of OLS and nonparametric
regression to estimate the parameter \beta in the model
Y = X\beta + \Theta (Z) + \epsilon.
npplreg implements a variety of methods for
nonparametric regression on multivariate (q-variate) explanatory
data defined over a set of possibly continuous and/or discrete
(unordered, ordered) data. The approach is based on Li and Racine
(2003) who employ ‘generalized product kernels’ that admit a mix
of continuous and discrete data types.
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.
Data contained in the data frame tzdat may be a mix of
continuous (default), unordered discrete (to be specified in the data
frame tzdat using factor), and ordered discrete
(to be specified in the data frame tzdat using
ordered). Data can be entered in an arbitrary order and
data types will be detected automatically by the routine (see
np for details).
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.
For practitioners who want the recommended automatic local-polynomial degree-and-bandwidth NOMAD route
without spelling out all LP tuning arguments,
npplreg(..., nomad=TRUE) and npplregbw(..., nomad=TRUE)
expand missing settings to the same documented preset. Explicit
incompatible settings fail fast rather than being silently rewritten.
npplreg returns a plregression object. The generic
accessor functions coef, fitted,
residuals, predict, and
vcov, extract (or
estimate) coefficients, estimated values, residuals,
predictions, and variance-covariance matrices,
respectively, from
the returned object. Furthermore, the functions summary
and plot support objects of this type. The returned object
has the following components:
For plregression objects, predict(object, se.fit = TRUE)
returns a list with components fit and se.fit. The
se.fit component contains asymptotic prediction standard errors
computed from the partially linear fitted-value linear operator and
the squared residuals from the training fit. This explicit prediction
request works even when the original model used se = FALSE;
it does not require coefficient covariance or alter the original object.
With se = TRUE, coefficient covariance allows conditional
heteroskedasticity. Let
\widetilde X be the residualized linear design, u the residuals
from the training fit, and A=\widetilde X'\widetilde X. The returned
covariance is
\{n/(n-p-q)\} A^{-1}\widetilde X'\mathrm{diag}(u^2)\widetilde X A^{-1},
where n is the number of complete training observations, p is
the number of linear regressors and q the number of smoothing
variables. The multiplier retains the package's finite-sample convention;
it is not an estimate of a smoother's effective degrees of freedom.
Coefficient standard errors are square roots of its diagonal. This
coefficient covariance and the fitted-value prediction errors above are
different targets; neither changes the coefficient or bandwidth estimates.
evalx |
evaluation points |
evalz |
evaluation points |
mean |
estimation of the regression, or conditional mean, at the evaluation points |
xcoef |
coefficient(s) corresponding to the components
|
xcoeferr |
standard errors of the coefficients, or |
xcoefvcov |
covariance matrix of the coefficients, or |
se |
whether coefficient uncertainty was requested |
bws |
the canonical bandwidth object, stored as a
|
bw |
backward-compatible alias for |
resid |
if |
R2 |
coefficient of determination (Doksum and Samarov (1995)) |
MSE |
mean squared error |
MAE |
mean absolute error |
MAPE |
mean absolute percentage error |
CORR |
absolute value of Pearson's correlation coefficient |
SIGN |
fraction of observations where fitted and observed values agree in sign |
An existing bandwidth object retains its training omission policy. Explicit
na.action overrides are supported only by the formula replacement-data
or replacement-response routes that already own that policy, and by documented
regression and single-index prediction policies. Unsupported stored native or
formula evaluation overrides are rejected rather than silently ignored.
For replacement native inputs, prepare the desired complete data explicitly.
Reusing retained training does not re-run its missing-value callback.
The partially linear model is
Y=X\beta+\Theta(Z)+\epsilon. The Robinson-style construction
residualizes Y and each column of X on Z, then
solves the final least-squares problem using those residualized
variables. Thus the nonparametric part of the problem is a sequence
of conditional-mean regressions E[Y\mid Z] and
E[X_j\mid Z], followed by the parametric solve for
\beta. In local-polynomial/NOMAD fits, the nuisance regressions
may select child-specific continuous polynomial degrees.
For book-length derivations, see Li and Racine (2007), Chapter 7 Semiparametric Partially Linear Models, especially Sections 7.1, 7.2, and 7.4, and Racine (2019), Chapter 8 Semiparametric Conditional Mean Function Estimation, especially Robinson's partially linear model.
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.
For formula fits, character-valued missing-data policies are resolved
through the stats model-frame owner; pass a caller-local policy as
a function object rather than its name. With replacement training data,
an explicit na.action, including NULL, takes precedence
over the saved policy. Native fitting still requires complete rows, so
a permissive policy does not guarantee the same retained sample as
stats::model.frame.
When reusing a bandwidth object without explicit training or evaluation
data, newly constructed bandwidth objects use retained training values.
A fit with explicit replacement training data retains that sample in its
returned bandwidth object; evaluation grids do not replace training data.
Older objects without retained samples use their stored call environment
when available and may require explicit training inputs after
saveRDS() and readRDS(). Custom formula transformations used
on new evaluation data must still be available.
All bias-corrected confidence intervals and bands are experimental (pre-beta research), incomplete, and not recommended for general-purpose inference. This status remains in effect unless the documentation explicitly states otherwise for a particular method and scope. It applies wherever bias-corrected bounds are available: asymptotic and bootstrap constructions, including legacy methods, pointwise intervals, Bonferroni intervals and simultaneous bands, for levels and supported derivatives.
These methods form an ongoing research project. Implementation support, numerical checks and favorable simulation results in selected settings do not establish generally valid coverage. Coverage can fail outside the studied settings, and available options do not constitute a general solution to bias-corrected inference. Method-specific assumptions, restrictions and known failures must be considered when experimenting with these bounds.
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.
Doksum, K. and A. Samarov (1995), “Nonparametric estimation of global functionals and a measure of the explanatory power of covariates in regression,” The Annals of Statistics, 23 1443-1473.
Gao, Q. and L. Liu and J.S. Racine (2015), “A partially linear kernel estimator for categorical data,” Econometric Reviews, 34 (6-10), 958-977.
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.
Pagan, A. and A. Ullah (1999), Nonparametric Econometrics, Cambridge University Press.
Racine, J.S. and Q. Li (2004), “Nonparametric estimation of regression functions with both categorical and continuous data,” Journal of Econometrics, 119, 99-130.
Robinson, P.M. (1988), “Root-n-consistent semiparametric regression,” Econometrica, 56, 931-954.
Wang, M.C. and J. van Ryzin (1981), “A class of smooth estimators for discrete distributions,” Biometrika, 68, 301-309.
nppltest,
np.kernels, np.options, plot, plot.np
npregbw, npreg
## Not run:
# EXAMPLE 1 (INTERFACE=FORMULA): For this example, we simulate an
# example for a partially linear model and compare the coefficient
# estimates from the partially linear model with those from a correctly
# specified parametric model...
set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rbinom(n, 1, .5)
z1 <- rbinom(n, 1, .5)
z2 <- rnorm(n)
y <- 1 + x1 + x2 + z1 + sin(z2) + rnorm(n)
# First, compute data-driven bandwidths. This may take a few minutes
# depending on the speed of your computer...
bw <- npplregbw(formula=y~x1+factor(x2)|factor(z1)+z2)
# Next, compute the partially linear fit
pl <- npplreg(bws=bw, se=TRUE)
# Print a summary of the model...
summary(pl)
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# Retrieve the coefficient estimates and their standard errors...
coef(pl)
coef(pl, se = TRUE)
# Compare the partially linear results to those from a correctly
# specified model's coefficients for x1 and x2
ols <- lm(y~x1+factor(x2)+factor(z1)+I(sin(z2)))
# The intercept is coef()[1], and those for x1 and x2 are coef()[2] and
# coef()[3]. The standard errors are the square root of the diagonal of
# the variance-covariance matrix (elements 2 and 3)
coef(ols)[2:3]
sqrt(diag(vcov(ols)))[2:3]
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# Plot the regression surfaces via plot() (i.e., plot the `partial
# regression surface plots').
if (interactive()) plot(bw)
# Plot the regression surfaces with variability bounds based on bootstrap standard errors.
plot(bw,
errors="bootstrap")
# EXAMPLE 1 (INTERFACE=DATA FRAME): For this example, we simulate an
# example for a partially linear model and compare the coefficient
# estimates from the partially linear model with those from a correctly
# specified parametric model...
set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rbinom(n, 1, .5)
z1 <- rbinom(n, 1, .5)
z2 <- rnorm(n)
y <- 1 + x1 + x2 + z1 + sin(z2) + rnorm(n)
X <- data.frame(x1, factor(x2))
Z <- data.frame(factor(z1), z2)
# First, compute data-driven bandwidths. This may take a few minutes
# depending on the speed of your computer...
bw <- npplregbw(xdat=X, zdat=Z, ydat=y)
# Next, compute the partially linear fit
pl <- npplreg(bws=bw, se=TRUE)
# Print a summary of the model...
summary(pl)
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# Retrieve the coefficient estimates and their standard errors...
coef(pl)
coef(pl, se = TRUE)
# Compare the partially linear results to those from a correctly
# specified model's coefficients for x1 and x2
ols <- lm(y~x1+factor(x2)+factor(z1)+I(sin(z2)))
# The intercept is coef()[1], and those for x1 and x2 are coef()[2] and
# coef()[3]. The standard errors are the square root of the diagonal of
# the variance-covariance matrix (elements 2 and 3)
coef(ols)[2:3]
sqrt(diag(vcov(ols)))[2:3]
# Sleep for 5 seconds so that we can examine the output...
if (interactive()) Sys.sleep(5)
# Plot the regression surfaces via plot() (i.e., plot the `partial
# regression surface plots').
if (interactive()) plot(bw)
# Plot the regression surfaces with variability bounds based on bootstrap standard errors.
plot(bw,
errors="bootstrap")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.