A function defined, as follows-
icc <- function(prof, b) {
z = exp(prof - b)
inf = z / (1 + z)
return (inf)}
prof <- seq(-4, 4,0.1)
brange <- seq(-3,3,0.1)
yy <- sapply(brange, \(b) icc(prof, b))
matplot(prof, yy, type = "l", lty = "solid")
I want to find the derivative of this icc function and plot it over the same parameter range as icc. However, the following code isn't working. What is the issue?
iic <- function(prof, b) {
z = exp(prof - b)
inf = z / (1 + z)
inf2= deriv(inf,"z")*deriv(z,"prof")
return (inf2)}
yy2 <- sapply(brange, \(b) iic(prof, b))
matplot(prof, yy2, type = "l", lty = "solid")
EDIT: I know that since the function has an easy expression, I can manually find the derivative and plot over the range (iic is basically the derivative of the functional expression of icc). However, I would like to see a general way of finding the derivative of a function over a range of values.