toBinary | R Documentation |
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.
toBinary(
dat,
surv = c("enter", "exit", "event"),
strats,
max.survs = NROW(dat)
)
dat |
A data frame with three variables representing the survival
response. The default is that they are named |
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. |
toBinary calls risksets
in the eha
package.
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. |
The survival variables must be three. If you only have exit and event, create a third containing all zeros.
Göran Broström
coxreg
, glm
.
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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.