[R] Generating by inverting function

David Winsemius dwinsemius at comcast.net
Sun Sep 30 19:01:17 CEST 2012


On Sep 30, 2012, at 5:34 AM, R. Michael Weylandt wrote:

> On Sun, Sep 30, 2012 at 10:51 AM, Salma Wafi <salmawafi76 at yahoo.com> wrote:
>> Dear All,
>> Thank you very much for your kind and response.
>> 
>> Actually, S(t) = exp(b* F(t)) represent one of survival models, where F(t) is known cumulative distribtion function. So, that is why I need to generate the survival times T based on this model. Then for generating time I have to invert S(t) as following,
>> 
>>  Since, S(t) has uniform distribution on  (0,1)

No, it does NOT in general or in any of the scenarios you have painted have a uniform distribution. It does, of course, have a range of [0,1].

>> 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).
>> 
>> Now in case F(t) is cdf of Lognormal distribution or Weibull distribution
>> 
>> My Question  is how we can get the inverse of 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?.
> 
> I repeat myself: if you have fit F() to a log-normal or Weibull
> distribution, just use qlnorm() or qweibull() included in base R. If
> you still need to fit those distributions, use MASS::fitdistr.

And I repeat myself, too. If you want to simulate one of a) an arbitrary survival vector, or b) a lognormal or c) a Weibull, then the Hmisc package has facilities to do each of those.

-- 
David.
> 
> Cheers,
> 
> Michael
> 
>> 
-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list