# 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) 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]) (Intercept) 1.090909 # Now try the Poisson approach: poissonfit<-glm(example5$d ~ 1, family="poisson", offset=log(example5$v)) summary(poissonfit) Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 0.08701 0.57735 0.151 0.88 # Again note that the parameters are given on a log scale, # so we need the following to recover mu as we want it: exp(poissonfit$coef[1]) (Intercept) 1.090909 # It seems silly to use the survreg() and glm() functions to accomplish what # we can evaluate directly. However, the advantage lies in the ability to # easily regress on multiple variables -- say gender, drug treatment etc -- # and to consider more complicated forms for mu than a simple constant value.