[R] maximum number of subdivisions reached

. . xkziloj at gmail.com
Mon Aug 29 17:16:08 CEST 2011


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.



More information about the R-help mailing list