| npqreg | R Documentation |
npqreg computes a kernel quantile regression estimate of a one
(1) dimensional dependent variable on p-variate explanatory
data, given a set of evaluation points, training points (consisting of
explanatory data and dependent data), and a bandwidth specification
using the methods of Li and Racine (2008) and Li, Lin and Racine
(2013). A bandwidth specification can be a condbandwidth object,
or a bandwidth vector, bandwidth type and kernel type.
npqreg(bws, ...)
## S3 method for class 'formula'
npqreg(bws, data = NULL, newdata = NULL, ...)
## S3 method for class 'condbandwidth'
npqreg(bws,
txdat = stop("training data 'txdat' missing"),
tydat = stop("training data 'tydat' missing"),
exdat,
tau = 0.5,
gradients = FALSE,
tol = 1.490116e-04,
small = 1.490116e-05,
itmax = 10000,
...)
## Default S3 method:
npqreg(bws, txdat, tydat, ...)
These arguments identify the bandwidth specification, formula/data interface, and training data.
bws |
a bandwidth specification. This can be set as a |
data |
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 |
These arguments control where the quantile regression is evaluated and which fitted quantities are returned.
exdat |
a |
gradients |
[currently not supported] a logical value indicating that you want
gradients computed and returned in the resulting |
newdata |
An optional data frame in which to look for evaluation data. If omitted, the training data are used. |
tau |
a numeric value specifying the |
These arguments control the one-dimensional numerical quantile extraction step.
itmax |
integer maximum number of iterations allowed in the one-dimensional
quantile refinement. Defaults to |
small |
minimum interval width used by the one-dimensional quantile
refinement. Defaults to |
tol |
tolerance on the one-dimensional quantile location refinement.
Defaults to |
Further arguments are passed to the regression estimator or bandwidth interpretation path as needed.
... |
additional arguments supplied to specify the regression type,
bandwidth type, kernel types, training data, and so on.
To do this,
you may specify any of |
Documentation guide: see np.kernels for kernels, np.options for global options, and plot for plotting options.
Given a conditional distribution bandwidth object, npqreg
estimates the conditional distribution at candidate response values
and extracts the requested conditional quantile by a one-dimensional
numerical refinement over the observed support of the dependent
variable. The refinement minimizes the squared residual between the
estimated conditional distribution and the requested probability
tau. The arguments tol, small, and itmax
control this one-dimensional refinement.
npqreg returns a npqregression object. The generic
functions fitted (or quantile),
se, predict (when using
predict you must add the argument tau= to
generate predictions other than the median), and
gradients, extract (or generate) estimated values,
asymptotic standard errors on estimates, predictions, and gradients,
respectively, from the returned object. Furthermore, the functions
summary and plot support objects of this
type. The returned object has the following components:
eval |
evaluation points |
quantile |
estimation of the quantile regression function (conditional quantile) at the evaluation points |
quanterr |
asymptotic standard errors of the quantile regression estimates, based on the estimated conditional density at the fitted quantile |
quantgrad |
gradients at each evaluation point |
tau |
the |
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.
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.
Hall, P. and J.S. Racine and Q. Li (2004), “Cross-validation and the estimation of conditional probability densities,” Journal of the American Statistical Association, 99, 1015-1026.
Koenker, R. W. and G.W. Bassett (1978), “Regression quantiles,” Econometrica, 46, 33-50.
Koenker, R. (2005), Quantile Regression, Econometric Society Monograph Series, Cambridge University Press.
Li, Q. and J.S. Racine (2007), Nonparametric Econometrics: Theory and Practice, Princeton University Press.
Li, Q. and J.S. Racine (2008), “Nonparametric estimation of conditional CDF and quantile functions with mixed categorical and continuous data,” Journal of Business and Economic Statistics, 26, 423-434.
Li, Q. and J. Lin and J.S. Racine (2013), “Optimal Bandwidth Selection for Nonparametric Conditional Distribution and Quantile Functions”, Journal of Business and Economic Statistics, 31, 57-65.
Wang, M.C. and J. van Ryzin (1981), “A class of smooth estimators for discrete distributions,” Biometrika, 68, 301-309.
np.kernels, np.options, plot quantreg
## Not run:
# EXAMPLE 1 (INTERFACE=FORMULA): For this example, we compute a
# bivariate nonparametric quantile regression estimate for Giovanni
# Baiocchi's Italian income panel (see Italy for details)
data("Italy")
attach(Italy)
# First, compute the cross-validated bandwidths. Note - this may take a
# few minutes depending on the speed of your computer...
bw <- npcdistbw(formula=gdp~ordered(year))
# Note - numerical search for computing the quantiles may take a minute
# or so...
model.q0.25 <- npqreg(bws=bw, tau=0.25)
model.q0.50 <- npqreg(bws=bw, tau=0.50)
model.q0.75 <- npqreg(bws=bw, tau=0.75)
# Plot the resulting quantiles manually...
plot(ordered(year), gdp,
main="CDF Quantile Estimates for the Italian Income Panel",
xlab="Year",
ylab="GDP Quantiles")
lines(ordered(year), model.q0.25$quantile, col="red", lty=2)
lines(ordered(year), model.q0.50$quantile, col="blue", lty=3)
lines(ordered(year), model.q0.75$quantile, col="red", lty=2)
legend(ordered(1951), 32, c("tau = 0.25", "tau = 0.50", "tau = 0.75"),
lty=c(2, 3, 2), col=c("red", "blue", "red"))
detach(Italy)
# EXAMPLE 1 (INTERFACE=DATA FRAME): For this example, we compute a
# bivariate nonparametric quantile regression estimate for Giovanni
# Baiocchi's Italian income panel (see Italy for details)
data("Italy")
attach(Italy)
data <- data.frame(ordered(year), gdp)
# First, compute the likelihood cross-validation bandwidths (default).
# Note - this may take a few minutes depending on the speed of your
# computer...
bw <- npcdistbw(xdat=ordered(year), ydat=gdp)
# Note - numerical search for computing the quantiles will take a
# minute or so...
model.q0.25 <- npqreg(bws=bw, tau=0.25)
model.q0.50 <- npqreg(bws=bw, tau=0.50)
model.q0.75 <- npqreg(bws=bw, tau=0.75)
# Plot the resulting quantiles manually...
plot(ordered(year), gdp,
main="CDF Quantile Estimates for the Italian Income Panel",
xlab="Year",
ylab="GDP Quantiles")
lines(ordered(year), model.q0.25$quantile, col="red", lty=2)
lines(ordered(year), model.q0.50$quantile, col="blue", lty=3)
lines(ordered(year), model.q0.75$quantile, col="red", lty=2)
legend(ordered(1951), 32, c("tau = 0.25", "tau = 0.50", "tau = 0.75"),
lty=c(2, 3, 2), col=c("red", "blue", "red"))
detach(Italy)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.