# NOT RUN {
deg <- 4 # myfun is a function that approximates the HDE
myfun <- function(x, deriv = 0) switch(as.character(deriv),
'0' = x^deg * exp(-x),
'1' = (deg * x^(deg-1) - x^deg) * exp(-x),
'2' = (deg * (deg-1) * x^(deg-2) - 2*deg * x^(deg-1) + x^deg) * exp(-x))
# }
# NOT RUN {
curve(myfun, 0, 10, col = "white")
xgrid <- seq(0, 10, length = 101)
seglines(xgrid, myfun(xgrid), myfun(xgrid, deriv = 1),
myfun(xgrid, deriv = 2), position = "bottom")
# }
Run the code above in your browser using DataLab