Learn R Programming

survMisc (version 0.4.2)

tne: Time, No. at risk, No. events

Description

No. of events expected (per stratum) is given by: $$\frac{e_i(n[s]_i)}{n_i}$$ where $n[s]_i$ is the no. at risk for the stratum. If the formula is 'intercept-only', the strata I=1 is returned. survfit object do not currently support interaction terms.

Usage

tne(x, ...)

  ## S3 method for class 'Surv':
tne(x, ..., eventsOnly = FALSE)

  ## S3 method for class 'survfit':
tne(x, ..., eventsOnly = FALSE,
    return = c("table", "list", "merged"),
    nameStrata = TRUE)

  ## S3 method for class 'coxph':
tne(x, ..., eventsOnly = FALSE,
    return = c("table", "list", "merged"),
    nameStrata = TRUE)

  ## S3 method for class 'formula':
tne(x, ..., eventsOnly = FALSE,
    return = c("table", "list", "merged"),
    nameStrata = TRUE)

Arguments

x
A object of class Surv, survfit, coxph or formula.
...
Additional arguments (not implemented)
eventsOnly
If eventsOnly=TRUE shows only times at which at least one event occurred. Otherwise shows all times recorded (i.e. including those censored)
return
See Value below
nameStrata
Applies only if return=="list" or return=="merged". The default is to name the elements of the list after each stratum. As the names for each stratum are made by concatenating the predictor names, this c

Value

  • For a Surv object: A data.table with columns:
  • ttime
  • nno. at risk
  • eno. events
  • For a survfit, coxph or formula a data.table with columns as above and in addition:
  • sstratum; predictor names are separated with an underscore '_'
  • nsno. at risk (by strata)
  • Esno. events expected (by strata)
  • e_Esno. events minus no. events expected
  • Additional columns returned match those of the predictors in the model.frame (for survfit objects) or model.matrix (in other cases). If return="list" = then instead a list with one element for each stratum, where each elements is a data.frame with columns t, n and e as for a Surv object. If return="merged", a data.table with a columns t, n, e as above and additional columns for n and e for each stratum.

References

Example using kidney data is from: Klein J, Moeschberger M 2003 Survival Analysis, 2nd edition. New York: Springer. Example 7.2, pg 210.

Examples

Run this code
### Surv object
df0 <- data.frame(t=c(1,1,2,3,5,8,13,21),
                  e=rep(c(0,1),4))
s1 <- Surv(df0$t, df0$e, type="right")
tne(s1)
tne(s1, eventsOnly=TRUE)
### survfit object
data(kidney, package="KMsurv")
s1 <- survfit(Surv(time=time, event=delta) ~ type, data=kidney)
tne(s1)
tne(s1, return="list")
tne(s1, eventsOnly=TRUE)
tne(survfit(Surv(time=time, event=delta) ~ 1, data=kidney))
data(larynx, package="KMsurv")
tne(survfit(Surv(time, delta) ~ factor(stage) + age, data=larynx))
data(bmt, package="KMsurv")
tne(survfit(Surv(t2, d3) ~ z3 +z10, data=bmt), return="merged")
tne(survfit(Surv(t2, d3) ~ 1, data=bmt))
### coxph object
data(kidney, package="KMsurv")
c1 <- coxph(Surv(time=time, event=delta) ~ type, data=kidney)
tne(c1)
tne(c1, return="list")
tne(coxph(Surv(t2, d3) ~ z3*z10, data=bmt))
### formula object
data(kidney, package="KMsurv")
### this doesn't work
### s1 <- survfit(Surv(t2, d3) ~ z3*z10, data=bmt)
tne(Surv(time=t2, event=d3) ~ z3*z10, data=bmt, return="merged")
tne(Surv(time=t2, event=d3) ~ ., data=bmt)
### example where each list element has only one row
### also names are impractical
tne(Surv(time=t2, event=d3) ~ ., data=bmt, return="list", nameStrata=FALSE)

Run the code above in your browser using DataLab