Learn R Programming

McSpatial (version 1.1.1)

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",
  alldata=FALSE,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
alldata
If alldata=T, each observation is used as a target value for z. When alldata=F, the function is estimated at a set of points chosen by the locfit program using an adaptive decision tree approach, and the akima<
data
A data frame containing the data. Default: use data in the current working directory

Value

  • targetThe target points for the original estimation of the function.
  • xcoef.targetThe 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.seThe matrix of standard errors for B(z) at the target values of z. Dimension = ntarget x ntau x k.
  • xcoefThe matrix of estimated coefficients, B(z), at the original data points. Dimension = n x ntau x k.
  • xcoef.seThe matrix of standard errors for B(z) with z evaluated at all points in the data set. Dimension = n x ntau x k.
  • yhatThe 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 alldata=T. When alldata=F, the package locfit is used to find a good set of target points at which to evaluate the function. See Loader (1999, section 12.2) for a description of the algorithm used to determine the target points. The akima package is then used to interpolate the predicted values, the coefficient estimates, and the standard errors, Available kernel weighting functions include the following: lll{ Kernel Call abbreviation Kernel function K(z) Rectangular ``rect'' $\frac{1}{2} I(|z|

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])

# 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(maptools)
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")

Run the code above in your browser using DataLab