I was doing some integration into a loop using integrate
and I come up with an error I can't understand neither get rid of. Here is a MWE I could extract:
u_min = 0.06911363
u_max = 1.011011
m = 0.06990648
s = 0.001092265
integrate(f = function(v){pnorm(v, mean = m, sd = s, lower.tail = FALSE)}, u_min, u_max)
this returns an error "the integrale is probably divergent" which is obviously false. I tried to modify the parameters a little bit and got this working for example:
u_min <- 0.07
u_max <- 1.1
m <- 0.0699
s <- 0.00109
integrate(f = function(v){pnorm(v, mean = m, sd = s, lower.tail = FALSE)}, u_min, u_max)
I tried to have a look into the integrate
function with debug
but it's a wrapper of a C
code. Also I'm not a specialist of quadrature techniques. I saw this SO post but couldn't make anything from it.
thanks
The default tolerance of .Machine$double.eps^0.25
(= 0.0001220703) needs to be lowered. Try, for example, this:
f <- function(v) pnorm(v, mean = m, sd = s, lower.tail = FALSE)
integrate(f, u_min, u_max, rel.tol = 1e-15)
## 0.0009421867 with absolute error < 1.1e-17