Learn R Programming

McSpatial (version 2.0)

qregsim1: Changes in Distributions Implied by Quantile Regression Estimates

Description

Uses quantile regression results to simulate the effects of an explanatory variable on the distribution of the dependent variable.

Usage

qregsim1(formall, formx, bmat, taumat, xvalues=NULL, ytarget=NULL, xcolors=NULL,graphx=TRUE, graphy=TRUE, graphsim=TRUE, histogram=FALSE, histfreq=FALSE, yname=NULL, xname=NULL, nsim=0, bwadjust=1, legloc="topright",data=NULL)

Arguments

formall
Formula with the dependent variable and all explanatory variables, as provided to the qregbmat or qregcpar command.
formx
The explanatory variable to be analyzed. Specified as a formula, e.g., formx=~x.
bmat
Matrix of coefficient estimates from the qregbmat or qregcpar command.
taumat
The vector of quantile values represented in bmat.
xvalues
Vector of explanatory variable values for discrete changes. If xvalues = NULL, the values are set to xvalues <- quantile(x,c(.25,.75)).
ytarget
Vector of target values for the density functions involving y. The values in ytarget are used as the target points for the predicted and actual values of y. The same values of ytarget are also used as the target values for the simulations.
xcolors
Vector of colors for the density function graphs. Default for two values of xvalues is c("black","red"). For more than two values, the default is drawn from the RColorBrewer package: xcolors = brewer.pal(nx,"Blues").
graphx
If graphx=T, presents the kernel density function for the explanatory variable.
graphy
If graphy=T, presents density functions for the actual and predicted values of the dependent variable.
graphsim
If graphsim=T, presents graphs of the density functions for the predicted values of y at the values specified in xvalues.
histogram
If histogram=T and graphx=T, the density function for the explanatory variable is presented as a histogram. Not relevant if graphx=F.
histfreq
If histogram=T and graphx=T, the histogram is presented using frequencies rather than densities. Not relevant if graphx=F or histogram=F.
yname
A label used for the dependent variable in the density graphs, e.g., yname = "Log of Sale Price".
xname
A label for graphs involving the explanatory variable, e.g., xname = "x1".
nsim
Number of simulations for quantile distributions. Default: nsim=0.
bwadjust
Factor used to adjust bandwidths for kernel densities. Smoother functions are produced when bwadjust>1. Passed directly to the density function's adjust option. Default: bwadjust=1.
legloc
The legend location.
data
A data frame containing the data. Default: use data in the current working directory.

Value

ytarget
The values for the horizontal axis of the quantile predictions at xvalues.
densyhat
Matrix of predictions for the predicted values of y at the values specified in xvalues. The dimension of the matrix is n x length(xvalues).
densy1
The values of the density function for the actual values of the dependent variable. densy1=NULL if graphy=F.
densy2
The values of the density function for the quantile regression predictions of the dependent variable. densy2=NULL if graphy=F.

Details

The conditional quantile function is $y(\tau) = \alpha(\tau) + \beta(\tau)*x + \lambda(\tau)*z$. The complete model specification is listed in formall, while x is specified in formx, e.g., formall <- y~x+z and formx <- ~x. When nsim = 0, the qregsim1 command simply calculates predicted values of y at each value of x listed in xvalues and at each $\tau$ list in taumat. Thus, the first column of densyhat holds the estimated density function for $\hat{y}(\tau) = \hat{\alpha}(\tau) + \hat{\beta}(\tau)*xvalues[1] + \hat{\lambda}(\tau)*z$, the second column holds the predictions at xvalues[2], and so on. The estimates are evaluated at each value of $\tau$, which leads to an n x length(taumat) set of predictions for each value of xvalues. Kernel density estimates are then calculated for these predictions.

The qregsim1 command can follow either qregbmat or qregcpar. All that differs is the dimension of bmat: using qregcpar, the coefficients vary by observation.

If nsim > 0, the qregsim1 function uses a simulation procedure based on the Machado-Mata (2005) approach to simulate the effect of an explanatory variable on the distribution of the dependent variable. The function begins by drawing (with replacement) nsim values from the rows of the explanatory variable matrix and nsim values of $\tau$. With nsim values of both the explanatory variables and coefficient vectors, the predictions are simply $\hat{y}_j(\tau) = \hat{\alpha}(\tau) + \hat{\beta}(\tau)*xvalues[j] + \hat{\lambda}(\tau)*z$ for $j = 1,...,length(xvalues)$.

The n x length(xvalues) matrix densyhat holds the full set of predictions.

In addition to the predicted values of $y$ at xvalues, the qregsim1 command can produce the following:

1. The estimated density function for the explanatory variable (if graphx=T). Presented as a histogram if histogram=T.

2. The estimated quantile regression coefficients for the variable specified by formx. This graph is produced if graphb=T.

References

Koenker, Roger. Quantile Regression. New York: Cambridge University Press, 2005.

Machado, J.A.F. and Mata, J., "Counterfactual Decomposition of Changes in Wage Distributions using Quantile Regression," Journal of Applied Econometrics 20 (2005), 445-465.

McMillen, Daniel P., "Changes in the Distribution of House Prices over Time: Structural Characteristics, Neighborhood or Coefficients?" Journal of Urban Economics 64 (2008), 573-589.

See Also

qregbmat

qregsim2

qregcpar

Examples

Run this code

par(ask=TRUE)
data(matchdata)
matchdata$age <- matchdata$year - matchdata$yrbuilt 
tvect <- seq(.10,.90,.10)
bmat <- qregbmat(lnprice~lnland+lnbldg+age+factor(year), data=matchdata,
  graph.factor=TRUE,taumat=tvect,graphb=FALSE)

xvect <- signif(quantile(matchdata$lnland,c(.25,.75)),4)
fit <- qregsim1(lnprice~lnland+lnbldg+age+factor(year),~lnland, bmat, 
  tvect,xvalues=xvect,data=matchdata)
#Simulation for 1995
smalldata <- matchdata[matchdata$year==1995,]
bmat95 <- bmat[,1:4]
fit <- qregsim1(lnprice~lnland+lnbldg+age,~lnland,bmat95,tvect, 
  xvalues=xvect, data=smalldata)
#Simulation for 2005
smalldata <- matchdata[matchdata$year==2005,]
bmat05 <- bmat[,1:4]
bmat05[,1] <- bmat05[,1] + bmat[,5]
fit <- qregsim1(lnprice~lnland+lnbldg+age,~lnland,bmat05,tvect, 
  xvalues=xvect, data=smalldata)

Run the code above in your browser using DataLab