# 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) 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) 1.090909 # Now try the exponential survival model: expfit<-survreg(Surv(v, d) ~ 1, dist="exponential", example5) summary(expfit) Value Std. Error z p (Intercept) -0.087 0.577 -0.151 0.88 # 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]) 1.090909 # We can calculate an approximate confidence interval as follows: # Approximate 95% lower bound: 1/exp(expfit$coef[1] + 2*sqrt(expfit$var[1])) 0.3438021 # Approximate 95% upper bound: 1/exp(expfit$coef[1] - 2*sqrt(expfit$var[1])) 3.461534