Learn R Programming

McSpatial (version 2.0)

qregcpar: Conditionally Parametric LWR Quantile Estimation

Description

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.

Usage

qregcpar(form,nonpar,taumat=c(.10,.25,.50,.75,.90), window=.25,bandwidth=0,kern="tcub",distance="Mahal", target=NULL,data=NULL)

Arguments

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

Value

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.

Details

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 $\tau$ 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)$ <="" td="">
Triangular ``tria''
$(1-|z|) * I(|z|<1)$< td=""> 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)$

References

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.

See Also

qreglwr

Examples

Run this code
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)

Run the code above in your browser using DataLab