Why I am getting Error in integrate(f, x1, x1 + dx) : maximum number of subdivisions reached
and can I avoid this? func <- function(y, a, rate, sad){ f3 <- function(z){ f1 <- function(y,a,n){ dpois(y,a*n) } f2 <- function(n,rate){ dexp(n,rate) } f <- function(n){ f1(y,a,n)*f2(n,rate) } r <- 0 r1 <- 1 x1 <- 0 dx <- 20 while(r1 > 10e-500){ r1 <- integrate(f,x1,x1+dx)$value r <- r + r1 x1 <- x1 + dx } r + integrate(f,x1,Inf)$valu } sapply(y,f3) } func(200,0.1,0.1,sad=Exp) Thanks in advance. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.