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))
xgrid <- seq(0, 10, length = 101)
ansm <- hdeffsev(xgrid, myfun(xgrid), myfun(xgrid, deriv = 1),
myfun(xgrid, deriv = 2), allofit = TRUE)
digg <- 4
cbind(severity = ansm$sev,
fun = round(myfun(xgrid), digg),
deriv1 = round(myfun(xgrid, deriv = 1), digg),
deriv2 = round(myfun(xgrid, deriv = 2), digg),
zderiv1 = round(1 + (myfun(xgrid, deriv = 1))^2 +
myfun(xgrid, deriv = 2) * myfun(xgrid), digg))
Run the code above in your browser using DataLab