View source: R/8_mdtFunctions.R
| mdtToLong | R Documentation |
mdtToLong reshapes a multiple decrement table into an aggregated
long data set with one row per (exit time, cause) and a count
column, ready for competing-risks tools such as
survival::survfit(Surv(time, status) ~ 1, weights = count)
(Aalen-Johansen cumulative incidence) or for any analysis based on
survival::Surv.
mdtToLong(object, x, t, exitTime = c("end", "mid"), dropZero = TRUE)
object |
an |
x |
entry age of the cohort (default: the lowest tabulated age, 0). |
t |
length of the follow-up in years (default: to the end of the
table). Lives still in the table at |
exitTime |
where in the year of age decrements are placed:
|
dropZero |
logical: drop rows with zero count (default |
With exitTime = "end" the Aalen-Johansen estimate of the
cumulative incidence of cause j at time k computed on the
weighted long data coincides with qxt(object, x, k, decrement = j);
see the multiple decrement vignette.
A data.frame with columns time (years since age
x), age (age at exit or censoring), status (a
factor whose first level, "censored", is followed by the
decrement names, as expected by survival::Surv for multi-state
data) and count (number of lives, possibly non-integer).
valdezDf <- data.frame(
x = 50:54,
lx = c(4832555, 4821937, 4810206, 4797185, 4782737),
heart = c(5168, 5363, 5618, 5929, 6277),
accidents = c(1157, 1206, 1443, 1679, 2152),
other = c(4293, 5162, 5960, 6840, 7631))
valdezMdt <- new("mdt", name = "ValdezExample", table = valdezDf)
long <- mdtToLong(valdezMdt, x = 50, t = 5)
head(long)
if (requireNamespace("survival", quietly = TRUE)) {
fit <- survival::survfit(survival::Surv(time, status) ~ 1,
data = long, weights = count)
summary(fit, times = 1:5)$pstate
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.