# This file from www.richardsconsulting.co.uk/lectures # First load in the survival library library(survival) # Now create a list of (i) survival times and (ii) censoring/event status. # # Note that '1' = death and '0' = censored in the status variable. example5<-list(v = c(1.0, 0.50, 0.50, 0.25, 0.25, 0.25), d = c( 0, 1, 0, 1, 1, 0)) # First, the direct MLE approach: sum(example5$d) / sum(example5$v) # Now try the exponential survival model: expfit<-survreg(Surv(v, d) ~ 1, dist="exponential", example5) summary(expfit) # Note that the exponential distribution is parameterised here with lambda, # where mu = 1 / lambda. Also, the parameter estimates are on a log scale, # so we need the following to recover mu as we want it: 1/exp(expfit$coef[1]) # We can calculate an approximate confidence interval as follows: # Approximate 95% lower bound: 1/exp(expfit$coef[1] + 2*sqrt(expfit$var[1])) # Approximate 95% upper bound: 1/exp(expfit$coef[1] - 2*sqrt(expfit$var[1]))