[R] Generating by inverting function

David Winsemius dwinsemius at comcast.net
Sun Sep 30 10:25:11 CEST 2012


On Sep 29, 2012, at 10:23 AM, Salma Wafi wrote:

> Hello,
> I am trying to generate random survival times by inverting the function,  S(t)= exp(b*F(t)),

This looks a bit confused. 

S(t) = 1- exp( -integral( h(t)dt )
where h(t) is the instantaneous hazard. That integral is the cumulative hazard function.

> where b is constant and F(t) is some cumulative distribution function, let say that F(t) is cdf of normal distribution or any others distributions.
>  
> as we know that S(t) has uniform distribution on  (0,1)

We do? Seems dubious. That would seem especially unlikely if we assumed that S(t) =exp( b* CDF_normal(t)) 

> so we can write that
> U= exp(b*F(t)), where U is uniform (0,1). Now to generat the time t, we do 
> log(U)= b* F(t)
> (log(U))/ b = F(t) and then  t = F((log(U))/b)^(-1).
>  
> My Question  is how we can get the inverse function for the cumulative distribution F(t) in R?. Is there any package in R can help to invert some function especially if this function is pdf or cdf?.

You may want to look at the Quantile2 function in package Hmisc. It is designed to generate simulated times for varying hazard ratios when offered survival probabilities. Harrell also has a Lognorm2, a Gompertz2, and Weibull2 functions.


--
David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list