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))
if (FALSE) {
curve(myfun, 0, 10, col = "white")
xgrid <- seq(0, 10, length = 101)
seglines(xgrid, myfun(xgrid), myfun(xgrid, deriv = 1),
COPS0 = 2,
myfun(xgrid, deriv = 2), pch.table = NULL,
position = "bottom")
}
Run the code above in your browser using DataLab