condens(form,window=.7,bandwidth=0,kern="tcub", mingrid.x=NULL,maxgrid.x=NULL,mingrid.y=NULL,maxgrid.y=NULL,ngrid=50, xlab="x",ylab="y",zlab="fxy/fx",contour=TRUE,level=TRUE,wire=TRUE,dens=TRUE, targetx.dens=NULL,quantile.dens=c(.10,.25,.50,.75,.90),data=NULL)
The density functions f(x) and f(y) are as follows:
$$f(x) = \frac{1}{sd(x)*b*n} \sum_i K ( \frac{ x_i - x}{sd(x)*b} )$$ $$f(y) = \frac{1}{sd(y)*b*n} \sum_i K ( \frac{ y_i - y}{sd(y)*b} )$$
A product kernel is used for f(x,y):
$$f(x,y) = \frac{1}{sd(x)*b*sd(y)*b*n}\sum_i K ( \frac{ x_i - x}{sd(x)*b} ) K ( \frac{ y_i - y}{sd(y)*b} ) $$
where b is the bandwidth and the target points are x and y. The bandwidth, b, can be set using the bandwidth option. If b = 0 (the default), sd(x)*b and sd(y)*b are replaced by window values, $h = quantile(dist, window)$, where $dist = |x_i - x|$ or $dist = |y_i - y|$. The window size is set using the window option. By default, window = .7 and bandwidth = 0. Available kernel weighting functions include the following:
Kernel | Call abbreviation |
Kernel function K(z) | Rectangular |
``rect'' | $1/2 * I(|z|<1)$ <="" td=""> 1)$> |
Triangular | ``tria'' |
$(1-|z|) * I(|z|<1)$< td=""> | Epanechnikov | 1)$<>
``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)$ |
The contour, level, and wire plots are produced from the values in gridmat using the lattice package. The two-dimensional density graphs produced when dens=TRUE are plots of f(y,x)/f(x) at given values of x. By default, the values for x are the quantiles given in quantile.dens. Alternatively, the values of x can be specified directly using the targetx.dens option. The values used to construct the density graphs are stored in densmat. Both gridmat and densmat are stored by condens even if the printing of the graphs is suppressed.
Loader, Clive. Local Regression and Likelihood. New York: Springer, 1999.
Pagan, Adrian and Aman Ullah. Nonparametric Econometrics. New York: Cambridge University Press, 1999.
data(dupage99)
dupage99$ratio <- dupage99$av/dupage99$price
dupage99$price <- dupage99$price/1000
par(ask=TRUE)
fit <- condens(ratio~price,contour=TRUE,level=TRUE,wire=TRUE,dens=TRUE,
targetx.dens=seq(100,500,100), data=dupage99)
Run the code above in your browser using DataLab