if (FALSE) {
data("green")
x.green <- seq(min(log(green$COST)), max(log(green$COST)),
length.out = 101)
options(np.tree=TRUE, crs.messages=FALSE, np.messages=FALSE)
# 1. Unconstrained
(h.bic.green.u <- kern_smooth_bw(log(green$COST),
log(green$OUTPUT), method = "u", technique = "noh",
bw_method = "bic"))
y.ks.green.u <- kern_smooth(log(green$COST),
log(green$OUTPUT), x.green, h = h.bic.green.u,
method = "u", technique = "noh")
# 2. Monotonicity constraint
(h.bic.green.m <- kern_smooth_bw(log(green$COST),
log(green$OUTPUT), method = "m", technique = "noh",
bw_method = "bic"))
y.ks.green.m <- kern_smooth(log(green$COST),
log(green$OUTPUT), x.green, h = h.bic.green.m,
method = "m", technique = "noh")
# 3. Monotonicity and Concavity constraints
(h.bic.green.mc<-kern_smooth_bw(log(green$COST), log(green$OUTPUT),
method="mc", technique="noh", bw_method="bic"))
y.ks.green.mc<-kern_smooth(log(green$COST),
log(green$OUTPUT), x.green, h=h.bic.green.mc, method="mc",
technique="noh")
# Representation
plot(log(OUTPUT)~log(COST), data=green, xlab="log(COST)",
ylab="log(OUTPUT)")
lines(x.green, y.ks.green.u, lty=1, lwd=4, col="green")
lines(x.green, y.ks.green.m, lty=2, lwd=4, col="cyan")
lines(x.green, y.ks.green.mc, lty=3, lwd=4, col="magenta")
legend("topleft", col=c("green","cyan","magenta"),
lty=c(1,2,3), legend=c("unconstrained", "monotone",
"monotone + concave"), lwd=4, cex=0.8)
}
Run the code above in your browser using DataLab