# NOT RUN {
op <- par(no.readonly = TRUE)
set.seed(1)
n <- 2000
x <- rbeta(n, 2, 2) * 10
y <- 3 * sin(2 * x) + 10 * (x > 5) * (x - 5)
y <- y + rnorm(n) + (rgamma(n, 2, 2) - 1) * (abs(x - 5) + 3)
xs <- seq(min(x), max(x), length = 1000)
ftrue <- 3 * sin(2 * xs) + 10 * (xs > 5) * (xs - 5)
fhat_loc_lin <- fk_regression(x, y)
fhat_NW <- fk_regression(x, y, type = 'NW')
par(mfrow = c(2, 2))
plot(fhat_loc_lin, main = 'Local linear estimator with amise bandwidth')
plot(fhat_NW, main = 'NW estimator with amise bandwidth')
fhat_loc_lin <- fk_regression(x, y, h = 'cv')
fhat_NW <- fk_regression(x, y, type = 'NW', h = 'cv')
plot(fhat_loc_lin, main = 'Local linear estimator with cv bandwidth')
plot(fhat_NW, main = 'NW estimator with cv bandwidth')
par(op)
# }
Run the code above in your browser using DataCamp Workspace