Integrate: the integral is probably divergent

只谈情不闲聊 提交于 2019-12-01 21:27:16

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

I'd use this work-around:

integrate(f = function(v){pnorm(v, mean = m, sd = s, lower.tail =  FALSE)}, 
      max(u_min,m-10*s),min(u_max,m+10*s))$value  + (u_min-m+10*s)*(u_min<m+10*s)

What I've done:

  • pnorm with lower.tail=FALSE is basically zero when very far on the right from the mean. So there is no point in "stretching" the right limit of the integral. So, when u_max > m+10*s, you just integrate to m + 10*s. You can of course change the 10 factor to add precision;
  • on the other hand, on the left pnorm is basically always 1; so you can enhance the left limit and the missing part is just u_min - m+10*s. Same logic as above.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!