[R] how to adjust the output

David Winsemius dwinsemius at comcast.net
Tue Feb 9 13:26:16 CET 2010


On Feb 9, 2010, at 4:27 AM, Roslina Zakaria wrote:

> 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.

Read the help page. The "Value" section says that integrate returns a  
list. Access the list by name of desired component:

cdf$value  # should get you the desired number.

--
David.
>
> 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]]
>
> ______________________________________________
> R-help at 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list