The survival function at time t for the log-normal model can be represented in R using 1 - plnorm()
, where plnorm()
is the logarithmically normal cumulative distribution function. To illustrate this, we first put your graph in a function:
## Function to plot aft data plot.aft <- function(x, legend = c("ICU Patients", "Non-ICU Patients"), xlab = "Days since Infection", ylab="Percent Surviving", lwd = 2, col = c("red", "black"), at = c(0, 20, 40, 60, 80, 100, 120, 140, 160, 180), ...) { plot(x[, 1], x[, 2], type = "l", ylim = c(0, 1), xaxt = "n", xlab = xlab, ylab = ylab, col = col[2], lwd = 2, ...) axis(1, at = at) lines(x[, 1], x[, 3], col = col[1], lwd=2) legend("topright", legend = legend, lwd = lwd, col = col) }
Then we specify the coefficients, variables and models, and then we generate the survival probabilities for exponential and logarithmically normal models:
#
Finally, we can build the probability of survival:
## Plot survival plot.aft(data.frame(t, s0.exp, s1.exp), main = "Exponential model") plot.aft(data.frame(t, s0.lnorm, s1.lnorm), main = "Log-normal model")
And the resulting numbers:
note that
plnorm(t, meanlog = linmod["exposed"])
coincides with
pnorm((log(t) - linmod["exposed"]) / 1)
which is Ξ¦ in the canonical equation for the logarithmic survival function: S (t) = 1 - Ξ¦ ((ln (t) - ΞΌ) / Ο)
As Iβm sure, you know, there are many R packages that can process models with accelerated failure times with left, right or interval censorship, listed in the form of survival , in case you have to develop an R preference over SAS.