[R] Simulating from the Weibull with right censoring

Göran Broström goran.brostrom at umu.se
Mon Mar 24 09:34:47 CET 2014



On 2014-03-24 07:22, David Winsemius wrote:
>
> On Mar 23, 2014, at 9:14 PM, Lucy Leigh wrote:
>
>> Hi everyone,
>>
>> I am currently attempting to simulate some survival data, based on
>> a Weibull model. I basically need to simulate some survival data so
>> that I can then test out a program I'm writing, before applying it
>> to some real data.
>>
>> I've managed to create failure time data, using the rweibull
>> function. I.e. Y[i] <- rweibull(1, shape, scale) For a variety of
>> shape and scale parameters etc.
>>
>> I wish to add in right censoring. If I am considering my failure
>> times as deaths, and the censoring time as a study cut-off date
>> (for example, 5 years from baseline), would it be correct to do
>> something like,
>>
>> for(i in 1:nSubjects){ if (Y[i] >  5){ Y[i] <- 5} else {Y[i]  <-
>> Y[i] }}
>>
>
> This would be more R-ish if you did it this way (loop-free)
>
> Y[ Y > 5 ] <- 5  # set cutoff
> cens.time <- runif(length(Y), 0, max(Y))
> cens <- cens.time < Y

Not really; Given survival times T and censoring times C ( == 5 in 
Lucy's example):

Y <- pmin(Y, C)
event <- (Y <= C)

gives what Lucy wants, with Y being the censored times and 'event' 
indicating an observed death.

Göran

> survreg( Surv(Y, !cens) ~ 1 )
>
> Untested (well, lightly tested)  in absence of data object.
>
>> I guess my question is, is it statistically sound to impose the
>> right censoring after estimating the distribution with no
>> censoring? I am leaning towards yes, because in an ideal world
>> where we followed all participants until they died, the
>> distribution would be as estimated by the rweibull above....and
>> assuming that the right censoring is independent, then cutting of
>> the measurements at a pre-specified time wouldn't affect the
>> outcome at all. But I guess I am just looking for a second
>> opinion?
>>
>> Thanks in advance, this list has been immensely helpful with some
>> previous questions I have had about the survival package. Lucy
>>
> Please post in plain text.
>
>
>> [[alternative HTML version deleted]]




More information about the R-help mailing list