# [R] Extracting the survival function estimate from a survreg object.

Sixten Borg sb at ihe.se
Tue Apr 6 11:35:23 CEST 2004

```Hello all,

I want to extract the survival function estimate from a model fitted by survreg().
Using predict.survreg(..., type="quantile", p=seq(0,1,0.001)), gives the quantiles, which
I managed to turn around into a survival function estimate (Prob{T > t} as function of t).

Is there a more straightforward way of doing this? I have had difficulties using pweibull() with
the coefficients reported by summary(<survreg object>).

I am enclosing an outline of my code for reference if anyone is interested.

Sixten

---------------------------------------------------------------------
sure <- survreg(formula = Surv(time, dead) ~ age + group + sex, data = modb)

nd <- data.frame(
age=50,
group=factor("A", levels=c("A", "B", "C")),
sex=factor("M", levels=c("F", "M")))

y <- seq(0, 1, 0.001)

#
# For a range of p-values, predict the quantiles.
#
sufu <- list(
y=1-y,
x=predict.survreg(sure, nd, type="quantile", p=y)
)

#
# Find the p value for each t, by locating the last quantile no larger than t.
# The pairs (t,p) forms a step function.
#
sufu2 <- list(
x=0:14,
y=unlist(lapply(0:14,function(x){rev(sufu\$y[sufu\$x<=x])}))
)

# Looks ok?
plot(sufu, type="s", xlim=c(0,20))
points(sufu2,  pch=20, col="blue")

#EOF#

```