Title: | Robust Bayesian Survival Analysis |
---|---|
Description: | A framework for estimating ensembles of parametric survival models with different parametric families. The RoBSA framework uses Bayesian model-averaging to combine the competing parametric survival models into a model ensemble, weights the posterior parameter distributions based on posterior model probabilities and uses Bayes factors to test for the presence or absence of the individual predictors or preference for a parametric family (Bartoš, Aust & Haaf, 2022, <doi:10.1186/s12874-022-01676-9>). The user can define a wide range of informative priors for all parameters of interest. The package provides convenient functions for summary, visualizations, fit diagnostics, and prior distribution calibration. |
Authors: | František Bartoš [aut, cre] , Julia M. Haaf [ths] , Matthew Denwood [cph] (Original copyright holder of some modified code where indicated.), Martyn Plummer [cph] (Original copyright holder of some modified code where indicated.) |
Maintainer: | František Bartoš <[email protected]> |
License: | GPL-3 |
Version: | 1.0.2 |
Built: | 2024-11-11 07:22:25 UTC |
Source: | CRAN |
Bayesian model-averaged parametric survival analysis with ability to specify informed prior distributions and draw inference with inclusion Bayes factors. See Bartoš et al. (2022) for more details about the methodology.
See Bartoš et al. (2022), for details regarding the RoBSA methodology.
František Bartoš [email protected]
Bartoš F, Aust F, Haaf JM (2022). “Informed Bayesian survival analysis.” BMC Medical Research Methodology. doi:10.1186/s12874-022-01676-9.
Useful links:
Calibrates prior distributions for parametric survival analysis based on historical data. Returns a list of prior distribution for the intercepts and auxiliary parameters.
calibrate_meta_analytic( datasets, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), prior_mu = prior("cauchy", parameters = list(location = 0, scale = 100)), prior_tau = prior("cauchy", parameters = list(location = 0, scale = 10), truncation = list(0, Inf)), ... )
calibrate_meta_analytic( datasets, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), prior_mu = prior("cauchy", parameters = list(location = 0, scale = 100)), prior_tau = prior("cauchy", parameters = list(location = 0, scale = 10), truncation = list(0, Inf)), ... )
datasets |
list of data.frames containing the historical
data. Each data.frame must contain a column named |
distributions |
vector of parametric families for which prior distributions ought to be calibrated |
prior_mu |
prior distribution for the the meta-analytic mean parameter |
prior_tau |
prior distribution for the the meta-analytic heterogeneity parameter |
... |
additional parameters to be passed to the meta-analytic function. See BayesTools::JAGS_fit for more details. |
returns a list of prior distribution for the intercepts and auxiliary parameters.
Calibrates prior distributions for parametric survival analysis based on median survival and interquartile range. Returns a list of prior distribution for the intercepts and auxiliary parameters.
calibrate_quartiles( median_t, iq_range_t, prior_sd = 0.5, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), verbose = FALSE, search_bounds1 = c(-100, 100), search_bounds2 = c(0 + 0.01, 100) )
calibrate_quartiles( median_t, iq_range_t, prior_sd = 0.5, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), verbose = FALSE, search_bounds1 = c(-100, 100), search_bounds2 = c(0 + 0.01, 100) )
median_t |
median survival |
iq_range_t |
interquartile range of the survival |
prior_sd |
pre-specified standard deviation of the prior distributions (either a single value that is used for both the intercept and auxiliary parameter or a vector where the first value corresponds to the sd for the prior distribution on the intercept and the second value to the sd for the prior distribution on the auxiliary parameter) |
distributions |
vector of parametric families for which prior distributions ought to be calibrated |
verbose |
whether debug information be printed |
search_bounds1 |
search boundaries for the intercept parameter |
search_bounds2 |
search boundaries for the auxiliary parameter |
returns a list of prior distribution for the intercepts and auxiliary parameters.
priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5)
priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5)
Checks fitted RoBSA object for warnings and errors and prints them to the console.
check_RoBSA(fit)
check_RoBSA(fit)
fit |
a fitted RoBSA object. |
check_RoBSA
returns a vector of error and
warning messages.
"RoBSA"
corresponding to the inputcheck_setup
prints summary of "RoBSA"
ensemble
corresponding to the specified formula, data, and priors.
This function is useful for checking the ensemble configuration prior
to fitting all models.
check_setup( formula, data, priors = NULL, test_predictors = NULL, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), distributions_weights = rep(1, length(distributions)), prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = 3, sample = 5000, burnin = 2000, adapt = 500, thin = 1, parallel = FALSE, autofit = TRUE, autofit_control = set_autofit_control(), convergence_checks = set_convergence_checks(), save = "all", seed = NULL, silent = FALSE, rescale_data = FALSE, models = FALSE, ... )
check_setup( formula, data, priors = NULL, test_predictors = NULL, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), distributions_weights = rep(1, length(distributions)), prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = 3, sample = 5000, burnin = 2000, adapt = 500, thin = 1, parallel = FALSE, autofit = TRUE, autofit_control = set_autofit_control(), convergence_checks = set_convergence_checks(), save = "all", seed = NULL, silent = FALSE, rescale_data = FALSE, models = FALSE, ... )
formula |
formula for the survival model |
data |
data frame containing the data |
priors |
names list of prior distributions for each
predictor. It allows users to specify both the null and alternative
hypothesis prior distributions by assigning a named list
(with |
test_predictors |
vector of predictor names
to be tested with Bayesian model-averaged testing.
Defaults to |
distributions |
distributions of parametric survival models |
distributions_weights |
prior odds for the competing distributions |
prior_beta_null |
default prior distribution for the null hypotheses of continuous predictors |
prior_beta_alt |
default prior distribution for the alternative hypotheses of continuous predictors |
prior_factor_null |
default prior distribution for the null hypotheses of categorical predictors |
prior_factor_alt |
default prior distribution for the alternative hypotheses of categorical predictors |
prior_intercept |
named list containing prior distribution for the intercepts (with names corresponding to the distributions) |
prior_aux |
named list containing prior distribution for the auxiliary parameters (with names corresponding to the distributions) |
chains |
a number of chains of the MCMC algorithm. |
sample |
a number of sampling iterations of the MCMC algorithm.
Defaults to |
burnin |
a number of burnin iterations of the MCMC algorithm.
Defaults to |
adapt |
a number of adaptation iterations of the MCMC algorithm.
Defaults to |
thin |
a thinning of the chains of the MCMC algorithm. Defaults to
|
parallel |
whether the individual models should be fitted in parallel.
Defaults to |
autofit |
whether the model should be fitted until the convergence
criteria (specified in |
autofit_control |
allows to pass autofit control settings with the
|
convergence_checks |
automatic convergence checks to assess the fitted
models, passed with |
save |
whether all models posterior distributions should be kept
after obtaining a model-averaged result. Defaults to |
seed |
a seed to be set before model fitting, marginal likelihood
computation, and posterior mixing for reproducibility of results. Defaults
to |
silent |
do not print the results. |
rescale_data |
whether continuous predictors should be rescaled prior to
estimating the model. Defaults to |
models |
should the models' details be printed. |
... |
additional arguments. |
check_setup
invisibly returns list of summary tables.
Return a matrix of mean difference contrasts.
This is an adjustment to the contr.orthonormal
that ascertains that the prior
distributions on difference between the gran mean and factor level are identical independent
of the number of factor levels (which does not hold for the orthonormal contrast). Furthermore,
the contrast is re-scaled so the specified prior distribution exactly corresponds to the prior
distribution on difference between each factor level and the grand mean – this is approximately
twice the scale of contr.orthonormal
.
contr.meandif(n, contrasts = TRUE)
contr.meandif(n, contrasts = TRUE)
n |
a vector of levels for a factor, or the number of levels |
contrasts |
logical indicating whether contrasts should be computed |
A matrix with n rows and k columns, with k = n - 1 if contrasts = TRUE
and k = n
if contrasts = FALSE
.
There are no references for Rd macro \insertAllCites
on this help page.
contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3))
contr.meandif(c(1, 2)) contr.meandif(c(1, 2, 3))
Return a matrix of orthornomal contrasts.
Code is based on stanova::contr.bayes
and corresponding to description
by Rouder et al. (2012)
contr.orthonormal(n, contrasts = TRUE)
contr.orthonormal(n, contrasts = TRUE)
n |
a vector of levels for a factor, or the number of levels |
contrasts |
logical indicating whether contrasts should be computed |
A matrix with n rows and k columns, with k = n - 1 if contrasts = TRUE
and k = n
if contrasts = FALSE
.
Rouder JN, Morey RD, Speckman PL, Province JM (2012). “Default Bayes factors for ANOVA designs.” Journal of Mathematical Psychology, 56(5), 356–374. doi:10.1016/j.jmp.2012.08.001.
contr.orthonormal(c(1, 2)) contr.orthonormal(c(1, 2, 3))
contr.orthonormal(c(1, 2)) contr.orthonormal(c(1, 2, 3))
Functions for setting default prior distributions. Note that these default prior distributions might (and probably won't) apply to your specific data scenario.
get_default_prior_beta_null() get_default_prior_beta_alt() get_default_prior_factor_null() get_default_prior_factor_alt() get_default_prior_intercept() get_default_prior_aux()
get_default_prior_beta_null() get_default_prior_beta_alt() get_default_prior_factor_null() get_default_prior_factor_alt() get_default_prior_intercept() get_default_prior_aux()
get_default_prior_beta_null
and get_default_prior_beta_alt
return a prior distribution and get_default_prior_intercept
and
get_default_prior_aux
return a list of prior distributions.
diagnostics
creates visual
checks of individual models convergence. Numerical
overview of individual models can be obtained by
summary(object, type = "diagnostics")
,
or even more detailed information by
summary(object, type = "individual")
.
diagnostics( fit, parameter = NULL, type, plot_type = "base", show_models = NULL, lags = 30, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_autocorrelation( fit, parameter = NULL, plot_type = "base", show_models = NULL, lags = 30, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_trace( fit, parameter = NULL, plot_type = "base", show_models = NULL, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_density( fit, parameter = NULL, plot_type = "base", show_models = NULL, title = is.null(show_models) | length(show_models) > 1, ... )
diagnostics( fit, parameter = NULL, type, plot_type = "base", show_models = NULL, lags = 30, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_autocorrelation( fit, parameter = NULL, plot_type = "base", show_models = NULL, lags = 30, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_trace( fit, parameter = NULL, plot_type = "base", show_models = NULL, title = is.null(show_models) | length(show_models) > 1, ... ) diagnostics_density( fit, parameter = NULL, plot_type = "base", show_models = NULL, title = is.null(show_models) | length(show_models) > 1, ... )
fit |
a fitted RoBSA object |
parameter |
a parameter to be plotted. |
type |
type of MCMC diagnostic to be plotted.
Options are |
plot_type |
whether to use a base plot |
show_models |
MCMC diagnostics of which models should be
plotted. Defaults to |
lags |
number of lags to be shown for
|
title |
whether the model number should be displayed in title.
Defaults to |
... |
additional arguments to be passed to the plotting functions. |
diagnostics
returns either NULL
if plot_type = "base"
or an object/list of objects (depending on the number of parameters to be plotted)
of class 'ggplot2' if plot_type = "ggplot2"
.
(log) density, hazard, and survival functions for AFT exponential parametric family.
exp_aft_log_density(t, eta) exp_aft_log_hazard(t, eta) exp_aft_log_survival(t, eta) exp_aft_density(t, eta) exp_aft_hazard(t, eta) exp_aft_survival(t, eta) exp_aft_mean(eta) exp_aft_sd(eta) exp_aft_r(n, eta) exp_aft_q(p, eta) exp_aft_p(q, eta)
exp_aft_log_density(t, eta) exp_aft_log_hazard(t, eta) exp_aft_log_survival(t, eta) exp_aft_density(t, eta) exp_aft_hazard(t, eta) exp_aft_survival(t, eta) exp_aft_mean(eta) exp_aft_sd(eta) exp_aft_r(n, eta) exp_aft_q(p, eta) exp_aft_p(q, eta)
t |
vector of survival times |
eta |
linear predictor |
n |
number of observations |
p |
vector of probabilities |
q |
vector of quantiles |
exp_aft_density
, exp_aft_hazard
, and
exp_aft_survival
return the density, hazard, and survival
of the specified survival distribution. The exp_aft_log_density
,
exp_aft_log_hazard
, exp_aft_log_survival
return log of
the corresponding qualities. exp_aft_mean
and exp_aft_sd
return the mean and standard deviation of the specified survival distribution.
exp_aft_r
, exp_aft_q
, and exp_aft_p
return a random
generation, quantiles, and cumulative probabilities of the specified
survival distribution.
flexsurv
objectextract_flexsurv
extracts estimates from a
flexsurv
object in and transform them to match the
RoBSA
output.
extract_flexsurv(fit)
extract_flexsurv(fit)
fit |
an object fitted with the |
extract_flexsurv
return list of estimates lists for each
parameter.
(log) density, hazard, and survival functions for AFT gamma parametric family.
gamma_aft_log_density(t, eta, shape) gamma_aft_log_hazard(t, eta, shape) gamma_aft_log_survival(t, eta, shape) gamma_aft_density(t, eta, shape) gamma_aft_hazard(t, eta, shape) gamma_aft_survival(t, eta, shape) gamma_aft_mean(eta, shape) gamma_aft_sd(eta, shape) gamma_aft_r(n, eta, shape) gamma_aft_q(p, eta, shape) gamma_aft_p(q, eta, shape)
gamma_aft_log_density(t, eta, shape) gamma_aft_log_hazard(t, eta, shape) gamma_aft_log_survival(t, eta, shape) gamma_aft_density(t, eta, shape) gamma_aft_hazard(t, eta, shape) gamma_aft_survival(t, eta, shape) gamma_aft_mean(eta, shape) gamma_aft_sd(eta, shape) gamma_aft_r(n, eta, shape) gamma_aft_q(p, eta, shape) gamma_aft_p(q, eta, shape)
t |
vector of survival times |
eta |
linear predictor |
shape |
auxiliary parameter |
n |
number of observations |
p |
vector of probabilities |
q |
vector of quantiles |
gamma_aft_density
, gamma_aft_hazard
, and
gamma_aft_survival
return the density, hazard, and survival
of the specified survival distribution. The gamma_aft_log_density
,
gamma_aft_log_hazard
, gamma_aft_log_survival
return log of
the corresponding qualities. gamma_aft_mean
and gamma_aft_sd
return the mean and standard deviation of the specified survival distribution.
gamma_aft_r
, gamma_aft_q
, and gamma_aft_p
return a random
generation, quantiles, and cumulative probabilities of the specified
survival distribution.
Reports whether x is a RoBSA object
is.RoBSA(x)
is.RoBSA(x)
x |
an object to test |
is.RoBSA returns a boolean.
(log) density, hazard, and survival functions for AFT log-logistic parametric family.
llogis_aft_log_density(t, eta, shape) llogis_aft_log_hazard(t, eta, shape) llogis_aft_log_survival(t, eta, shape) llogis_aft_density(t, eta, shape) llogis_aft_hazard(t, eta, shape) llogis_aft_survival(t, eta, shape) llogis_aft_mean(eta, shape) llogis_aft_sd(eta, shape) llogis_aft_r(n, eta, shape) llogis_aft_q(p, eta, shape) llogis_aft_p(q, eta, shape)
llogis_aft_log_density(t, eta, shape) llogis_aft_log_hazard(t, eta, shape) llogis_aft_log_survival(t, eta, shape) llogis_aft_density(t, eta, shape) llogis_aft_hazard(t, eta, shape) llogis_aft_survival(t, eta, shape) llogis_aft_mean(eta, shape) llogis_aft_sd(eta, shape) llogis_aft_r(n, eta, shape) llogis_aft_q(p, eta, shape) llogis_aft_p(q, eta, shape)
t |
vector of survival times |
eta |
linear predictor |
shape |
auxiliary parameter |
n |
number of observations |
p |
vector of probabilities |
q |
vector of quantiles |
llogis_aft_density
, llogis_aft_hazard
, and
llogis_aft_survival
return the density, hazard, and survival
of the specified survival distribution. The llogis_aft_log_density
,
llogis_aft_log_hazard
, llogis_aft_log_survival
return log of
the corresponding qualities. llogis_aft_mean
and llogis_aft_sd
return the mean and standard deviation of the specified survival distribution.
llogis_aft_r
, llogis_aft_q
, and llogis_aft_p
return a random
generation, quantiles, and cumulative probabilities of the specified
survival distribution.
(log) density, hazard, and survival functions for AFT log-normal parametric family.
lnorm_aft_log_density(t, eta, sd) lnorm_aft_log_hazard(t, eta, sd) lnorm_aft_log_survival(t, eta, sd) lnorm_aft_density(t, eta, sd) lnorm_aft_hazard(t, eta, sd) lnorm_aft_survival(t, eta, sd) lnorm_aft_mean(eta, sd) lnorm_aft_sd(eta, sd) lnorm_aft_r(n, eta, sd) lnorm_aft_q(p, eta, sd) lnorm_aft_p(q, eta, sd)
lnorm_aft_log_density(t, eta, sd) lnorm_aft_log_hazard(t, eta, sd) lnorm_aft_log_survival(t, eta, sd) lnorm_aft_density(t, eta, sd) lnorm_aft_hazard(t, eta, sd) lnorm_aft_survival(t, eta, sd) lnorm_aft_mean(eta, sd) lnorm_aft_sd(eta, sd) lnorm_aft_r(n, eta, sd) lnorm_aft_q(p, eta, sd) lnorm_aft_p(q, eta, sd)
t |
vector of survival times |
eta |
linear predictor |
sd |
auxiliary parameter |
n |
number of observations |
p |
vector of probabilities |
q |
vector of quantiles |
lnorm_aft_density
, lnorm_aft_hazard
, and
lnorm_aft_survival
return the density, hazard, and survival
of the specified survival distribution. The lnorm_aft_log_density
,
lnorm_aft_log_hazard
, lnorm_aft_log_survival
return log of
the corresponding qualities. lnorm_aft_mean
and lnorm_aft_sd
return the mean and standard deviation of the specified survival distribution.
lnorm_aft_r
, lnorm_aft_q
, and lnorm_aft_p
return a random
generation, quantiles, and cumulative probabilities of the specified
survival distribution.
plot_models
plots individual models'
estimates for a "RoBSA"
object.
plot_models( x, parameter = NULL, conditional = FALSE, plot_type = "base", order = "decreasing", order_by = "model", ... )
plot_models( x, parameter = NULL, conditional = FALSE, plot_type = "base", order = "decreasing", order_by = "model", ... )
x |
a fitted RoBSA object |
parameter |
a name of parameter to be plotted. Defaults to the first regression parameter if left unspecified. |
conditional |
whether conditional estimates should be
plotted. Defaults to |
plot_type |
whether to use a base plot |
order |
how the models should be ordered.
Defaults to |
order_by |
what feature should be use to order the models.
Defaults to |
... |
list of additional graphical arguments
to be passed to the plotting function. Supported arguments
are |
plot_models
returns either NULL
if plot_type = "base"
or an object object of class 'ggplot2' if plot_type = "ggplot2"
.
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot posterior distribution of the treatment effect from each model plot_models(fit, parameter = "treatment") ## End(Not run)
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot posterior distribution of the treatment effect from each model plot_models(fit, parameter = "treatment") ## End(Not run)
Survival plots for a RoBSA object
plot_prediction( x, type = "survival", time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_survival( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_hazard( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_density( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... )
plot_prediction( x, type = "survival", time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_survival( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_hazard( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... ) plot_density( x, time_range = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, conditional = FALSE, plot_type = "base", samples = 10000, ... )
x |
a fitted RoBSA object. |
type |
what type of prediction should be created |
time_range |
a numeric of length two specifying the range for the
survival prediction. Defaults to |
new_data |
a data.frame containing fully specified predictors for which predictions should be made |
predictor |
an alternative input to |
covariates_data |
a supplementary input to |
conditional |
whether only models assuming presence of the specified
|
plot_type |
whether to use a base plot |
samples |
number of posterior samples to be evaluated |
... |
additional arguments. |
returns either NULL
if plot_type = "base"
or an object object of class 'ggplot2' if plot_type = "ggplot2"
.
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot survival for each level the treatment plot_survival(fit, parameter = "treatment") # plot hazard for each level the treatment plot_hazard(fit, parameter = "treatment") # plot density for each level the treatment plot_density(fit, parameter = "treatment") ## End(Not run)
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot survival for each level the treatment plot_survival(fit, parameter = "treatment") # plot hazard for each level the treatment plot_hazard(fit, parameter = "treatment") # plot density for each level the treatment plot_density(fit, parameter = "treatment") ## End(Not run)
plot.RoBSA
allows to visualize
posterior distribution of different "RoBSA"
object
parameters. See plot_survival
for plotting the survival
ways. See type
for the different model types.
## S3 method for class 'RoBSA' plot( x, parameter = NULL, conditional = FALSE, plot_type = "base", prior = FALSE, dots_prior = NULL, ... )
## S3 method for class 'RoBSA' plot( x, parameter = NULL, conditional = FALSE, plot_type = "base", prior = FALSE, dots_prior = NULL, ... )
x |
a fitted RoBSA object |
parameter |
a name of parameter to be plotted. Defaults to
the first regression parameter if left unspecified. Use
|
conditional |
whether conditional estimates should be
plotted. Defaults to |
plot_type |
whether to use a base plot |
prior |
whether prior distribution should be added to
figure. Defaults to |
dots_prior |
list of additional graphical arguments
to be passed to the plotting function of the prior
distribution. Supported arguments are |
... |
list of additional graphical arguments
to be passed to the plotting function. Supported arguments
are |
plot.RoBSA
returns either NULL
if plot_type = "base"
or an object object of class 'ggplot2' if plot_type = "ggplot2"
.
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot posterior distribution of the treatment effect plot(fit, parameter = "treatment") ## End(Not run)
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # plot posterior distribution of the treatment effect plot(fit, parameter = "treatment") ## End(Not run)
Predicts survival/hazard/density/mean/sd for a given
RoBSA object. Either predicts values for each row of a fully specified
new_data
data.frame, or for all levels of a given predictor
at the mean of continuous covariate values and default factor levels or
covariate values specified as covariates_data
data.frame.
## S3 method for class 'RoBSA' predict( object, time = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, type = c("survival", "hazard", "density", "mean", "sd"), summarize = TRUE, averaged = TRUE, conditional = FALSE, samples = 10000, ... )
## S3 method for class 'RoBSA' predict( object, time = NULL, new_data = NULL, predictor = NULL, covariates_data = NULL, type = c("survival", "hazard", "density", "mean", "sd"), summarize = TRUE, averaged = TRUE, conditional = FALSE, samples = 10000, ... )
object |
a fitted RoBSA object |
time |
a vector of time values at which the survival/hazard/density will be predicted (for each passed data point) |
new_data |
a data.frame containing fully specified predictors for which predictions should be made |
predictor |
an alternative input to |
covariates_data |
a supplementary input to |
type |
what type of prediction should be created |
summarize |
whether the predictions should be aggregated as mean and sd. Otherwise, prediction for for posterior samples is returned. |
averaged |
whether predictions should be combined with Bayesian model-averaging or whether predictions for each individual model should be returned. |
conditional |
whether only models assuming presence of the specified
|
samples |
number of posterior samples to be evaluated |
... |
additional arguments (unused) |
a list with predictions (or a list of lists in case that predictions for each
individual model are requested averaged = FALSE
)
Prints a fitted RoBSA object
## S3 method for class 'RoBSA' print(x, ...)
## S3 method for class 'RoBSA' print(x, ...)
x |
a fitted RoBSA object. |
... |
additional arguments. |
print.RoBSA
invisibly returns the print statement.
Prints summary object for RoBSA method
## S3 method for class 'summary.RoBSA' print(x, ...)
## S3 method for class 'summary.RoBSA' print(x, ...)
x |
a summary of a RoBSA object |
... |
additional arguments |
print.summary.RoBSA
invisibly returns the print statement.
prior
creates a prior distribution.
The prior can be visualized by the plot
function.
prior( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1 )
prior( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1 )
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
truncation |
list with two elements, |
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
prior
and prior_none
return an object of class 'prior'.
A named list containing the distribution name, parameters, and prior weights.
plot.prior()
, Normal, Lognormal, Cauchy,
Beta, Exponential,
LocationScaleT, InvGamma.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
prior_factor
creates a prior distribution for fitting
models with factor predictors. (Note that results across different operating
systems might vary due to differences in JAGS numerical precision.)
prior_factor( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1, contrast = "orthonormal" )
prior_factor( distribution, parameters, truncation = list(lower = -Inf, upper = Inf), prior_weights = 1, contrast = "orthonormal" )
distribution |
name of the prior distribution. The possible options are
|
parameters |
list of appropriate parameters for a given
|
truncation |
list with two elements, |
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
contrast |
type of contrast for the prior distribution. The possible options are
|
return an object of class 'prior'.
# create an orthonormal prior distribution p1 <- prior_factor(distribution = "mnormal", contrast = "orthonormal", parameters = list(mean = 0, sd = 1))
# create an orthonormal prior distribution p1 <- prior_factor(distribution = "mnormal", contrast = "orthonormal", parameters = list(mean = 0, sd = 1))
prior_informed
creates an informed prior distribution based on past
research. The prior can be visualized by the plot
function.
prior_informed(name, parameter = NULL, type = "smd")
prior_informed(name, parameter = NULL, type = "smd")
name |
name of the prior distribution. There are many options based on prior psychological or medical research. For psychology, the possible options are
For medicine, the possible options are based on Bartoš et al. (2021)
who developed empirical prior distributions for the effect size and heterogeneity parameters of the
continuous standardized outcomes based on the Cochrane database of systematic reviews.
Use |
parameter |
parameter name describing what prior distribution is supposed to be produced in cases
where the |
type |
prior type describing what prior distribution is supposed to be produced in cases
where the |
Further details can be found in van Erp et al. (2017), Gronau et al. (2017), and Bartoš et al. (2021).
prior_informed
returns an object of class 'prior'.
Bartoš F, Gronau QF, Timmers B, Otte WM, Ly A, Wagenmakers E (2021).
“Bayesian model-averaged meta-analysis in medicine.”
Statistics in Medicine, 40(30), 6743–6761.
doi:10.1002/sim.9170.
Gronau QF, Van Erp S, Heck DW, Cesario J, Jonas KJ, Wagenmakers E (2017).
“A Bayesian model-averaged meta-analysis of the power pose effect with informed and default priors: The case of felt power.”
Comprehensive Results in Social Psychology, 2(1), 123–138.
doi:10.1080/23743603.2017.1326760.
van Erp S, Verhagen J, Grasman RP, Wagenmakers E (2017).
“Estimates of between-study heterogeneity for 705 meta-analyses reported in Psychological Bulletin from 1990–2013.”
Journal of Open Psychology Data, 5(1).
doi:10.5334/jopd.33.
prior()
, prior_informed_medicine_names
# prior distribution representing expected effect sizes in social psychology # based on prior elicitation with dr. Oosterwijk p1 <- prior_informed("Oosterwijk") # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1) # empirical prior distribution for the standardized mean differences from the oral health # medical subfield based on meta-analytic effect size estimates from the # Cochrane database of systematic reviews p2 <- prior_informed("Oral Health", parameter = "effect", type = "smd") print(p2)
# prior distribution representing expected effect sizes in social psychology # based on prior elicitation with dr. Oosterwijk p1 <- prior_informed("Oosterwijk") # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1) # empirical prior distribution for the standardized mean differences from the oral health # medical subfield based on meta-analytic effect size estimates from the # Cochrane database of systematic reviews p2 <- prior_informed("Oral Health", parameter = "effect", type = "smd") print(p2)
Contain names identifying the individual subfields
from the Cochrane database of systematic reviews. The individual
elements correspond to valid name arguments for the prior_informed()
function.
prior_informed_medicine_names
prior_informed_medicine_names
An object of class character
of length 47.
prior
creates a prior distribution.
The prior can be visualized by the plot
function.
prior_none(prior_weights = 1)
prior_none(prior_weights = 1)
prior_weights |
prior odds associated with a given distribution. The value is passed into the model fitting function, which creates models corresponding to all combinations of prior distributions for each of the model parameters and sets the model priors odds to the product of its prior distributions. |
prior
and prior_none
return an object of class 'prior'.
A named list containing the distribution name, parameters, and prior weights.
plot.prior()
, Normal, Lognormal, Cauchy,
Beta, Exponential,
LocationScaleT, InvGamma.
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
# create a standard normal prior distribution p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1)) # create a half-normal standard normal prior distribution p2 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1), truncation = list(lower = 0, upper = Inf)) # the prior distribution can be visualized using the plot function # (see ?plot.prior for all options) plot(p1)
RoBSA
is used to estimate a robust Bayesian
survival analysis. The interface allows a complete customization of
the ensemble with different prior distributions for the null and
alternative hypothesis of each parameter.
(See README for an example.)
RoBSA( formula, data, priors = NULL, test_predictors = NULL, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), distributions_weights = rep(1, length(distributions)), prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = 3, sample = 5000, burnin = 2000, adapt = 500, thin = 1, parallel = FALSE, autofit = TRUE, autofit_control = set_autofit_control(), convergence_checks = set_convergence_checks(), save = "all", seed = NULL, silent = TRUE, rescale_data = FALSE, ... )
RoBSA( formula, data, priors = NULL, test_predictors = NULL, distributions = c("exp-aft", "weibull-aft", "lnorm-aft", "llogis-aft", "gamma-aft"), distributions_weights = rep(1, length(distributions)), prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = 3, sample = 5000, burnin = 2000, adapt = 500, thin = 1, parallel = FALSE, autofit = TRUE, autofit_control = set_autofit_control(), convergence_checks = set_convergence_checks(), save = "all", seed = NULL, silent = TRUE, rescale_data = FALSE, ... )
formula |
formula for the survival model |
data |
data frame containing the data |
priors |
names list of prior distributions for each
predictor. It allows users to specify both the null and alternative
hypothesis prior distributions by assigning a named list
(with |
test_predictors |
vector of predictor names
to be tested with Bayesian model-averaged testing.
Defaults to |
distributions |
distributions of parametric survival models |
distributions_weights |
prior odds for the competing distributions |
prior_beta_null |
default prior distribution for the null hypotheses of continuous predictors |
prior_beta_alt |
default prior distribution for the alternative hypotheses of continuous predictors |
prior_factor_null |
default prior distribution for the null hypotheses of categorical predictors |
prior_factor_alt |
default prior distribution for the alternative hypotheses of categorical predictors |
prior_intercept |
named list containing prior distribution for the intercepts (with names corresponding to the distributions) |
prior_aux |
named list containing prior distribution for the auxiliary parameters (with names corresponding to the distributions) |
chains |
a number of chains of the MCMC algorithm. |
sample |
a number of sampling iterations of the MCMC algorithm.
Defaults to |
burnin |
a number of burnin iterations of the MCMC algorithm.
Defaults to |
adapt |
a number of adaptation iterations of the MCMC algorithm.
Defaults to |
thin |
a thinning of the chains of the MCMC algorithm. Defaults to
|
parallel |
whether the individual models should be fitted in parallel.
Defaults to |
autofit |
whether the model should be fitted until the convergence
criteria (specified in |
autofit_control |
allows to pass autofit control settings with the
|
convergence_checks |
automatic convergence checks to assess the fitted
models, passed with |
save |
whether all models posterior distributions should be kept
after obtaining a model-averaged result. Defaults to |
seed |
a seed to be set before model fitting, marginal likelihood
computation, and posterior mixing for reproducibility of results. Defaults
to |
silent |
whether all print messages regarding the fitting process
should be suppressed. Defaults to |
rescale_data |
whether continuous predictors should be rescaled prior to
estimating the model. Defaults to |
... |
additional arguments. |
RoBSA
returns an object of class 'RoBSA'.
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) summary(fit) ## End(Not run)
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) summary(fit) ## End(Not run)
Controls settings for the autofit process of the MCMC JAGS sampler (specifies termination criteria), and values for the convergence checks.
set_autofit_control( max_Rhat = 1.05, min_ESS = 500, max_error = NULL, max_SD_error = NULL, max_time = list(time = 60, unit = "mins"), sample_extend = 1000 ) set_convergence_checks( max_Rhat = 1.05, min_ESS = 500, max_error = NULL, max_SD_error = NULL, remove_failed = FALSE, balance_probability = TRUE )
set_autofit_control( max_Rhat = 1.05, min_ESS = 500, max_error = NULL, max_SD_error = NULL, max_time = list(time = 60, unit = "mins"), sample_extend = 1000 ) set_convergence_checks( max_Rhat = 1.05, min_ESS = 500, max_error = NULL, max_SD_error = NULL, remove_failed = FALSE, balance_probability = TRUE )
max_Rhat |
maximum value of the R-hat diagnostic.
Defaults to |
min_ESS |
minimum estimated sample size.
Defaults to |
max_error |
maximum value of the MCMC error.
Defaults to |
max_SD_error |
maximum value of the proportion of MCMC error
of the estimated SD of the parameter.
Defaults to |
max_time |
list with the time and unit specifying the maximum
autofitting process per model. Passed to difftime function
(possible units are |
sample_extend |
number of samples to extend the fitting process if
the criteria are not satisfied.
Defaults to |
remove_failed |
whether models not satisfying the convergence checks should
be removed from the inference. Defaults to |
balance_probability |
whether prior model probability should be balanced
across the combinations of models with the same H0/H1 for effect / heterogeneity / bias
in the case of non-convergence. Defaults to |
set_autofit_control
returns a list of autofit control settings
and set_convergence_checks
returns a list of convergence checks settings.
A placeholder object and functions for the RoBSA package. (adapted from the runjags R package).
RoBSA.options(...) RoBSA.get_option(name)
RoBSA.options(...) RoBSA.get_option(name)
... |
named option(s) to change - for a list of available options, see details below. |
name |
the name of the option to get the current value of - for a list of available options, see details below. |
The current value of all available RoBSA options (after applying any changes specified) is returned invisibly as a named list.
summary.RoBSA
creates a numerical
summary of the RoBSA object.
## S3 method for class 'RoBSA' summary( object, type = "ensemble", conditional = FALSE, exp = FALSE, parameters = FALSE, probs = c(0.025, 0.975), logBF = FALSE, BF01 = FALSE, transform_factors = TRUE, short_name = FALSE, remove_spike_0 = FALSE, ... )
## S3 method for class 'RoBSA' summary( object, type = "ensemble", conditional = FALSE, exp = FALSE, parameters = FALSE, probs = c(0.025, 0.975), logBF = FALSE, BF01 = FALSE, transform_factors = TRUE, short_name = FALSE, remove_spike_0 = FALSE, ... )
object |
a fitted RoBSA object. |
type |
whether to show the overall RoBSA results ( |
conditional |
show the conditional estimates (assuming that the
alternative is true). Defaults to |
exp |
whether exponents of the regression estimates should be also presented |
parameters |
character vector of parameters (or a named list with of character vectors for summary and diagnostics tables) specifying the parameters (and their grouping) for the summary table |
probs |
quantiles of the posterior samples to be displayed.
Defaults to |
logBF |
show log of the BFs. Defaults to |
BF01 |
show BF in support of the null hypotheses. Defaults to
|
transform_factors |
Whether factors with orthonormal prior
distributions should be transformed to differences from the grand mean. Defaults
to |
short_name |
whether the prior distribution names should be
shortened. Defaults to |
remove_spike_0 |
whether prior distributions equal to spike
at 0 should be removed from the |
... |
additional arguments |
summary of a RoBSA object
summary.RoBSA
returns a list of tables of class 'BayesTools_table'.
See diagnostics()
for visual convergence checks of the individual models.
RoBSA()
, diagnostics()
, check_RoBSA()
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # summary can provide many details about the model summary(fit) # note that the summary function contains additional arguments # that allow to obtain a specific output, i.e, the conditional estimates # (assuming that the non-null models are true) can be obtained summary(fit, conditional = TRUE) # overview of the models and their prior and posterior probability, marginal likelihood, # and inclusion Bayes factor: summary(fit, type = "models") # and the model diagnostics overview, containing maximum R-hat and minimum ESS across parameters # but see '?diagnostics' for diagnostics plots for individual model parameters summary(fit, type = "diagnostics") # summary of individual models and their parameters can be further obtained by summary(fit, type = "individual") ## End(Not run)
## Not run: # (execution of the example takes several minutes) # example from the README (more details and explanation therein) data(cancer, package = "survival") priors <- calibrate_quartiles(median_t = 5, iq_range_t = 10, prior_sd = 0.5) df <- data.frame( time = veteran$time / 12, status = veteran$status, treatment = factor(ifelse(veteran$trt == 1, "standard", "new"), levels = c("standard", "new")), karno_scaled = veteran$karno / 100 ) RoBSA.options(check_scaling = FALSE) fit <- RoBSA( Surv(time, status) ~ treatment + karno_scaled, data = df, priors = list( treatment = prior_factor("normal", parameters = list(mean = 0.30, sd = 0.15), truncation = list(0, Inf), contrast = "treatment"), karno_scaled = prior("normal", parameters = list(mean = 0, sd = 1)) ), test_predictors = "treatment", prior_intercept = priors[["intercept"]], prior_aux = priors[["aux"]], parallel = TRUE, seed = 1 ) # summary can provide many details about the model summary(fit) # note that the summary function contains additional arguments # that allow to obtain a specific output, i.e, the conditional estimates # (assuming that the non-null models are true) can be obtained summary(fit, conditional = TRUE) # overview of the models and their prior and posterior probability, marginal likelihood, # and inclusion Bayes factor: summary(fit, type = "models") # and the model diagnostics overview, containing maximum R-hat and minimum ESS across parameters # but see '?diagnostics' for diagnostics plots for individual model parameters summary(fit, type = "diagnostics") # summary of individual models and their parameters can be further obtained by summary(fit, type = "individual") ## End(Not run)
update.RoBSA
can be used to
add an additional model to an existing "RoBSA"
object by
specifying the distribution, and either null or alternative priors
for each parameter and prior weight of the model,
change the prior weights of fitted models by specifying a vector
prior_weights
of the same length as the fitted models,
refitting models that failed to converge with updated settings of control parameters,
or changing the convergence criteria and recalculating the ensemble
results by specifying new control
argument and setting
refit_failed == FALSE
.
## S3 method for class 'RoBSA' update( object, refit_failed = TRUE, formula = NULL, priors = NULL, test_predictors = "", distribution = NULL, model_weights = 1, prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = NULL, adapt = NULL, burnin = NULL, sample = NULL, thin = NULL, autofit = NULL, parallel = NULL, autofit_control = NULL, convergence_checks = NULL, save = "all", seed = NULL, silent = TRUE, ... )
## S3 method for class 'RoBSA' update( object, refit_failed = TRUE, formula = NULL, priors = NULL, test_predictors = "", distribution = NULL, model_weights = 1, prior_beta_null = get_default_prior_beta_null(), prior_beta_alt = get_default_prior_beta_alt(), prior_factor_null = get_default_prior_factor_null(), prior_factor_alt = get_default_prior_factor_alt(), prior_intercept = get_default_prior_intercept(), prior_aux = get_default_prior_aux(), chains = NULL, adapt = NULL, burnin = NULL, sample = NULL, thin = NULL, autofit = NULL, parallel = NULL, autofit_control = NULL, convergence_checks = NULL, save = "all", seed = NULL, silent = TRUE, ... )
object |
a fitted RoBSA object |
refit_failed |
whether failed models should be refitted. Relevant only
if new priors or |
formula |
formula for the survival model |
priors |
names list of prior distributions for each
predictor. It allows users to specify both the null and alternative
hypothesis prior distributions by assigning a named list
(with |
test_predictors |
vector of predictor names
to be tested with Bayesian model-averaged testing.
Defaults to |
distribution |
a distribution of the new model. |
model_weights |
either a single value specifying prior model weight of a newly specified model using priors argument, or a vector of the same length as already fitted models to update their prior weights. |
prior_beta_null |
default prior distribution for the null hypotheses of continuous predictors |
prior_beta_alt |
default prior distribution for the alternative hypotheses of continuous predictors |
prior_factor_null |
default prior distribution for the null hypotheses of categorical predictors |
prior_factor_alt |
default prior distribution for the alternative hypotheses of categorical predictors |
prior_intercept |
named list containing prior distribution for the intercepts (with names corresponding to the distributions) |
prior_aux |
named list containing prior distribution for the auxiliary parameters (with names corresponding to the distributions) |
chains |
a number of chains of the MCMC algorithm. |
adapt |
a number of adaptation iterations of the MCMC algorithm.
Defaults to |
burnin |
a number of burnin iterations of the MCMC algorithm.
Defaults to |
sample |
a number of sampling iterations of the MCMC algorithm.
Defaults to |
thin |
a thinning of the chains of the MCMC algorithm. Defaults to
|
autofit |
whether the model should be fitted until the convergence
criteria (specified in |
parallel |
whether the individual models should be fitted in parallel.
Defaults to |
autofit_control |
allows to pass autofit control settings with the
|
convergence_checks |
automatic convergence checks to assess the fitted
models, passed with |
save |
whether all models posterior distributions should be kept
after obtaining a model-averaged result. Defaults to |
seed |
a seed to be set before model fitting, marginal likelihood
computation, and posterior mixing for reproducibility of results. Defaults
to |
silent |
whether all print messages regarding the fitting process
should be suppressed. Defaults to |
... |
additional arguments. |
See RoBSA()
for more details.
update.RoBSA
returns an object of class 'RoBSA'.
RoBSA()
, summary.RoBSA()
, prior()
, check_setup()
(log) density, hazard, and survival functions for AFT Weibull parametric family.
weibull_aft_log_density(t, eta, shape) weibull_aft_log_hazard(t, eta, shape) weibull_aft_log_survival(t, eta, shape) weibull_aft_density(t, eta, shape) weibull_aft_hazard(t, eta, shape) weibull_aft_survival(t, eta, shape) weibull_aft_mean(eta, shape) weibull_aft_sd(eta, shape) weibull_aft_r(n, eta, shape) weibull_aft_q(p, eta, shape) weibull_aft_p(q, eta, shape)
weibull_aft_log_density(t, eta, shape) weibull_aft_log_hazard(t, eta, shape) weibull_aft_log_survival(t, eta, shape) weibull_aft_density(t, eta, shape) weibull_aft_hazard(t, eta, shape) weibull_aft_survival(t, eta, shape) weibull_aft_mean(eta, shape) weibull_aft_sd(eta, shape) weibull_aft_r(n, eta, shape) weibull_aft_q(p, eta, shape) weibull_aft_p(q, eta, shape)
t |
vector of survival times |
eta |
linear predictor |
shape |
auxiliary parameter |
n |
number of observations |
p |
vector of probabilities |
q |
vector of quantiles |
weibull_aft_density
, weibull_aft_hazard
, and
weibull_aft_survival
return the density, hazard, and survival
of the specified survival distribution. The weibull_aft_log_density
,
weibull_aft_log_hazard
, weibull_aft_log_survival
return log of
the corresponding qualities. weibull_aft_mean
and weibull_aft_sd
return the mean and standard deviation of the specified survival distribution.
weibull_aft_r
, weibull_aft_q
, and weibull_aft_p
return a random
generation, quantiles, and cumulative probabilities of the specified
survival distribution.