sf: *s*urvival (or hazard) *f*unction based on e and n.

View source: R/sf.R

sfR Documentation

survival (or hazard) function based on e and n.


survival (or hazard) function based on e and n.


sf(x, ...)

## Default S3 method:
sf(x, ..., what = c("S", "H"), SCV = FALSE, times = NULL)

## S3 method for class 'ten'
sf(x, ..., what = c("S", "H"), SCV = FALSE, times = NULL, reCalc = FALSE)

## S3 method for class 'stratTen'
sf(x, ..., what = c("S", "H"), SCV = FALSE, times = NULL, reCalc = FALSE)

## S3 method for class 'numeric'
  n = NULL,
  what = c("all", "S", "Sv", "H", "Hv"),
  times = NULL



One of the following:


A numeric vector of events status (assumed sorted by time).


Vectors of events and numbers at risk (assumed sorted by time).


A ten object.


A stratTen object.


Additional arguments (not implemented).


See return, below.


Include the Squared Coefficient of Variation, which is calcluated using the mean mean(x) and the variance var(x):

SCV[x] = var(x) / mean(x)^2

This measure of dispersion is also referred to as the 'standardized variance' or the 'noise'.


Times for which to calculate the function.
If times=NULL (the default), times are used for which at least one event occurred in at least one covariate group.


Recalcuate the values?
If reCalc=FALSE (the default) and the ten object already has the calculated values stored as an attribute, the value of the attribute is returned directly.


Number at risk.


A data.table which is stored as an attribute of the ten object.
If what="s", the survival is returned, based on the Kaplan-Meier or product-limit estimator. This is 1 at t=0 and thereafter is given by:

S[t] = prod (1 - e[t]) / n[t]

If what="sv", the survival variance is returned.
Greenwoods estimtor of the variance of the Kaplan-Meier (product-limit) estimator is:

Var(S[t]) = S[t]^2 sum e[t] / (n[t] * (n[t] - e[t]))

If what="h", the hazard is returned, based on the the Nelson-Aalen estimator. This has a value of H=0 at t=0 and thereafter is given by:

H[t] = sum(e[t] / n[t])

If what="hv", the hazard variance is returned.
The variance of the Nelson-Aalen estimator is given by:

Var(H[t]) = sum(e / n^2)

If what="all" (the default), all of the above are returned in a data.table, along with:
Survival, based on the Nelson-Aalen hazard estimator H, which is:

S[t] = exp(H[t])

Hazard, based on the Kaplan-Meier survival estimator S, which is:

H[t] = -log(S[t])


data("kidney", package="KMsurv")
k1 <- ten(Surv(time=time, event=delta) ~ type, data=kidney)
sf(k1, times=1:10, reCalc=TRUE)
k2 <- ten(with(kidney, Surv(time=time, event=delta)))
## K&M. Table 4.1A, pg 93.
## 6MP patients
data("drug6mp", package="KMsurv")
d1 <- with(drug6mp, Surv(time=t2, event=relapse))
(d1 <- ten(d1))
sf(x=d1$e, n=d1$n, what="S")

data("pbc", package="survival")
t1 <- ten(Surv(time, status==2) ~ log(bili) + age + strata(edema), data=pbc)

## K&M. Table 4.2, pg 94.
data("bmt", package="KMsurv")
b1 <- bmt[bmt$group==1, ] # ALL patients
t2 <- ten(Surv(time=b1$t2, event=b1$d3))
with(t2, sf(x=e, n=n, what="Hv"))
## K&M. Table 4.3, pg 97.
sf(x=t2$e, n=t2$n, what="all")

survMisc documentation built on April 7, 2022, 5:06 p.m.