# NOT RUN {
# EXAMPLE 1 (INTERFACE=FORMULA): For this example, we simulate an
# example for a partially linear model and perform bandwidth selection
set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rbinom(n, 1, .5)
z1 <- rbinom(n, 1, .5)
z2 <- rnorm(n)
y <- 1 + x1 + x2 + z1 + sin(z2) + rnorm(n)
X <- data.frame(x1, factor(x2))
Z <- data.frame(factor(z1), z2)
# Compute data-driven bandwidths... this may take a minute or two
# depending on the speed of your computer...
bw <- npplregbw(formula=y~x1+factor(x2)|factor(z1)+z2)
summary(bw)
# Note - the default is to use the local constant estimator. If you wish
# to use instead a local linear estimator, this is accomplished via
# npplregbw(xdat=X, zdat=Z, ydat=y, regtype="ll")
# Note - see the example for npudensbw() for multiple illustrations
# of how to change the kernel function, kernel order, and so forth.
# You may want to manually specify your bandwidths
bw.mat <- matrix(data = c(0.19, 0.34, # y on Z
0.00, 0.74, # X[,1] on Z
0.29, 0.23), # X[,2] on Z
ncol = ncol(Z), byrow=TRUE)
bw <- npplregbw(formula=y~x1+factor(x2)|factor(z1)+z2,
bws=bw.mat, bandwidth.compute=FALSE)
summary(bw)
# Sleep for 5 seconds so that we can examine the output...
Sys.sleep(5)
# You may want to tweak some of the bandwidths
bw$bw[[1]] # y on Z, alternatively bw$bw$yzbw
bw$bw[[1]]$bw <- c(0.17, 0.30)
bw$bw[[2]] # X[,1] on Z
bw$bw[[2]]$bw[1] <- 0.00054
summary(bw)
# EXAMPLE 1 (INTERFACE=DATA FRAME): For this example, we simulate an
# example for a partially linear model and perform bandwidth selection
set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rbinom(n, 1, .5)
z1 <- rbinom(n, 1, .5)
z2 <- rnorm(n)
y <- 1 + x1 + x2 + z1 + sin(z2) + rnorm(n)
X <- data.frame(x1, factor(x2))
Z <- data.frame(factor(z1), z2)
# Compute data-driven bandwidths... this may take a minute or two
# depending on the speed of your computer...
bw <- npplregbw(xdat=X, zdat=Z, ydat=y)
summary(bw)
# Note - the default is to use the local constant estimator. If you wish
# to use instead a local linear estimator, this is accomplished via
# npplregbw(xdat=X, zdat=Z, ydat=y, regtype="ll")
# Note - see the example for npudensbw() for multiple illustrations
# of how to change the kernel function, kernel order, and so forth.
# You may want to manually specify your bandwidths
bw.mat <- matrix(data = c(0.19, 0.34, # y on Z
0.00, 0.74, # X[,1] on Z
0.29, 0.23), # X[,2] on Z
ncol = ncol(Z), byrow=TRUE)
bw <- npplregbw(xdat=X, zdat=Z, ydat=y,
bws=bw.mat, bandwidth.compute=FALSE)
summary(bw)
# Sleep for 5 seconds so that we can examine the output...
Sys.sleep(5)
# You may want to tweak some of the bandwidths
bw$bw[[1]] # y on Z, alternatively bw$bw$yzbw
bw$bw[[1]]$bw <- c(0.17, 0.30)
bw$bw[[2]] # X[,1] on Z
bw$bw[[2]]$bw[1] <- 0.00054
summary(bw)
# }
# NOT RUN {
# }
# NOT RUN {
<!-- % enddontrun -->
# }
Run the code above in your browser using DataLab