Title: | Bayesian Mixture Survival Models using Additive Mixture-of-Weibull Hazards, with Lasso Shrinkage and Stratification |
---|---|
Description: | Bayesian Mixture Survival Models using Additive Mixture-of-Weibull Hazards, with Lasso Shrinkage and Stratification. As a Bayesian dynamic survival model, it relaxes the proportional-hazard assumption. Lasso shrinkage controls overfitting, given the increase in the number of free parameters in the model due to presence of two Weibull components in the hazard function. |
Authors: | Alireza S. Mahani, Mansour T.A. Sharabiani |
Maintainer: | Alireza S. Mahani <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.9.1 |
Built: | 2024-10-31 16:32:58 UTC |
Source: | https://github.com/cran/BayesMixSurv |
Bayesian survival model for right-censored data, using a sum of two hazard functions, each having a power dependence on time, corresponding to a Weibull distribution on event density. (Note that event density function for the mixture model does NOT remain a Weibull distribution.) Each component has a different shape and scale parameter, with scale parameters each being the exponential of a linear function of covariates specified in formula1
and formula2
. Stratification is implemented using a common set of intercepts between the two components. Lasso shrinkage - using Laplace prior on coefficients (Park and Casella 2008) - allows for variable selection in the presence of low observation-to-variable ratio. The mixture model allows for time-dependent (and context-dependent) hazard ratios. Confidence intervals for coefficient estimation and prediction are generated using full Bayesian paradigm, i.e. by keeping all samples rather than summarizing them into mean and sd. Posterior distribution is estimated via MCMC sampling, using univariate slice sampler with stepout and shrinkage (Neal 2003).
bayesmixsurv(formula1, data, formula2=formula1, stratCol=NULL, weights, subset , na.action=na.fail, control=bayesmixsurv.control(), print.level=2) bayesmixsurv.control(single=FALSE, alpha2.fixed=NULL, alpha.boundary=1.0, lambda1=1.0 , lambda2=lambda1, iter=1000, burnin=round(iter/2), sd.thresh=1e-4, scalex=TRUE , nskip=round(iter/10)) ## S3 method for class 'bayesmixsurv' print(x, ...)
bayesmixsurv(formula1, data, formula2=formula1, stratCol=NULL, weights, subset , na.action=na.fail, control=bayesmixsurv.control(), print.level=2) bayesmixsurv.control(single=FALSE, alpha2.fixed=NULL, alpha.boundary=1.0, lambda1=1.0 , lambda2=lambda1, iter=1000, burnin=round(iter/2), sd.thresh=1e-4, scalex=TRUE , nskip=round(iter/10)) ## S3 method for class 'bayesmixsurv' print(x, ...)
formula1 |
Survival formula expressing the time/status variables as well as covariates used in the first component. |
data |
Data frame containing the covariates and response variable, as well as the stratification column. |
formula2 |
Survival formula expressing the covariates used in the second component. No left-hand side is necessary since the response variable information is extracted from |
stratCol |
Name of column in |
weights |
Optional vector of case weights. *Not supported yet* |
subset |
Subset of the observations to be used in the fit. *Not supported yet* |
na.action |
Missing-data filter function. *Not supported yet (only na.fail behavior works)* |
control |
See |
print.level |
Controlling verbosity level. |
single |
If |
alpha2.fixed |
If provided, it specifies the shape parameter of the second component. Default is |
alpha.boundary |
When |
lambda1 |
Lasso Shrinkage parameter used in the Laplace prior on covariates used in the first component. |
lambda2 |
Lasso Shrinkage parameter used in the Laplace prior on covariates used in the second component. Defaults to |
iter |
Number of posterior MCMC samples to generate. |
burnin |
Number of initial MCMC samples to discard before calculating summary statistics. |
sd.thresh |
Threshold for standard deviation of a covariate (after possible centering/scaling). If below the threshold, the corresponding coefficient is removed from sampling, i.e. its value is clamped to zero. |
scalex |
If |
nskip |
Controlling how often to print progress report during MCMC run. For example, if |
x |
Object of class 'bayesmixsurv', usually the result of a call to |
... |
Arguments to be passed to/from other methods. |
The function bayesmixsurv.control
return a list with the same elements as its input parameters. The function bayesmixsurv
returns object of class bayesmixsurv
, with the following components:
call |
The matched call |
formula1 |
Same as input. |
formula2 |
Same as input. |
weights |
Same as input. *Not supported yet* |
subset |
Same as input. *Not supported yet* |
na.action |
Same as input. *Not supported yet* (current behavior is |
control |
Same as input. |
X1 |
Model matrix used for component 1, after potential centering and scaling. |
X2 |
Model matrix used for component 2, after potential centering and scaling. |
y |
Survival response variable (time and status) used in the model. |
contrasts1 |
The contrasts used for component 1 (where relevant). |
contrasts2 |
The contrasts used for component 2 (where relevant). |
xlevels1 |
A record of the levels of the factors used in fitting for component 1 (where relevant). |
xlevels2 |
A record of the levels of the factors used in fitting for component 2 (where relevant). |
terms1 |
The terms object used for component 1. |
terms2 |
The terms object used for component 2. |
colnamesX1 |
Names of columns for |
colnamesX2 |
Names of columns for |
apply.scale.X1 |
Index of columns of |
apply.scale.X2 |
Index of columns of |
centerVec.X1 |
Vector of centering parameters for columns of |
centerVec.X2 |
Vector of centering parameters for columns of |
scaleVec.X1 |
Vector of scaling parameters for columns of |
scaleVec.X2 |
Vector of scaling parameters for columns of |
Xg |
Model matrix associated with stratification (if any). |
stratContrasts |
The contrasts used for stratification model matrix, if any. |
stratXlevels |
A record of the levels of the factors used in stratification (if any)). |
stratTerms |
The terms object used for stratification. |
colnamesXg |
Names of columns for |
idx1 |
Vector of indexes into |
idx2 |
Vector of indexes into |
median |
List of median values, with elements including |
max |
Currently, a list with one element, |
smp |
List of coefficient samples, with elements |
Alireza S. Mahani, Mansour T.A. Sharabiani
Neal R.M. (2003). Slice Sampling. Annals of Statistics, 31, 705-767.
Park T. and Casella G. (2008) The Bayesian Lasso. Journal of the American Statistical Association, 103, 681-686.
# NOTE: to ensure convergence, typically more than 100 samples are needed # fit the most general model, with two Weibull components and unspecified shape parameters ret <- bayesmixsurv(Surv(time, status)~as.factor(trt)+age+as.factor(celltype)+prior, veteran , control=bayesmixsurv.control(iter=100)) # fix one of the two shape parameters ret2 <- bayesmixsurv(Surv(time, status)~as.factor(trt)+age+as.factor(celltype)+prior, veteran , control=bayesmixsurv.control(iter=100, alpha2.fixed=1.0))
# NOTE: to ensure convergence, typically more than 100 samples are needed # fit the most general model, with two Weibull components and unspecified shape parameters ret <- bayesmixsurv(Surv(time, status)~as.factor(trt)+age+as.factor(celltype)+prior, veteran , control=bayesmixsurv.control(iter=100)) # fix one of the two shape parameters ret2 <- bayesmixsurv(Surv(time, status)~as.factor(trt)+age+as.factor(celltype)+prior, veteran , control=bayesmixsurv.control(iter=100, alpha2.fixed=1.0))
bayesmixsurv.crossval
calculates cross-validation-based, out-of-sample log-likelihood of a bsgw model for a data set, given the supplied folds. bayesmixsurv.crossval.wrapper
applies bayesmixsurv.crossval
to a set of combinations of shrinkage parameters (lambda1
,lambda2
) and produces the resulting vector of log-likelihood values as well as the specific combination of shrinkage parameters associated with the maximum log-likelihood. bayesmixsurv.generate.folds
generates random partitions, while bayesmixsurv.generate.folds.eventbalanced
generates random partitions with events evenly distributed across partitions. The latter feature is useful for cross-valiation of small data sets with low event rates, since it prevents over-accumulation of events in one or two partitions, and lack of events altogether in other partitions.
bayesmixsurv.generate.folds(ntot, nfold=5) bayesmixsurv.generate.folds.eventbalanced(formula, data, nfold=5) bayesmixsurv.crossval(data, folds, all=FALSE, print.level=1 , control=bayesmixsurv.control(), ...) bayesmixsurv.crossval.wrapper(data, folds, all=FALSE, print.level=1 , control=bayesmixsurv.control(), lambda.min=0.01, lambda.max=100, nlambda=10 , lambda1.vec=exp(seq(from=log(lambda.min), to=log(lambda.max), length.out = nlambda)) , lambda2.vec=NULL , lambda12=if (is.null(lambda2.vec)) cbind(lambda1=lambda1.vec, lambda2=lambda1.vec) else as.matrix(expand.grid(lambda1=lambda1.vec, lambda2=lambda2.vec)), plot=TRUE, ...)
bayesmixsurv.generate.folds(ntot, nfold=5) bayesmixsurv.generate.folds.eventbalanced(formula, data, nfold=5) bayesmixsurv.crossval(data, folds, all=FALSE, print.level=1 , control=bayesmixsurv.control(), ...) bayesmixsurv.crossval.wrapper(data, folds, all=FALSE, print.level=1 , control=bayesmixsurv.control(), lambda.min=0.01, lambda.max=100, nlambda=10 , lambda1.vec=exp(seq(from=log(lambda.min), to=log(lambda.max), length.out = nlambda)) , lambda2.vec=NULL , lambda12=if (is.null(lambda2.vec)) cbind(lambda1=lambda1.vec, lambda2=lambda1.vec) else as.matrix(expand.grid(lambda1=lambda1.vec, lambda2=lambda2.vec)), plot=TRUE, ...)
ntot |
Number of observations to create partitions for. It must typically be set to |
nfold |
Number of folds or partitions to generate. |
formula |
Formula specifying the covariates to be used in component 1, and the time/status response variable in the survival model. |
data |
Data frame containing the covariates and response, used in training and prediction. |
folds |
An integer vector of length |
all |
If |
print.level |
Verbosity of progress report. |
control |
List of control parameters, usually the output of bayesmixsurv.control. |
lambda.min |
Minimum value used to generate |
lambda.max |
Maximum value used to generate |
nlambda |
Length of |
lambda1.vec |
Vector of shrinkage parameters to be tested for component-1 coefficients. |
lambda2.vec |
Vector of shrinkage parameters to be tested for component-2 coefficients. |
lambda12 |
A data frame that enumerates all combinations of |
plot |
If |
... |
Further arguments passed to |
Functions bayesmixsurv.generate.folds
and bayesmixsurv.generate.folds.eventbalanced
produce integer vectors of length ntot
or nrow(data)
respectively. The output of these functions can be directly passed to bayesmixsurv.crossval
or bayesmixsurv.crossval.wrapper
. Function bayesmixsurv.crossval
returns the log-likelihood of data under the assumed bsgw model, calculated using a cross-validation scheme with the supplied fold
parameter. If all=TRUE
, the estimation objects for each of the nfold
estimation jobs will be returned as the "estobjs" attribute of the returned value. Function bayesmixsurv.crossval.wrapper
returns a list with elements lambda1
and lambda2
, the optimal shrinkage parameters for components 1 and 2, respectively. Additionally, the following attributes are attached:
loglike.vec |
Vector of log-likelihood values, one for each tested combination of |
loglike.opt |
The maximum log-likelihood value from the |
lambda12 |
Data frame with columns |
estobjs |
If |
Alireza S. Mahani, Mansour T.A. Sharabiani
# NOTE: to ensure convergence, typically more than 30 samples are needed folds <- bayesmixsurv.generate.folds.eventbalanced(Surv(futime, fustat) ~ 1, ovarian, 5) cv <- bayesmixsurv.crossval(ovarian, folds, formula1=Surv(futime, fustat) ~ ecog.ps + rx , control=bayesmixsurv.control(iter=30, nskip=10), print.level = 3) cv2 <- bayesmixsurv.crossval.wrapper(ovarian, folds, formula1=Surv(futime, fustat) ~ ecog.ps + rx , control=bayesmixsurv.control(iter=30, nskip=10) , lambda1.vec=exp(seq(from=log(0.1), to=log(1), length.out = 3)))
# NOTE: to ensure convergence, typically more than 30 samples are needed folds <- bayesmixsurv.generate.folds.eventbalanced(Surv(futime, fustat) ~ 1, ovarian, 5) cv <- bayesmixsurv.crossval(ovarian, folds, formula1=Surv(futime, fustat) ~ ecog.ps + rx , control=bayesmixsurv.control(iter=30, nskip=10), print.level = 3) cv2 <- bayesmixsurv.crossval.wrapper(ovarian, folds, formula1=Surv(futime, fustat) ~ ecog.ps + rx , control=bayesmixsurv.control(iter=30, nskip=10) , lambda1.vec=exp(seq(from=log(0.1), to=log(1), length.out = 3)))
Four sets of MCMC diagnostic plots are currently generated: 1) log-likelihood trace plots, 2) coefficient trace plots, 3) coefficient autocorrelation plots, 4) coefficient histograms.
## S3 method for class 'bayesmixsurv' plot(x, pval=0.05, burnin=round(x$control$iter/2), nrow=2, ncol=3, ...)
## S3 method for class 'bayesmixsurv' plot(x, pval=0.05, burnin=round(x$control$iter/2), nrow=2, ncol=3, ...)
x |
A |
pval |
The P-value at which lower/upper bounds on coefficients are calculated and overlaid on trace plots and historgrams. |
burnin |
Number of samples discarded from the beginning of an MCMC chain, after which parameter quantiles are calculated. |
nrow |
Number of rows of subplots within each figure, applied to plot sets 2-4. |
ncol |
Number of columns of subplots within each figure, applied to plot sets 2-4. |
... |
Further arguments to be passed to/from other methods. |
Alireza S. Mahani, Mansour T.A. Sharabiani
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx, ovarian , control=bayesmixsurv.control(iter=800, nskip=100)) plot(est)
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx, ovarian , control=bayesmixsurv.control(iter=800, nskip=100)) plot(est)
Calculates log-likelihood and hazard/cumulative hazard/survival functions over a user-supplied vector time values, based on bayesmixsurv model object.
## S3 method for class 'bayesmixsurv' predict(object, newdata=NULL, tvec=NULL, burnin=object$control$burnin, ...) ## S3 method for class 'predict.bayesmixsurv' summary(object, idx=1:dim(object$smp$h)[3], burnin=object$burnin, pval=0.05 , popmean=identical(idx,1:dim(object$smp$h)[3]), make.plot=TRUE, ...)
## S3 method for class 'bayesmixsurv' predict(object, newdata=NULL, tvec=NULL, burnin=object$control$burnin, ...) ## S3 method for class 'predict.bayesmixsurv' summary(object, idx=1:dim(object$smp$h)[3], burnin=object$burnin, pval=0.05 , popmean=identical(idx,1:dim(object$smp$h)[3]), make.plot=TRUE, ...)
object |
For |
newdata |
An optional data frame in which to look for variables with which to predict. If omiited, the fitted values (training set) are used. |
tvec |
An optional vector of time values, along which time-dependent entities (hazard, cumulative hazard, survival) will be predicted. If omitted, only the time-independent entities (currently only log-likelihood) will be calculated. If a single integer is provided for |
burnin |
Number of samples to discard from the beginning of each MCMC chain before calculating median value(s) for time-independent entities. |
idx |
Index of observations (rows of |
pval |
Desired p-value, based on which lower/upper bounds will be calculated. Default is |
popmean |
Whether population averages must be calculated or not. By default, population averages are only calculated when the entire data is included in prediction. |
make.plot |
Whether population mean and other plots must be created or not. |
... |
Further arguments to be passed to/from other methods. |
The time-dependent predicted objects (except loglike
) are three-dimensional arrays of size (nsmp x nt x nobs
), where nsmp
= number of MCMC samples, nt
= number of time values in tvec
, and nobs
= number of rows in newdata
. Therefore, even for modest data sizes, these objects can occupy large chunks of memory. For example, for nsmp=1000, nt=100, nobs=1000
, the three objects h, H, S
have a total size of 2.2GB. Since applying quantile
to these arrays is time-consuming (as needed for calculation of median and lower/upper bounds), we have left such summaries out of the scope of predict
function. Users can instead apply summary
to the prediction object to obtain summary statistics. During cross-validation-based selection of shrinkage parameter lambda
, there is no need to supply tvec
since we only need the log-likelihood value. This significantly speeds up the parameter-tuning process. The function summary.predict.bayesmixsurv
allows the user to calculates summary statistics for a subset (or all of) data, if desired. This approach is in line with the overall philosophy of delaying the data summarization until necessary, to avoid unnecessary loss in accuracy due to premature blending of information contained in individual samples.
The function predict.bayesmixsurv
returns as object of class "predict.bayesmixsurv" with the following fields:
tvec |
Actual vector of time values (if any) used for prediction. |
burnin |
Same as input. |
median |
List of median values for predicted entities. Currently, only |
smp |
List of MCMC samples for predicted entities. Elements include |
km.fit |
Kaplan-Meyer fit of the data used for prediction (if data contains response fields). |
The function summary.predict.bayesmixsurv
returns a list with the following fields:
lower |
A list of lower-bound values for |
median |
List of median values for same entities described in |
upper |
List of upper-bound values for same entities described in |
popmean |
Lower-bound/median/upper-bound values for population average of survival probability. |
km.fit |
Kaplan-Meyer fit associated with the prediction object (if available). |
Alireza S. Mahani, Mansour T.A. Sharabiani
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx + age, ovarian , control=bayesmixsurv.control(iter=400, nskip=100)) pred <- predict(est, tvec=50) predsumm <- summary(pred, idx=1:10)
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx + age, ovarian , control=bayesmixsurv.control(iter=400, nskip=100)) pred <- predict(est, tvec=50) predsumm <- summary(pred, idx=1:10)
summary
method for class "bayesmixsurv".
## S3 method for class 'bayesmixsurv' summary(object, pval = 0.05, burnin = object$control$burnin, ...) ## S3 method for class 'summary.bayesmixsurv' print(x, ...)
## S3 method for class 'bayesmixsurv' summary(object, pval = 0.05, burnin = object$control$burnin, ...) ## S3 method for class 'summary.bayesmixsurv' print(x, ...)
object |
An object of class 'bayesmixsurv', usually the result of a call to bayesmixsurv. |
x |
An object of class "summary.bayesmixsurv", usually the result of a call to |
pval |
Desired p-value, based on which lower/upper bounds will be calculated. Default is 0.05. |
burnin |
Number of samples to discard from the beginning of each MCMC chain before calculating median and lower/upper bounds. |
... |
Further arguments to be passed to/from other methods. |
An object of class summary.bayesmixsurv
, with the following elements:
call |
The matched call. |
pval |
Same as input. |
burnin |
Same as input. |
single |
Copied from |
coefficients |
A list including matrices |
Alireza S. Mahani, Mansour T.A. Sharabiani
See summary for a description of the generic method.
The model fitting function is bayesmixsurv.
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx, ovarian , control=bayesmixsurv.control(iter=800, nskip=100)) summary(est, pval=0.1)
est <- bayesmixsurv(Surv(futime, fustat) ~ ecog.ps + rx, ovarian , control=bayesmixsurv.control(iter=800, nskip=100)) summary(est, pval=0.1)