Hi R-users,

 
I have this code below and I understand the error message but do not know how to correct it.  My question is how do I get rid of “with absolute error < 7.5e-06” attach to value of cdf so that I can carry out the calculation.
 
integrand <- function(z) 
{ alp  <- 2.0165
  rho  <- 0.868
 
# simplified expressions
  a      <- alp-0.5
  c1     <- sqrt(pi)/(gamma(alp)*(1-rho)^alp)
  c2     <- sqrt(rho)/(1-rho)
  t1     <- exp(-z/(1-rho))
  t2     <- (z/(2*c2))^a 
  bes1   <- besselI(z*c2,a) 
  t1bes1 <- t1*bes1  
  c1*t1bes1*t2
}
 
z1  <- 20
cdf <- integrate(integrand, lower = 0, upper = z1,abs.tol = FALSE)
r   <- runif(1)
 
## Newton iteration
z2  <- z1 - (cdf - r)/integrand(z1)
 
Output
 
> z1  <- 20
 
> cdf <- integrate(integrand, lower = 0, upper = z1)
 
> r   <- runif(1)
 
> z2  <- z1 - (cdf - r)/integrand(z1)
Error in cdf - r : non-numeric argument to binary operator
 
> source(.trPaths[5], echo=TRUE, max.deparse.length=10000)
 
> cdf
0.9996004 with absolute error < 7.5e-06
 
Thank you so much for any help given.




      
	[[alternative HTML version deleted]]

