Title: | Cause-Specific Framework for Competing-Risk Analysis |
---|---|
Description: | Numerical integration of cause-specific survival curves to arrive at cause-specific cumulative incidence functions, with three usage modes: 1) Convenient API for parametric survival regression followed by competing-risk analysis, 2) API for CFC, accepting user-specified survival functions in R, and 3) Same as 2, but accepting survival functions in C++. For mathematical details and software tutorial, see Mahani and Sharabiani (2019) <DOI:10.18637/jss.v089.i09>. |
Authors: | Mansour T.A. Sharabiani, Alireza S. Mahani |
Maintainer: | Alireza S. Mahani <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.0 |
Built: | 2024-12-06 04:40:29 UTC |
Source: | https://github.com/cran/CFC |
Bone marrow transplant data with 408 rows and 5 columns.
The data has 408 rows and 5 columns.
a numeric vector code. Survival status. 1: dead from treatment related causes, 2: relapse , 0: censored.
a numeric vector. Survival time.
a numeric vector code. Plalelet
1: more than 100 x per L, 0: less.
a numeric vector. T-cell depleted BMT 1:yes, 0:no.
a numeric vector code. Age of patient, scaled and centered ((age-35)/15).
Simulated data (taken from R package 'timereg')
Using adaptive generalized Newton-Cotes for calculating cumulative incidence functions.
cfc(f.list, args.list, n, tout, Nmax = 100L, rel.tol = 1e-05, ncores = 1)
cfc(f.list, args.list, n, tout, Nmax = 100L, rel.tol = 1e-05, ncores = 1)
f.list |
In |
args.list |
List of arguments (each one a list), one per cause, to be supplied to the survival functions in |
n |
Range of iterator (starting at |
tout |
Vector of time points for which cumulative incidence functions are requested. |
Nmax |
Maximum number of subdivisions in the interval [ |
rel.tol |
Threshold for relative integration error, used as stoppage criterion. It is calculated as the maximum relative error at time point |
ncores |
Number of parallel threads to use. This is currrently only implemented in |
An object of class cfc
, which is a list with the following elements:
ci |
Array of dimensions |
s |
Array of same dimensions as |
is.maxiter |
Binary Array of length |
n.maxiter |
Number of iterations that did not converge, i.e., |
Mansour T.A. Sharabiani, Alireza S. Mahani
Haller, B., Schmidt, G., & Ulm, K. (2013). Applying competing risks regression models: an overview. Lifetime data analysis, 1-26.
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
Prentice et al (1978). The analysis of failure times in the presence of competing risks. Biometrics, 541-554.
## Not run: library("survival") # used for constructing survival formulas library("BSGW") # used for Bayesian survival regression data("bmt") # splitting data into training and prediction sets idx.train <- sample(1:nrow(bmt), size = 0.7 * nrow(bmt)) idx.pred <- setdiff(1:nrow(bmt), idx.train) nobs.train <- length(idx.train) nobs.pred <- length(idx.pred) # prepare data and formula for Bayesian cause-specific survival regression # using R package BSGW out.prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- out.prep$formula.list[[1]] f2 <- out.prep$formula.list[[2]] dat <- out.prep$dat tmax <- out.prep$tmax # estimating cause-specific models # set nsmp to larger number in real-world applications nsmp <- 10 reg1 <- bsgw(f1, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) reg2 <- bsgw(f2, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) # defining survival function for this model survfunc <- function(t, args, n) { nobs <- args$nobs; natt <- args$natt; nsmp <- args$nsmp alpha <- args$alpha; beta <- args$beta; X <- args$X idx.smp <- floor((n - 1) / nobs) + 1 idx.obs <- n - (idx.smp - 1) * nobs return (exp(- t ^ alpha[idx.smp] * exp(sum(X[idx.obs, ] * beta[idx.smp, ])))); } # preparing function and argument lists X.pred <- as.matrix(cbind(1, bmt[idx.pred, c("platelet", "age", "tcell")])) arg.1 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg1$smp$betas), beta = reg1$smp$beta, X = X.pred) arg.2 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg2$smp$betas), beta = reg2$smp$beta, X = X.pred) arg.list <- list(arg.1, arg.2) f.list <- list(survfunc, survfunc) # cause-specific competing-risk # set rel.tol to smaller number in real-world applications tout <- seq(from = 0.0, to = tmax, length.out = 10) out.cfc <- cfc(f.list, arg.list, nobs.pred * nsmp, tout, rel.tol = 1e-2) ## End(Not run)
## Not run: library("survival") # used for constructing survival formulas library("BSGW") # used for Bayesian survival regression data("bmt") # splitting data into training and prediction sets idx.train <- sample(1:nrow(bmt), size = 0.7 * nrow(bmt)) idx.pred <- setdiff(1:nrow(bmt), idx.train) nobs.train <- length(idx.train) nobs.pred <- length(idx.pred) # prepare data and formula for Bayesian cause-specific survival regression # using R package BSGW out.prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- out.prep$formula.list[[1]] f2 <- out.prep$formula.list[[2]] dat <- out.prep$dat tmax <- out.prep$tmax # estimating cause-specific models # set nsmp to larger number in real-world applications nsmp <- 10 reg1 <- bsgw(f1, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) reg2 <- bsgw(f2, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) # defining survival function for this model survfunc <- function(t, args, n) { nobs <- args$nobs; natt <- args$natt; nsmp <- args$nsmp alpha <- args$alpha; beta <- args$beta; X <- args$X idx.smp <- floor((n - 1) / nobs) + 1 idx.obs <- n - (idx.smp - 1) * nobs return (exp(- t ^ alpha[idx.smp] * exp(sum(X[idx.obs, ] * beta[idx.smp, ])))); } # preparing function and argument lists X.pred <- as.matrix(cbind(1, bmt[idx.pred, c("platelet", "age", "tcell")])) arg.1 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg1$smp$betas), beta = reg1$smp$beta, X = X.pred) arg.2 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg2$smp$betas), beta = reg2$smp$beta, X = X.pred) arg.list <- list(arg.1, arg.2) f.list <- list(survfunc, survfunc) # cause-specific competing-risk # set rel.tol to smaller number in real-world applications tout <- seq(from = 0.0, to = tmax, length.out = 10) out.cfc <- cfc(f.list, arg.list, nobs.pred * nsmp, tout, rel.tol = 1e-2) ## End(Not run)
Constructing cumulative incidence and event-free probability functions from cause-specific survival times give for a fixed set of probabilities.
cfc.pbasis(t1, t2, probs, unity.tol = 1e-06, diff.tol = 0.01, diff.tol.policy = c("all", "mean"))
cfc.pbasis(t1, t2, probs, unity.tol = 1e-06, diff.tol = 0.01, diff.tol.policy = c("all", "mean"))
t1 |
Multi-dimensional array containing survival times for cause 1 (i.e. exponential of the negative integral of hazard function). First dimension must correspond to probabilities at which times are calculated. Elements with same time, but distributed in the space of remaining dimensions, are treated independently. These diemensions can correspond, e.g., to observations or samples (in Bayesian frameworks). Survival times must be increasing along the first dimension. |
t2 |
Multi-dimensional array containing survival times for cause 2. See note for |
probs |
Probabilities for which survival times are provided in |
unity.tol |
Tolerance for difference of survival probability from 1.0 at time=0.0. In other words, we require that |
diff.tol |
Tolerance for change in survival probabilities from one time point to the next. Large changes lead to higher errors during numerical integration. |
diff.tol.policy |
If |
For each 'row' of t1
, and t2
, all elements are processed independently. To combine the survival curves from corresponding elements of t1
and t2
, we first form a 'comon denominator' time vector by combining the two time vectors and sorting the results (after removing duplicates). We limit the maximum value in the combined time vector to minimum of the the two maxima from each cause. Next, we use interpolation to find survival probabilities of each cause at all the time points in the combined time vector. Finally, we call the function cfc.tbasis
.
If t1
and t2
are one-dimensional, a matrix with columns named "time"
, "ci1"
, "ci2"
and "efp"
is returned. For multi-dimensional arrays, a list is returned with one such matrix for each element of the consolidated dimension representing all but the first dimension of t1
and t2
.
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
Prentice et al (1978). The analysis of failure times in the presence of competing risks. Biometrics, 541-554.
## Not run: # prepare data for cause-specific competing-risk analysis data(bmt) bmt$status1 <- 1*(bmt$cause==1) bmt$status2 <- 1*(bmt$cause==2) f1 <- Surv(time, status1) ~ platelet + age + tcell f2 <- Surv(time, status2) ~ platelet + age + tcell # perform weibull regression on each cause independently library(survival) reg1 <- survreg(f1, bmt) reg2 <- survreg(f2, bmt) # predict times for given probabilities # transpose predictions so that first dimension # is time/probability (use first 50 observations for speed) pvec <- seq(from=1.0, to = 0.1, length.out = 100) pred1 <- t(predict(reg1, newdata = bmt[1:50,], p = 1-pvec, type = "quantile")) pred2 <- t(predict(reg2, newdata = bmt[1:50,], p = 1-pvec, type = "quantile")) # cause-specific competing risk analysis - probability mode my.cfc <- cfc.pbasis(pred1, pred2, probs = pvec) # calculating averages across observations (e.g. patients in the study) my.summ <- summary(my.cfc) # plotting average CI and event-free probability curves plot(my.summ) ## End(Not run)
## Not run: # prepare data for cause-specific competing-risk analysis data(bmt) bmt$status1 <- 1*(bmt$cause==1) bmt$status2 <- 1*(bmt$cause==2) f1 <- Surv(time, status1) ~ platelet + age + tcell f2 <- Surv(time, status2) ~ platelet + age + tcell # perform weibull regression on each cause independently library(survival) reg1 <- survreg(f1, bmt) reg2 <- survreg(f2, bmt) # predict times for given probabilities # transpose predictions so that first dimension # is time/probability (use first 50 observations for speed) pvec <- seq(from=1.0, to = 0.1, length.out = 100) pred1 <- t(predict(reg1, newdata = bmt[1:50,], p = 1-pvec, type = "quantile")) pred2 <- t(predict(reg2, newdata = bmt[1:50,], p = 1-pvec, type = "quantile")) # cause-specific competing risk analysis - probability mode my.cfc <- cfc.pbasis(pred1, pred2, probs = pvec) # calculating averages across observations (e.g. patients in the study) my.summ <- summary(my.cfc) # plotting average CI and event-free probability curves plot(my.summ) ## End(Not run)
Preparing a data frame and formulas for cause-specific competing-risk survival analysis. It expands the multi-state status column into a series of binary columns by treating an event for a cause as censoring for all other causes.
cfc.prepdata(formul, dat)
cfc.prepdata(formul, dat)
formul |
Original survival formula. |
dat |
Original data frame, with |
The output data frame will have K
new binary status columns. The K
new status columns will be named "status_1"
, "status_2"
through "status_<K>"
. Each of the output formulas in formula.list
field will have the corresponding status
. Column "status_1" will be 1
wherever status
equals 1
in original data frame, and 0
elsewhere, and similarly for the remaining K-1
newly-added status columns.
A list with the following elements:
K |
Number of causes. |
dat |
Expanded data frame. |
formula.list |
A list of |
formula.noresp |
A formula with no left-hand side (time and status variables). This can be used for preparing the model matrix for prediction data sets, which can possibly have no response. |
tmax |
Maximum time to event/censoring extracted from original data frame. This can be used, e.g., during competing-risk analysis. |
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
data(bmt) prep.out <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt)
data(bmt) prep.out <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt)
Convenient function to build cause-specific, parametric survival models using the survival package. This is followed by application of cfc
function to produce cumulative incidence functions.
cfc.survreg(formula, data, newdata = NULL, dist = "weibull" , control = survreg.control(), tout, Nmax = 100L , rel.tol = 1e-05)
cfc.survreg(formula, data, newdata = NULL, dist = "weibull" , control = survreg.control(), tout, Nmax = 100L , rel.tol = 1e-05)
formula |
Survival formula with a multi-state status variable. See |
data |
Data frame containing variables listed in |
newdata |
Data frame of structure similar to |
dist |
One of |
control |
List of |
tout |
Time points, along which to produce the cumulative incidence curves. |
Nmax |
Maximum number of subdivisions to be used in the |
rel.tol |
Threshold for relative error in |
A list with the following elements:
K |
Number of causes. |
formulas |
List of formulas used in each of the |
regs |
List of all cause-specific regression objects returned by |
tout |
Same as input. |
cfc |
An object of class |
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
data(bmt) formul <- Surv(time, cause) ~ platelet + age + tcell ret <- cfc.survreg(formul, bmt[1:300, ], bmt[-(1:300), ] , Nmax = 300, rel.tol = 1e-3)
data(bmt) formul <- Surv(time, cause) ~ platelet + age + tcell ret <- cfc.survreg(formul, bmt[1:300, ], bmt[-(1:300), ] , Nmax = 300, rel.tol = 1e-3)
survreg
models
Function for predicting survival probability as a function of time for survreg
regression objects in survival package. It can be used to mix survreg
models with other survival models in competing-risk analysis, using CFC package. This function is used inside cfc.survreg
.
cfc.survreg.survprob(t, args, n)
cfc.survreg.survprob(t, args, n)
t |
Time from index. Must be non-negative, but can be a vector. |
args |
Regression object that is returned by |
n |
Observation index, must be between |
Vector of survival probabilities at time(s) t
.
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
## Not run: library("CFC") # for cfc data(bmt) library("randomForestSRC") # for rfsrc library("survival") # for survreg prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- prep$formula.list[[1]] f2 <- prep$formula.list[[2]] dat <- prep$dat tmax <- prep$tmax # building a parametric Weibull regression model # for cause 1 reg1 <- survreg(f1, dat, x = TRUE) # must keep x for prediction # building a random forest survival model for cause 2 reg2 <- rfsrc(f2, dat) # implementing a continuous interface for the random forest # survival function rfsrc.survfunc <- function(t, args, n) { which.zero <- which(t < .Machine$double.eps) ret <- approx(args$time.interest, args$survival[n, ], t, rule = 2)$y ret[which.zero] <- 1.0 return (ret) } # constructing function and argument list f.list <- list(cfc.survreg.survprob, rfsrc.survfunc) arg.list <- list(reg1, reg2) # competing-risk analysis tout <- seq(0.0, tmax, length.out = 10) # increase rel.tol for higher accuracy cfc.out <- cfc(f.list, arg.list, nrow(bmt), tout, rel.tol = 1e-3) ## End(Not run)
## Not run: library("CFC") # for cfc data(bmt) library("randomForestSRC") # for rfsrc library("survival") # for survreg prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- prep$formula.list[[1]] f2 <- prep$formula.list[[2]] dat <- prep$dat tmax <- prep$tmax # building a parametric Weibull regression model # for cause 1 reg1 <- survreg(f1, dat, x = TRUE) # must keep x for prediction # building a random forest survival model for cause 2 reg2 <- rfsrc(f2, dat) # implementing a continuous interface for the random forest # survival function rfsrc.survfunc <- function(t, args, n) { which.zero <- which(t < .Machine$double.eps) ret <- approx(args$time.interest, args$survival[n, ], t, rule = 2)$y ret[which.zero] <- 1.0 return (ret) } # constructing function and argument list f.list <- list(cfc.survreg.survprob, rfsrc.survfunc) arg.list <- list(reg1, reg2) # competing-risk analysis tout <- seq(0.0, tmax, length.out = 10) # increase rel.tol for higher accuracy cfc.out <- cfc(f.list, arg.list, nrow(bmt), tout, rel.tol = 1e-3) ## End(Not run)
Constructing cumulative incidence and event-free probability functions from cause-specific survival probabilities evaluated at fixed time points.
cfc.tbasis(p1, p2, unity.tol = 1e-06, diff.tol = 0.01, diff.tol.policy = c("mean", "all"), check = TRUE)
cfc.tbasis(p1, p2, unity.tol = 1e-06, diff.tol = 0.01, diff.tol.policy = c("mean", "all"), check = TRUE)
p1 |
Multi-dimensional array containing survival probabilities for cause 1 (i.e. exponential of the negative integral of hazard function). First dimension must correspond to time points at which probabilities are calculated. Elements with same time, but distributed in the space of remaining dimensions, are treated independently. These diemensions can correspond, e.g., to observations or samples (in Bayesian frameworks). |
p2 |
Multi-dimensional array containing survival probabilities for cause 2. See note for |
unity.tol |
Tolerance for difference of survival probabilities from 1.0 at time=0.0, which is the first 'row' of arrays |
diff.tol |
Tolerance for change in survival probabilities from one time point to the next. Large changes lead to higher errors during numerical integration. |
diff.tol.policy |
If |
check |
Boolean flag indicating whether or not to check probability arrays for validity. Current validity checks are: 1) ensuring all probabilities are between 0.0 and 1.0, 2) all probabilities at time=0.0 are equal to 1.0 (see |
Assuming one-dimensional p1
and p2
for clarity, the algorithm calculates cumulative incidence function for cuase 1 using a recursive formula: ci1[n+1] = ci1[n] + dci1[n]
, where dci1[n] = 0.5*(p2[n] + p2[n+1])*(p1[n] - p1[n+1])
. The increment in cumulative incidence function for cause 2 is similarly calculated, dci2[n] = 0.5*(p1[n] + p1[n+1])*(p2[n] - p2[n+1])
. These equations guarantee that dci1[n] + dci2[n] = p1[n]*p2[n] - p1[n+1]*p2[n+1]
. Event-free probability is simply calculated as codeefp[n] = p1[n]*p2[n]. Taken together, this numerical integration ensures that efp[n+1] - efp[n] + dci1[n] + dci2[n] = 0
.
If p1
and p2
are one-dimensional arrays (i.e. vectors), a matrix with columns named "ci1"
, "ci2"
and "efp"
is returned, representing the cummulative incidence functions for cause 1 and cause 2 and the event-free probability, evaluated at same time points as p1
and p2
are provided. If p1
and p2
are multi-dimensional arrays, a list is returned with elements "ci1"
, "ci2"
and "efp"
, each one with the same interpretation, and all of the same dimensions as p1
and p2
.
The integration algorithm described above does not require knowledge of time step. (Alternatively, using hazard functions for integration would have required specification of time step.) Since p1
and p2
are integrals (followed by exponentiation) of cause-specific hazard functions, using them directly adds to robustness of numerical integration and avoids error accumulation. The returned cumulative incidence and event-free probabilities correspond to the same time points assumed for input cause-specific probabilities.
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
Prentice et al (1978). The analysis of failure times in the presence of competing risks. Biometrics, 541-554.
## Not run: # prepare data for cause-specific competing-risk analysis data(bmt) bmt$status1 <- 1*(bmt$cause==1) bmt$status2 <- 1*(bmt$cause==2) f1 <- Surv(time, status1) ~ platelet + age + tcell f2 <- Surv(time, status2) ~ platelet + age + tcell # sample-based bayesian weibull regression library(BSGW) reg1 <- bsgw(f1, bmt, ordweib = TRUE, control = bsgw.control(iter = 500, burnin = 100, nskip = 50)) reg2 <- bsgw(f2, bmt, ordweib = TRUE, control = bsgw.control(iter = 500, burnin = 100, nskip = 50)) # prediction on a uniform grid of 100 time points # (use first 50 observations for speed) pred1 <- predict(reg1, newdata = bmt[1:50,], tvec = 100) pred2 <- predict(reg2, newdata = bmt[1:50,], tvec = 100) # permuting dimensions of survival objects to conform with cfc S1 <- aperm(pred1$smp$S, c(2,1,3)) S2 <- aperm(pred2$smp$S, c(2,1,3)) # cause-specific competing risk analysis - time mode my.cfc <- cfc.tbasis(S1, S2) # calculating averages across observations (e.g. patients in the study) my.summ <- summary(my.cfc, MARGIN = c(1,2)) # plotting mean CI and event-free functions # as well as their sampled-based confidence intervals plot(my.summ, t = pred1$tvec) ## End(Not run)
## Not run: # prepare data for cause-specific competing-risk analysis data(bmt) bmt$status1 <- 1*(bmt$cause==1) bmt$status2 <- 1*(bmt$cause==2) f1 <- Surv(time, status1) ~ platelet + age + tcell f2 <- Surv(time, status2) ~ platelet + age + tcell # sample-based bayesian weibull regression library(BSGW) reg1 <- bsgw(f1, bmt, ordweib = TRUE, control = bsgw.control(iter = 500, burnin = 100, nskip = 50)) reg2 <- bsgw(f2, bmt, ordweib = TRUE, control = bsgw.control(iter = 500, burnin = 100, nskip = 50)) # prediction on a uniform grid of 100 time points # (use first 50 observations for speed) pred1 <- predict(reg1, newdata = bmt[1:50,], tvec = 100) pred2 <- predict(reg2, newdata = bmt[1:50,], tvec = 100) # permuting dimensions of survival objects to conform with cfc S1 <- aperm(pred1$smp$S, c(2,1,3)) S2 <- aperm(pred2$smp$S, c(2,1,3)) # cause-specific competing risk analysis - time mode my.cfc <- cfc.tbasis(S1, S2) # calculating averages across observations (e.g. patients in the study) my.summ <- summary(my.cfc, MARGIN = c(1,2)) # plotting mean CI and event-free functions # as well as their sampled-based confidence intervals plot(my.summ, t = pred1$tvec) ## End(Not run)
cfc
summary
method for class cfc
.
## S3 method for class 'cfc' summary(object , f.reduce = function(x) x , pval = 0.05, ...) ## S3 method for class 'summary.cfc' plot(x, which = c(1, 2), ...)
## S3 method for class 'cfc' summary(object , f.reduce = function(x) x , pval = 0.05, ...) ## S3 method for class 'summary.cfc' plot(x, which = c(1, 2), ...)
object |
An object of class "cfc", usually the result of a call to |
f.reduce |
Function to be applied to each sub-array of |
pval |
Desired significance level for confidence intervals produced by |
x |
An object of class "summary.cfc", usually the result of a call to |
which |
Vector of integers, indicating which plot(s) must be produced: 1) cumulative incidence functions, one per cause. For each cause, median and credible bands are plotted vs. time-from-index. 2) (unadjusted) survival functions, one per cause. Similar to (1), median and credible bands are plotted. |
... |
Further arguments to be passed to |
Recall that the survival probability and cumulative incidence arrays returned by cfc
are three-dimensional, and their first two dimensions indicate 1) time points and 2) causes. f.reduce
is expected to produce an array of a fixed length, when applied to each sub-array, ci[i, j, ]
and s[i, j, ]
. The end-result is two three-dimensional array, where the first two dimensions are identical to its input arrays. This 3D array is then passed to the quantile
function to compute median and credible bands. There is a special case where f.reduce
returns a scalar, rather than an array, when applied to each sub-array. In this case, quantile calculation is meaningless and we return simply these point estimates. In summary, the return object from summary
is a list with elements: 1) ci
(cumulative incidence), 2) s
(survival), and 3) quantiles
, a boolean flag indicating whether the cumulative incidence and survival arrays returned are quantiles or point estimates.
Alireza S. Mahani, Mansour T.A. Sharabiani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
## Not run: library("BSGW") # used for Bayesian survival regression data(bmt) # splitting data into training and prediction sets idx.train <- sample(1:nrow(bmt), size = 0.7 * nrow(bmt)) idx.pred <- setdiff(1:nrow(bmt), idx.train) nobs.train <- length(idx.train) nobs.pred <- length(idx.pred) # prepare data and formula for Bayesian cause-specific survival regression # using R package BSGW out.prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- out.prep$formula.list[[1]] f2 <- out.prep$formula.list[[2]] dat <- out.prep$dat tmax <- out.prep$tmax # estimating cause-specific models # set nsmp to larger number in real-world applications nsmp <- 10 reg1 <- bsgw(f1, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) reg2 <- bsgw(f2, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) # defining survival function for this model survfunc <- function(t, args, n) { nobs <- args$nobs; natt <- args$natt; nsmp <- args$nsmp alpha <- args$alpha; beta <- args$beta; X <- args$X idx.smp <- floor((n - 1) / nobs) + 1 idx.obs <- n - (idx.smp - 1) * nobs return (exp(- t ^ alpha[idx.smp] * exp(sum(X[idx.obs, ] * beta[idx.smp, ])))); } # preparing function and argument lists X.pred <- as.matrix(cbind(1, bmt[idx.pred, c("platelet", "age", "tcell")])) arg.1 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg1$smp$betas), beta = reg1$smp$beta, X = X.pred) arg.2 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg2$smp$betas), beta = reg2$smp$beta, X = X.pred) arg.list <- list(arg.1, arg.2) f.list <- list(survfunc, survfunc) # cause-specific competing-risk # set rel.tol to smaller number in real-world applications out.cfc <- cfc(f.list, arg.list, nobs.pred * nsmp, tout, rel.tol = 1e-2) # summarizing (and plotting) the results # this function calculates the population-average CI and survival, one # per each MCMC sample; therefore, the quantiles produced by the summary # method, correspondingly, reflect our confidence in population-average values my.f.reduce <- function(x, nobs, nsmp) { return (colMeans(array(x, dim = c(nobs, nsmp)))) } my.summ <- summary(out.cfc, f.reduce = my.f.reduce, nobs = nobs.pred, nsmp = nsmp) ## End(Not run)
## Not run: library("BSGW") # used for Bayesian survival regression data(bmt) # splitting data into training and prediction sets idx.train <- sample(1:nrow(bmt), size = 0.7 * nrow(bmt)) idx.pred <- setdiff(1:nrow(bmt), idx.train) nobs.train <- length(idx.train) nobs.pred <- length(idx.pred) # prepare data and formula for Bayesian cause-specific survival regression # using R package BSGW out.prep <- cfc.prepdata(Surv(time, cause) ~ platelet + age + tcell, bmt) f1 <- out.prep$formula.list[[1]] f2 <- out.prep$formula.list[[2]] dat <- out.prep$dat tmax <- out.prep$tmax # estimating cause-specific models # set nsmp to larger number in real-world applications nsmp <- 10 reg1 <- bsgw(f1, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) reg2 <- bsgw(f2, dat[idx.train, ], control = bsgw.control(iter = nsmp) , ordweib = T, print.level = 0) # defining survival function for this model survfunc <- function(t, args, n) { nobs <- args$nobs; natt <- args$natt; nsmp <- args$nsmp alpha <- args$alpha; beta <- args$beta; X <- args$X idx.smp <- floor((n - 1) / nobs) + 1 idx.obs <- n - (idx.smp - 1) * nobs return (exp(- t ^ alpha[idx.smp] * exp(sum(X[idx.obs, ] * beta[idx.smp, ])))); } # preparing function and argument lists X.pred <- as.matrix(cbind(1, bmt[idx.pred, c("platelet", "age", "tcell")])) arg.1 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg1$smp$betas), beta = reg1$smp$beta, X = X.pred) arg.2 <- list(nobs = nobs.pred, natt = 4, nsmp = nsmp , alpha = exp(reg2$smp$betas), beta = reg2$smp$beta, X = X.pred) arg.list <- list(arg.1, arg.2) f.list <- list(survfunc, survfunc) # cause-specific competing-risk # set rel.tol to smaller number in real-world applications out.cfc <- cfc(f.list, arg.list, nobs.pred * nsmp, tout, rel.tol = 1e-2) # summarizing (and plotting) the results # this function calculates the population-average CI and survival, one # per each MCMC sample; therefore, the quantiles produced by the summary # method, correspondingly, reflect our confidence in population-average values my.f.reduce <- function(x, nobs, nsmp) { return (colMeans(array(x, dim = c(nobs, nsmp)))) } my.summ <- summary(out.cfc, f.reduce = my.f.reduce, nobs = nobs.pred, nsmp = nsmp) ## End(Not run)
summary
method for class cfc.pbasis
.
## S3 method for class 'cfc.pbasis' summary(object, ...) ## S3 method for class 'summary.cfc.pbasis' plot(x, ...)
## S3 method for class 'cfc.pbasis' summary(object, ...) ## S3 method for class 'summary.cfc.pbasis' plot(x, ...)
object |
An object of class "cfc.pbasis", usually the result of a call to |
x |
An object of class "summary.cfc.pbasis", usually the result of a call to |
... |
Further arguments to be passed to/from other methods. |
The function summary.cfc.pbasis
calculates the average of cumulative incidence and event-free probability functions at each time point across all elements of the object list. If the object is a matrix, it is returned without change.
Alireza S. Mahani, Mansour T.A. Sharabiani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
The model fitting function is cfc.pbasis
. See summary
and plot
for descriptions of the generic methods. See cfc.tbasis
for time-denominated CFC, as well as usage examples.
cfc.survreg
summary
and method for class cfc.survreg
.
## S3 method for class 'cfc.survreg' summary(object, obs.idx = "all", ...) ## S3 method for class 'summary.cfc.survreg' plot(x, which = c(1, 2), ...)
## S3 method for class 'cfc.survreg' summary(object, obs.idx = "all", ...) ## S3 method for class 'summary.cfc.survreg' plot(x, which = c(1, 2), ...)
object |
An object of class "cfc.survreg", usually the result of a call to |
obs.idx |
Index of observations to calculate mean cumulative incidence for; defaults to all observation. |
... |
Further arguments to be passed to/from other methods. |
x |
An object of class |
which |
Vector of integers, indicating which plot(s) must be produced: 1) cumulative incidence functions, one per cause, as a function of time-to-index, all in the same plot, 2) comparison of cumulative incidence function with/without competing-risk adjustment. The unadjusted figure is equivalent to 1 minus the Kaplan-Meyer (i.e., survival) function. |
summary.cfc.surveeg
produces a matrix of dimensions length(object$tout)
(number of time points) by object$K
(number of causes). See description of which
aregument for plot.summary.cfc.survreg
.
Mansour T.A. Sharabiani, Alireza S. Mahani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
The model fitting function is cfc.survreg
. See summary
and plot
for descriptions of the generic methods. For more flexible ways of cause-specific competing-risk analysis, see cfc
.
summary
method for class cfc.tbasis
.
## S3 method for class 'cfc.tbasis' summary(object, MARGIN = if (class(object)[2] == "matrix") NULL else 1, ...) ## S3 method for class 'summary.cfc.tbasis' plot(x, t = 1, ci = 0.95, ...)
## S3 method for class 'cfc.tbasis' summary(object, MARGIN = if (class(object)[2] == "matrix") NULL else 1, ...) ## S3 method for class 'summary.cfc.tbasis' plot(x, t = 1, ci = 0.95, ...)
object |
An object of class "cfc.tbasis", usually the result of a call to |
MARGIN |
Dimensions of cumulative incidence and event-free probability arrays to keep while averaging the remaining dimensions. If the |
x |
An object of class "summary.cfc.tbasis", usually the result of a call to |
t |
Regular time step, or vector of time values, used for producing cumulative incidence and event-free probability plots. |
ci |
Confidence interval used in cumulative incidence and event-free probability plots. |
... |
Further arguments to be passed to/from other methods. |
The function summary.cfc.tbasis
calculates the average of cumulative incidence and event-free probability functions as directed by MARGIN
. For example, if the element ci1
of the object list is three-dimensional, then using MARGIN=c(1,2)
causes the last dimension to be averaged out.
Alireza S. Mahani, Mansour T.A. Sharabiani
Mahani A.S. and Sharabiani M.T.A. (2019). Bayesian, and Non-Bayesian, Cause-Specific Competing-Risk Analysis for Parametric and Nonparametric Survival Functions: The R Package CFC. Journal of Statistical Software, 89(9), 1-29. doi:10.18637/jss.v089.i09
The model fitting function is cfc.tbasis
. See summary
and plot
for descriptions of the generic methods. See cfc.pbasis
for probability-denominated CFC, as well as usage examples.