Description Usage Arguments Details Value References See Also Examples
Estimates a model of the form y = XB(z) + u using locally weighted quantile regression for a set of user-provided quantiles. z can include one or two variables.
1 2 3 4 |
form |
Model formula |
nonpar |
List of either one or two variables for z. Formats: qregcpar(y~xlist, nonpar=~z1, ...) or qregcpar(y~xlist, nonpar=~z1+z2, ...). Important: note the "~" before the first z variable. |
taumat |
Vector of target quantiles. Default: taumat=c(.10,.25,.50,.75,.90) |
.
window |
Window size. Default: 0.25. |
bandwidth |
Bandwidth. Default: not used. |
kern |
Kernel weighting functions. Default is the tri-cube. Options include "rect", "tria", "epan", "bisq", "tcub", "trwt", and "gauss". |
distance |
Options: "Euclid", "Mahal", or "Latlong" for Euclidean, Mahalanobis, or "great-circle" geographic distance. May be abbreviated to the first letter but must be capitalized. Note: qregcpar looks for the first two letters to determine which variable is latitude and which is longitude, so the data set must be attached first or specified using the data option; options like data$latitude will not work. Default: Mahal. |
target |
If target = NULL, uses the maketarget command to form targets using the values specified for window, bandwidth, and kern. If target="alldata", each observation is used as a target value for x. A set of target values can be supplied directly. |
data |
A data frame containing the data. Default: use data in the current working directory |
The list of explanatory variables is specified in the base model formula while Z is specified using nonpar. X can include any number of explanatory variables, but Z must have at most two.
The estimated value of y at a target value z_0 and a quantile τ is the predicted value from a weighted quantile regression of y on X with weights given by K. When Z includes a single variable, K is a simple kernel weighting function: K((z - z_0 )/(sd(z)*h)) . When Z includes two variables (e.g, nonpar=~z1+z2), the method for specifying K depends on the distance option. Under either option, the ith row of the matrix Z = (z1, z2) is transformed such that z_i = sqrt(z_i * V * t(z_i)). Under the "Mahal" option, V is the inverse of cov(Z). Under the "Euclid" option, V is the inverse of diag(cov(Z)). After this transformation, the weights again reduce to the simple kernel weighting function K((z- z_0 )/(sd(z)*h)).
The great circle formula is used to define K when distance = "Latlong"; in this case, the variable list for nonpar must be listed as nonpar = ~latitude+longitude (or ~lo+la or ~lat+long, etc), with the longitude and latitude variables expressed in degrees (e.g., -87.627800 and 41.881998 for one observation of longitude and latitude, respectively). The order in which latitude and longitude are listed does not matter and the function only looks for the first two letters to determine which variable is latitude and which is the longitude. It is important to note that the great circle distance measure is left in miles rather than being standardized. Thus, the window option should be specified when distance = "Latlong" or the bandwidth should be adjusted to account for the scale. The kernel weighting function becomes K(distance/h) under the "Latlong" option. h is specified by the bandwidth or window option.
For each quantile, the estimated coefficient matrix, xcoef, includes an intercept (the first column in k of xcoef) and the coefficients for the explanatory variables. The dimension of xcoef is n x ntau x k.
Estimation can be very slow when target = "alldata". The maketarget command can be used to identify target points.
Available kernel weighting functions include the following:
Kernel | Call abbreviation | Kernel function K(z) |
Rectangular | ``rect'' | 1/2 * I(|z|<1) |
Triangular | ``tria'' | (1-|z|) * I(|z|<1) |
Epanechnikov | ``epan'' | 3/4 * (1-z^2)*I(|z| < 1) |
Bi-Square | ``bisq'' | 15/16 * (1-z^2)^2 * I(|z| < 1) |
Tri-Cube | ``tcub'' | 70/81 * (1-|z|^3)^3 * I(|z| < 1) |
Tri-Weight | ``trwt'' | 35/32 * (1-z^2)^3 * I(|z| < 1) |
Gaussian | ``gauss'' | 2pi^{-.5} exp(-z^2/2) |
target |
The target points for the original estimation of the function. |
xcoef.target |
The matrix of estimated coefficients, B(z), at the target values of z. Dimension = ntarget x ntau x k, where ntarget = number of target poitns, ntau = number of quantiles, and k = number of explanatory variables including the intercept. |
xcoef.target.se |
The matrix of standard errors for B(z) at the target values of z. Dimension = ntarget x ntau x k. |
xcoef |
The matrix of estimated coefficients, B(z), at the original data points. Dimension = n x ntau x k. |
xcoef.se |
The matrix of standard errors for B(z) with z evaluated at all points in the data set. Dimension = n x ntau x k. |
yhat |
The matrix of predicted values of y at the original data points. Dimension = n x ntau. |
Cleveland, William S. and Susan J. Devlin, "Locally Weighted Regression: An Approach to Regression Analysis by Local Fitting," Journal of the American Statistical Association 83 (1988), 596-610.
Loader, Clive. Local Regression and Likelihood. New York: Springer, 1999.
Koenker, Roger. Quantile Regression. New York: Cambridge University Press, 2005. Chapter 7 and Appendix A.9.
McMillen, Daniel P., "Issues in Spatial Data Analysis," Journal of Regional Science 50 (2010), 119-141.
McMillen, Daniel P. and Christian Redfearn, “Estimation and Hypothesis Testing for Nonparametric Hedonic House Price Functions,” Journal of Regional Science 50 (2010), 712-733.
Pagan, Adrian and Aman Ullah. Nonparametric Econometrics. New York: Cambridge University Press, 1999.
qreglwr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | data(cookdata)
cookdata$obs <- seq(1,nrow(cookdata))
cookdata <- cookdata[!is.na(cookdata$FAR),]
par(ask=TRUE)
# 1. CPAR LWR estimates, y = a(DCBD) + b(dcbd)*DCBD + u
fit <- qregcpar(LNFAR~DCBD,nonpar=~DCBD, taumat=c(.10,.50,.90),
kern="bisq", window=.30, data=cookdata)
o <- order(cookdata$DCBD)
plot(cookdata$DCBD[o], fit$yhat[o,1],type="l", main="Log Floor Area Ratio",
xlab="Distance from CBD",ylab="Log FAR")
lines(cookdata$DCBD[o], fit$yhat[o,2])
lines(cookdata$DCBD[o], fit$yhat[o,3])
## Not run:
# 2. CPAR estimates, y = a(lat,long) + b(lat,long)xDCBD + u
fit <- qregcpar(LNFAR~DCBD, nonpar=~LATITUDE+LONGITUDE, taumat=c(.10,.90),
kern="bisq", window=.30, distance="LATLONG", data=cookdata)
plot(cookdata$DCBD, cookdata$LNFAR,main="Log Floor Area Ratio",
xlab="Distance from CBD",ylab="Log FAR")
points(cookdata$DCBD, fit$yhat[,1], col="red")
plot(cookdata$DCBD, cookdata$LNFAR,main="Log Floor Area Ratio",
xlab="Distance from CBD",ylab="Log FAR")
points(cookdata$DCBD, fit$yhat[,2], col="red")
library(RColorBrewer)
cmap <- readShapePoly(system.file("maps/CookCensusTracts.shp",
package="McSpatial"))
cmap$yhat10[cookdata$obs] <- fit$yhat[,1]
cmap$yhat90[cookdata$obs] <- fit$yhat[,2]
cmap$yhat1090 <- cmap$yhat90 - cmap$yhat10
brks <- seq(min(cmap$yhat1090,na.rm=TRUE),max(cmap$yhat1090,na.rm=TRUE),length=9)
spplot(cmap,"yhat1090",at=brks,col.regions=rev(brewer.pal(9,"RdBu")),
main="Difference between .10 and.90 Quantiles")
## End(Not run)
|
Loading required package: lattice
Loading required package: locfit
locfit 1.5-9.1 2013-03-22
Loading required package: maptools
Loading required package: sp
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
Loading required package: quantreg
Loading required package: SparseM
Attaching package: 'SparseM'
The following object is masked from 'package:base':
backsolve
Loading required package: RANN
There were 21 warnings (use warnings() to see them)
Warning message:
readShapePoly is deprecated; use rgdal::readOGR or sf::st_read
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.