toBinary: Transforms a "survival" data frame into a data frame suitable...

View source: R/toBinary.R

toBinaryR Documentation

Transforms a "survival" data frame into a data frame suitable for binary (logistic) regression

Description

The result of the transformation can be used to do survival analysis via logistic regression. If the cloglog link is used, this corresponds to a discrete time analogue to Cox's proportional hazards model.

Usage

toBinary(
  dat,
  surv = c("enter", "exit", "event"),
  strats,
  max.survs = NROW(dat)
)

Arguments

dat

A data frame with three variables representing the survival response. The default is that they are named enter, exit, and event

surv

A character vector with the names of the three variables representing survival.

strats

An eventual stratification variable.

max.survs

Maximal number of survivors per risk set. If set to a (small) number, survivors are sampled from the risk sets.

Details

toBinary calls risksets in the eha package.

Value

Returns a data frame expanded risk set by risk set. The three "survival variables" are replaced by a variable named event (which overwrites an eventual variable by that name in the input). Two more variables are created, riskset and orig.row.

event

Indicates an event in the corresponding risk set.

riskset

Factor (with levels 1, 2, ...) indicating risk set.

risktime

The 'risktime' (age) in the corresponding riskset.

orig.row

The row number for this item in the original data frame.

Note

The survival variables must be three. If you only have exit and event, create a third containing all zeros.

Author(s)

Göran Broström

See Also

coxreg, glm.

Examples


enter <- rep(0, 4)
exit <- 1:4
event <- rep(1, 4)
z <- rep(c(-1, 1), 2)
dat <- data.frame(enter, exit, event, z)
binDat <- toBinary(dat)
dat
binDat
coxreg(Surv(enter, exit, event) ~ z, method = "ml", data = dat)
## Same as:
summary(glm(event ~ z + riskset, data = binDat, family = binomial(link = cloglog)))


goranbrostrom/eha documentation built on June 19, 2024, 1:39 a.m.