lwrgrid: LWR Bandwidth or Window Selection

Description Usage Arguments Value References See Also Examples

View source: R/lwrgrid.R

Description

Finds the value of a user-provided array of window or bandwidth values that provides the lowest cv or gcv for an LWR model. Calls lwr and returns its full output for the chosen value of h.

Usage

1
2
3
 
lwrgrid(form,window=0,bandwidth=0,kern="tcub",method="gcv",print=TRUE,
  distance="Mahal",target=NULL,data=NULL)

Arguments

form

Model formula

window

Vector of possible window sizes. Default: none.

bandwidth

Vector of possible bandwidths. Default: none.

method

Specifies "gcv" or "cv" criterion function. Default: method="gcv".

print

If TRUE, prints gcv or cv values for each value of the window or bandwidth.

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: lwr looks for the first two letters to determine which variable is latitude and which is longitude, so 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 alpha = window. In this case, the target points are found using a nearest neighbor procedure even if bandwidth > 0. 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.

ytarget

The predicted values of y at the original target points.

dtarget1

The estimated derivatives dy/dx1 at the target points.

dtarget2

The estimated derivatives dy/dx2 at the target points. All zeros if the model has only one explanatory variable.

ytarget.se

Standard errors for the predicted values of y at the target points.

dtarget1.se

Standard errors for the derivatives dy/dx1 at the target points.

dtarget2.se

Standard errors for the derivatives dy/dx2 at the target points. All zeros if the model has only one explanatory variable.

yhat

The predicted values of y for the full data set.

dhat1

The estimated derivatives dy/dx1 for the full data set.

dhat2

The estimated derivatives dy/dx2 for the full data set. All zeros if the model has only one explanatory variable.

yhat.se

Standard errors for the predicted values of y for the full data set.

dhat1.se

Standard errors for the estimated derivatives dy/dx1 for the full data set.

dhat2.se

Standard errors for the estimated derivatives dy/dx2 for the full data set. All zeros if the model has only one explanatory variable.

df1

tr(L), a measure of the degrees of freedom used in estimation.

df2

tr(L'L), an alternative measure of the degrees of freedom used in estimation.

sig2

Estimated residual variance, sig2 = rss/(n-2*df1+df2).

cv

Cross-validation measure. cv = mean(((y-yhat)/(1-infl))^2), where yhat is vector of predicted values for y and infl is the vector of diagonal terms for L.

gcv

gcv = n*(n*sig2)/((n-nreg)^2), where sig2 is the estimated residual variance and nreg = 2*df1 - df2.

infl

A vector containing the diagonal elements of L.

minh

Value of window or bandwidth the minimizes the criterion function.

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.

McMillen, Daniel P., "Issues in Spatial Data Analysis," Journal of Regional Science 50 (2010), 119-141.

McMillen, Daniel P., "Employment Densities, Spatial Autocorrelation, and Subcenters in Large Metropolitan Areas," Journal of Regional Science 44 (2004), 225-243.

McMillen, Daniel P. and John F. McDonald, "A Nonparametric Analysis of Employment Density in a Polycentric City," Journal of Regional Science 37 (1997), 591-612.

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.

Silverman, A. W., Density Estimation for Statistics and Data Analysis, Chapman and Hall, New York (1986).

See Also

lwr

maketarget

Examples

 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
37
38
39
par(ask=TRUE)
n = 1000
z1 <- runif(n,0,2*pi)
z1 <- sort(z1)
z2 <- runif(n,0,2*pi)
o1 <- order(z1)
o2 <- order(z2)
ybase1 <-  z1 - .1*(z1^2) + sin(z1) - cos(z1) - .5*sin(2*z1) + .5*cos(2*z1) 
ybase2 <- -z2 + .1*(z2^2) - sin(z2) + cos(z2) + .5*sin(2*z2) - .5*cos(2*z2)
ybase <- ybase1+ybase2
sig = sd(ybase)/2
y <- ybase + rnorm(n,0,sig)
summary(lm(y~ybase))

# Single variable estimation
fit1 <- lwrgrid(y~z1,window=seq(.10,.30,.05))
c(fit1$df1,fit1$df2,2*fit1$df1-fit1$df2)
plot(z1[o1],ybase1[o1],type="l",ylim=c(min(ybase1,fit1$yhat),max(ybase1,fit1$yhat)),
  xlab="z1",ylab="y")
# Make predicted and actual values have the same means
fit1$yhat <- fit1$yhat - mean(fit1$yhat) + mean(ybase1)
lines(z1[o1],fit1$yhat[o1], col="red")
legend("topright", c("Base", "LWR"), col=c("black","red"),lwd=1)
fit2 <- lwrgrid(y~z2,window=seq(.10,.90,.10))
fit2$yhat <- fit2$yhat - mean(fit2$yhat) + mean(ybase2)
c(fit2$df1,fit2$df2,2*fit2$df1-fit2$df2)
plot(z2[o2],ybase2[o2],type="l",ylim=c(min(ybase2,fit2$yhat),max(ybase2,fit2$yhat)),
    xlab="z1",ylab="y")
lines(z2[o2],fit2$yhat[o2], col="red")
legend("topright", c("Base", "LWR"), col=c("black","red"),lwd=1)

#both variables
fit3 <- lwrgrid(y~z1+z2,window=seq(.03,.09,.02))
yhat1 <- fit3$yhat - mean(fit3$yhat) + mean(ybase1)
plot(z1[o1],yhat1[o1], xlab="z1",ylab="y")
lines(z1[o1],ybase1[o1],col="red")
yhat2 <- fit3$yhat - mean(fit3$yhat) + mean(ybase2)
plot(z2[o2],yhat2[o2], xlab="z2",ylab="y")
lines(z2[o2],ybase2[o2],col="red")

McSpatial documentation built on May 2, 2019, 9:32 a.m.