| Title: | Bayesian Dynamic Borrowing Analysis and Simulation |
|---|---|
| Description: | Bayesian dynamic borrowing is an approach to incorporating external data to supplement a randomized, controlled trial analysis in which external data are incorporated in a dynamic way (e.g., based on similarity of outcomes); see Viele 2013 <doi:10.1002/pst.1589> for an overview. This package implements the hierarchical commensurate prior approach to dynamic borrowing as described in Hobbes 2011 <doi:10.1111/j.1541-0420.2011.01564.x>. There are three main functionalities. First, 'psborrow2' provides a user-friendly interface for applying dynamic borrowing on the study results handles the Markov Chain Monte Carlo sampling on behalf of the user. Second, 'psborrow2' provides a simulation framework to compare different borrowing parameters (e.g. full borrowing, no borrowing, dynamic borrowing) and other trial and borrowing characteristics (e.g. sample size, covariates) in a unified way. Third, 'psborrow2' provides a set of functions to generate data for simulation studies, and also allows the user to specify their own data generation process. This package is designed to use the sampling functions from 'cmdstanr' which can be installed from <https://stan-dev.r-universe.dev>. |
| Authors: | Matt Secrest [aut, cre] (ORCID: <https://orcid.org/0000-0002-0939-4902>), Isaac Gravestock [aut], Craig Gower-Page [ctb], Manoj Khanal [ctb], Mingyang Shan [ctb], Kexin Jin [ctb], Zhi Yang [ctb], Genentech, Inc. [cph, fnd] |
| Maintainer: | Matt Secrest <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.0.5.1 |
| Built: | 2026-05-18 15:43:21 UTC |
| Source: | https://github.com/Genentech/psborrow2 |
Specify column names for adjustment variables in model matrix and prior distributions for the model parameters for these covariates (i.e., betas)
add_covariates(covariates, priors)add_covariates(covariates, priors)
covariates |
character. Names of columns in the data matrix containing covariates to be adjusted for in the outcome model. Note: the external and treatment flags should not go here. |
priors |
Either a single object of class |
Object of class Covariates.
add_covariates( covariates = c("a", "b"), priors = list( "a" = prior_normal(0, 1), "b" = prior_normal(0, 2) ) )add_covariates( covariates = c("a", "b"), priors = list( "a" = prior_normal(0, 1), "b" = prior_normal(0, 2) ) )
Analysis ClassA class for defining Analysis details. Objects of class
Analysis should not be created directly but by the constructor
create_analysis_obj().
data_matrixmatrix. The data matrix, including all covariates to be adjusted for, all relevant outcome variables, and treatment arm and external control arm flags.
covariatesCovariate. Object of class Covariate as output by
the function covariate_details().
outcomeOutcome. Object of class Outcome as output by
outcome_surv_exponential(), outcome_surv_weibull_ph(), or outcome_bin_logistic().
borrowingBorrowing. Object of class Borrowing as output by
borrowing_full(), borrowing_none(), or borrowing_hierarchical_commensurate().
treatmentTreatment. Object of class Treatment as output by
treatment_details().
model_stringcharacter. The string that contains the full Stan model code to be compiled.
modelCmdStanModel. The compiled Stan model as output by cmdstanr::cmdstan_model()
ready_to_samplelogical. Is the object ready to sample?
psborrow2 object to a data frameCreates data.frame objects from various classes in psborrow2
## S3 method for class 'BaselineDataList' as.data.frame(x, ...)## S3 method for class 'BaselineDataList' as.data.frame(x, ...)
x |
object of type: BaselineDataList |
... |
Optional arguments for passed to data.frame |
A data.frame
Set parameters to generate correlated multivariate normal data for internal and external patients.
baseline_covariates( names, means_int, means_ext = means_int, covariance_int, covariance_ext = covariance_int )baseline_covariates( names, means_int, means_ext = means_int, covariance_int, covariance_ext = covariance_int )
names |
character vector of variable names. |
means_int |
numeric vector of means for internal patients. Must have same length as |
means_ext |
numeric vector of means for external patients. Must have same length as |
covariance_int |
variance-covariance matrix for generating multivariate normal for internal patients.
Must be square matrix with same number of rows and |
covariance_ext |
variance-covariance matrix for generating multivariate normal data for external patients.
Must be square matrix with same number of rows and |
BaselineObject to build simulated dataset
corr_covs <- baseline_covariates( names = c("b1", "b2"), means_int = c(5, 25), covariance_int = covariance_matrix(diag = c(1, 1), upper_tri = 0.4) )corr_covs <- baseline_covariates( names = c("b1", "b2"), means_int = c(5, 25), covariance_int = covariance_matrix(diag = c(1, 1), upper_tri = 0.4) )
Contains a generated baseline dataset for a single arm.
A BaselineDataFrame
cov_namescharacter contains the names of covariates generated from the multivariate normal distribution
meansnumeric contains the means of generating distribution for the covariates in cov_names
variancesnumeric contains the marginal variances of generating distribution for the covariates in
cov_names.
A named list of BaselineDataFrames with generated data for internal_treated/internal_control/
external_control groups
A BaselineDataList
baseline_objectSimulated covariates definitions as BaselineObject. See create_baseline_object()
BaselineObject class for data simulationBaselineObject class for data simulation
n_trt_intinteger. Number of internal treated patients
n_ctrl_intinteger. Number of internal control patients
n_ctrl_extinteger. Number of external control patients
covariateslist. List of correlated covariates objects, see baseline_covariates()
transformationslist. List of named transformation functions.
Please use prior_bernoulli() instead.
bernoulli_prior(...)bernoulli_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that bernoulli_prior() is deprecated and that
prior_bernoulli() should be used instead.
Please use prior_beta() instead.
beta_prior(...)beta_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that beta_prior() is deprecated and that
prior_beta() should be used instead.
Create an object of class SimVarBin to hold proportions of binary
variables specified in a simulation study.
bin_var( prob_internal, prob_external, mu_internal_before_bin = 0, mu_external_before_bin = 0 )bin_var( prob_internal, prob_external, mu_internal_before_bin = 0, mu_external_before_bin = 0 )
prob_internal |
numeric. Proportion for the internal arms. |
prob_external |
numeric. Proportion for the external arm. |
mu_internal_before_bin |
numeric. Mean value of the covariate before binarization
for the internal arms. The default is 0. See |
mu_external_before_bin |
numeric. Mean value of the covariate before binarization
for the external arm. The default is 0. See |
This function contains information necessary to create binary covariates
as part of a simulation study. The binary covariates are created
by binarizing multivariate normal distributions to achieve
the probabilities specified in prob_internal and prob_external. The
user may choose to change the default mean value of each variable
prior to binarization by specifying mu_internal_before_bin or
mu_external_before_bin to ensure the correct scales are used in the
covariance matrix, though the ultimate proportions will depend on
prob_internal and prob_external. The default values for
mu_internal_before_bin and mu_external_before_bin are 0, and
it is not recommended to change these without good reason.
Object of class SimVarBin.
Other simvar:
cont_var()
cv1 <- bin_var(0.50, 0.80) cv2 <- bin_var(.95, .92)cv1 <- bin_var(0.50, 0.80) cv2 <- bin_var(.95, .92)
Binary Cut-Off Transformation
binary_cutoff(name, int_cutoff, ext_cutoff)binary_cutoff(name, int_cutoff, ext_cutoff)
name |
variable to transform |
int_cutoff |
cut-off for internal patients, numeric between 0 and 1 |
ext_cutoff |
cut-off for external patients, numeric between 0 and 1 |
Transformation function to be used in create_baseline_object().
Sets quantile values larger than cut-off value to TRUE otherwise FALSE.
# Creates a simple function, where `data` is a `BaselineDataFrame`: function(data) { ext <- data$ext == 0 q <- get_quantiles(data, name) ifelse(ext, q > int_cutoff, q > ext_cutoff) }# Creates a simple function, where `data` is a `BaselineDataFrame`: function(data) { ext <- data$ext == 0 q <- get_quantiles(data, name) ifelse(ext, q > int_cutoff, q > ext_cutoff) }
BinaryOutcome classBinaryOutcome class
n_paraminteger. Number of ancillary parameters for the model to estimate.
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
binary_varcharacter. Variable used for outcome in BinaryOutcome objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
Please use one of borrowing_hierarchical_commensurate(), borrowing_none(), or borrowing_full() instead.
borrowing_details(...)borrowing_details(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that borrowing_details() is deprecated and that
one of borrowing_hierarchical_commensurate(), borrowing_none(), or
borrowing_full() should be used instead.
Fixed Power Prior Borrowing
borrowing_fixed_power_prior(ext_flag_col, power_par)borrowing_fixed_power_prior(ext_flag_col, power_par)
ext_flag_col |
character. Name of the external flag column in the matrix. |
power_par |
numeric. Fixed power parameter for all external data. Must be between 0 and 1. |
Object of class BorrowingFixedPowerPrior.
borrowing_fixed_power_prior( ext_flag_col = "ext", power_par = 0.5 )borrowing_fixed_power_prior( ext_flag_col = "ext", power_par = 0.5 )
Full borrowing
borrowing_full(ext_flag_col)borrowing_full(ext_flag_col)
ext_flag_col |
character. Name of the external flag column in the matrix. |
This method does not distinguish between internal and external arms, effectively pooling patients.
The ext_flag_col argument refers to the column in the data matrix that
contains the flag indicating a patient is from the external control cohort.
Object of class BorrowingFull.
Other borrowing:
borrowing_none()
fb <- borrowing_full("ext")fb <- borrowing_full("ext")
Hierarchical commensurate borrowing
borrowing_hierarchical_commensurate(ext_flag_col, tau_prior)borrowing_hierarchical_commensurate(ext_flag_col, tau_prior)
ext_flag_col |
character. Name of the external flag column in the matrix. |
tau_prior |
Prior. Prior for the commensurability parameter. |
In Bayesian dynamic borrowing using the hierarchical commensurate prior approach, external control information is borrowed to the extent that the outcomes (i.e., log hazard rates or log odds) are similar between external and internal control populations. See Viele 2014 doi:10.1002/pst.1589 and Hobbs 2011 doi:10.1111/j.1541-0420.2011.01564.x for details.
The ext_flag_col argument refers to the column in the data matrix that
contains the flag indicating a patient is from the external control cohort.
The tau_prior argument specifies the hyperprior on the precision parameter
commonly referred to as the commensurability parameter.
See Viele 2014 doi:10.1002/pst.1589 for more
details.
This hyperprior determines (along with the comparability of the outcomes
between internal and external controls) how much borrowing of the external
control group will be performed.
Example hyperpriors include largely uninformative inverse gamma distributions
[e.g., prior_gamma(alpha = .001, beta = .001)] as well as more
informative distributions [e.g., prior_gamma(alpha = 1, beta = .001)],
though any distribution can be used. Distributions
with more density at higher values of (i.e., higher precision)
will lead to more borrowing.
Object of class BorrowingHierarchicalCommensurate.
Viele, K., Berry, S., Neuenschwander, B., Amzal, B., Chen, F., Enas, N., Hobbs, B., Ibrahim, J.G., Kinnersley, N., Lindborg, S., Micallef, S., Roychoudhury, S. and Thompson, L. (2014), Use of historical control data for assessing treatment effects in clinical trials. Pharmaceut. Statist., 13: 41–54. doi:10.1002/pst.1589
Hobbes, B.P., Carlin, B.P., Mandrekar, S.J. and Sargent, D.J. (2011), Hierarchical commensurate and power prior models for adaptive incorporation of historical information in clinical trials. Biometrics, 67: 1047–1056. doi:10.1111/j.1541-0420.2011.01564.x
db <- borrowing_hierarchical_commensurate( ext_flag_col = "ext", tau_prior = prior_gamma(0.0001, 0.0001) )db <- borrowing_hierarchical_commensurate( ext_flag_col = "ext", tau_prior = prior_gamma(0.0001, 0.0001) )
No borrowing
borrowing_none(ext_flag_col)borrowing_none(ext_flag_col)
ext_flag_col |
character. Name of the external flag column in the matrix. |
This method evaluates only the internal comparison,
ignoring historical controls. Note that this method will filter the
model matrix based on values in ext_flag_col.
The ext_flag_col argument refers to the column in the data matrix that
contains the flag indicating a patient is from the external control cohort.
Object of class BorrowingNone.
Other borrowing:
borrowing_full()
db <- borrowing_none( ext_flag_col = "ext" )db <- borrowing_none( ext_flag_col = "ext" )
Borrowing ClassA class for defining borrowing details. Objects of class
Borrowing should not be created directly but by the constructors
borrowing_hierarchical_commensurate(), borrowing_none(), borrowing_full().
method_namestring. The name of the method.
ext_flag_colcharacter. Name of the external flag column in the matrix.
Prior constructor functions: borrowing_full(), borrowing_hierarchical_commensurate(), borrowing_none()
Other borrowing classes:
BorrowingFixedPowerPrior-class,
BorrowingFull-class,
BorrowingHierarchicalCommensurate-class,
BorrowingNone-class
BorrowingFixedPowerPrior classBorrowingFixedPowerPrior class
method_namestring. The name of the method.
ext_flag_colcharacter. Name of the external flag column in the matrix.
powersnumeric. The fixed values to be used as the powers in the power prior.
Other borrowing classes:
Borrowing-class,
BorrowingFull-class,
BorrowingHierarchicalCommensurate-class,
BorrowingNone-class
BorrowingFull classA class for defining details for "Full Borrowing" methods.
Objects of class BorrowingFull
should not be created directly but by the constructor
borrowing_full().
method_namestring. The name of the method.
ext_flag_colcharacter. Name of the external flag column in the matrix.
name_taunamed vector for hierarchical commensurability parameter hyperprior.
Other borrowing classes:
Borrowing-class,
BorrowingFixedPowerPrior-class,
BorrowingHierarchicalCommensurate-class,
BorrowingNone-class
BorrowingHierarchicalCommensurate classA class for defining details of dynamic borrowing
using the hierarchical Bayesian model with a commensurability
parameter. Objects of class BorrowingHierarchicalCommensurate
should not be created directly but by the constructor
borrowing_hierarchical_commensurate().
method_namestring. The name of the method.
ext_flag_colcharacter. Name of the external flag column in the matrix.
tau_priorPrior. Prior for the commensurability parameter.
Other borrowing classes:
Borrowing-class,
BorrowingFixedPowerPrior-class,
BorrowingFull-class,
BorrowingNone-class
BorrowingNone classA class for defining details for "No borrowing" methods.
Objects of class BorrowingNone
should not be created directly but by the constructor
borrowing_none().
method_namestring. The name of the method.
ext_flag_colcharacter. Name of the external flag column in the matrix.
Other borrowing classes:
Borrowing-class,
BorrowingFixedPowerPrior-class,
BorrowingFull-class,
BorrowingHierarchicalCommensurate-class
Build the model string by interpolating the Stan template
build_model_string( template_domain, template_filename, outcome, borrowing, analysis_obj, ... )build_model_string( template_domain, template_filename, outcome, borrowing, analysis_obj, ... )
template_domain |
Character string specifying the domain of the template (e.g., "surv", "bin", "cont") |
template_filename |
Character string specifying the filename of the Stan template |
outcome |
|
borrowing |
|
analysis_obj |
|
... |
Additional named arguments to be passed for interpolation |
String containing the interpolated Stan model
psborrow2
Creates data.frame objects from various classes in psborrow2
## S4 method for signature 'SimDataList' c(x, ...)## S4 method for signature 'SimDataList' c(x, ...)
x |
object of type: SimDataList |
... |
additional objects to combine |
A combined object
list of SimDataList objects.
Please use prior_cauchy() instead.
cauchy_prior(...)cauchy_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that cauchy_prior() is deprecated and that
prior_cauchy() should be used instead.
Check whether cmdstanr is available and prints version and logistic example.
check_cmdstanr(check_sampling = FALSE) check_cmdstan()check_cmdstanr(check_sampling = FALSE) check_cmdstan()
check_sampling |
Compile and sample from the "logistic" example model. |
check_cmdstanr() prints results from checks.
check_cmdstan() returns TRUE if CmdStan seems to be installed, otherwise FALSE
check_cmdstan(): Check if the CmdStan command line tools are available.
check_cmdstanr()check_cmdstanr()
Check that an Analysis object's data_matrix has all the required variables.
check_data_matrix_has_columns(object)check_data_matrix_has_columns(object)
object |
|
stop() if some columns are missing.
anls <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ) ) check_data_matrix_has_columns(anls)anls <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ) ) check_data_matrix_has_columns(anls)
Create a Fixed External Data Object
check_fixed_external_data(data, req_cols)check_fixed_external_data(data, req_cols)
data |
A |
req_cols |
A |
A DataSimObject with updated enrollment_internal and enrollment_external slots.
Create an object of class SimVarCont to hold mean values of
of continuous variables specified in a simulation study.
cont_var(mu_internal, mu_external)cont_var(mu_internal, mu_external)
mu_internal |
numeric. Mean covariate value for the internal arms. |
mu_external |
numeric. Mean covariate value for the external arm. |
Object of class SimVarCont.
Other simvar:
bin_var()
cv1 <- cont_var(0.5, 1) cv2 <- cont_var(10, 10)cv1 <- cont_var(0.5, 1) cv2 <- cont_var(10, 10)
ContinuousOutcome classContinuousOutcome class
n_paraminteger. Number of ancillary parameters for the model to estimate.
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
continuous_varcharacter. Variable used for outcome in ContinuousOutcome objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
Create Covariance Matrix
covariance_matrix(diag, upper_tri)covariance_matrix(diag, upper_tri)
diag |
Diagonal entries of the covariance matrix |
upper_tri |
Upper triangle entries of the matrix, specified column wise. |
A symmetric matrix with diag values on the main diagonal and
upper_tri values in the lower and upper triangles.
m1 <- covariance_matrix(c(1, 1, 1, 1), c(.8, .3, .8, 0, 0, 0)) m1 mvtnorm::rmvnorm(5, mean = c(0, 0, 0, 0), sigma = m1) # No correlation covariance_matrix(c(1, 2, 3))m1 <- covariance_matrix(c(1, 1, 1, 1), c(.8, .3, .8, 0, 0, 0)) m1 mvtnorm::rmvnorm(5, mean = c(0, 0, 0, 0), sigma = m1) # No correlation covariance_matrix(c(1, 2, 3))
Covariate ClassA class for defining covariate details. Objects of class
Covariate should not be created directly but by the constructor
add_covariates().
covariatescharacter. Names of columns in the data matrix containing covariates to be adjusted for in the outcome model. Note: the external and treatment flags should not go here.
priors.Either a single object of class Prior specifying the prior
distribution to apply to all covariates or a named list of
distributions of class Prior, one for each covariate
name_betas.Names for the beta parameters in the STAN model.
Create alpha string
create_alpha_string(borrowing_object, outcome_object) ## S4 method for signature 'Borrowing' create_alpha_string(borrowing_object, outcome_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' create_alpha_string(borrowing_object, outcome_object)create_alpha_string(borrowing_object, outcome_object) ## S4 method for signature 'Borrowing' create_alpha_string(borrowing_object, outcome_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' create_alpha_string(borrowing_object, outcome_object)
borrowing_object |
borrowing object |
outcome_object |
outcome object |
Compile MCMC sampler using STAN and create analysis object
create_analysis_obj( data_matrix, outcome, borrowing, treatment, covariates = NULL, quiet = FALSE )create_analysis_obj( data_matrix, outcome, borrowing, treatment, covariates = NULL, quiet = FALSE )
data_matrix |
matrix. The data matrix, including all covariates to be adjusted for, all relevant outcome variables, and treatment arm and external control arm flags. |
outcome |
|
borrowing |
|
treatment |
|
covariates |
|
quiet |
logical. Whether to suppress messages ( |
Object of class Analysis.
if (check_cmdstan()) { anls <- create_analysis_obj( data_matrix = example_matrix, outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ), covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ) ) }if (check_cmdstan()) { anls <- create_analysis_obj( data_matrix = example_matrix, outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ), covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ) ) }
Create Baseline Data Simulation Object
create_baseline_object( n_trt_int, n_ctrl_int, n_ctrl_ext, covariates, transformations )create_baseline_object( n_trt_int, n_ctrl_int, n_ctrl_ext, covariates, transformations )
n_trt_int |
Number of internal treated patients |
n_ctrl_int |
Number of internal control patients |
n_ctrl_ext |
Number of external control patients |
covariates |
List of correlated covariates objects, see |
transformations |
List of named transformation functions. |
Transformation functions are evaluated in order and create or overwrite a column
in the data.frame with that name. The function should take a data.frame (specifically
a BaselineDataFrame object from generate(BaselineObject)) and return a vector with
length identical to the total number of patients.
The @BaselineObject slot may be accessed directly or with get_quantiles() to
create transformations. See binary_cutoff()
bl_no_covs <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100 ) bl_biomarkers <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100, covariates = baseline_covariates( c("b1", "b2", "b3"), means_int = c(0, 0, 0), covariance_int = covariance_matrix(c(1, 1, 1), c(.8, .3, .8)) ), transformations = list( exp_b1 = function(data) exp(data$b1), b2 = binary_cutoff("b2", int_cutoff = 0.7, ext_cutoff = 0.5) ) )bl_no_covs <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100 ) bl_biomarkers <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100, covariates = baseline_covariates( c("b1", "b2", "b3"), means_int = c(0, 0, 0), covariance_int = covariance_matrix(c(1, 1, 1), c(.8, .3, .8)) ), transformations = list( exp_b1 = function(data) exp(data$b1), b2 = binary_cutoff("b2", int_cutoff = 0.7, ext_cutoff = 0.5) ) )
Creates a matrix suitable for create_analysis_obj(). Creates dummy variables for factors and
allows transformations of covariates specified with a formula.
create_data_matrix( data, outcome, trt_flag_col, ext_flag_col, covariates = NULL, weight_var = NULL )create_data_matrix( data, outcome, trt_flag_col, ext_flag_col, covariates = NULL, weight_var = NULL )
data |
data.frame. Data containing all variables |
outcome |
character. The outcome variable for binary outcomes or the time and censoring variables. |
trt_flag_col |
character. The treatment indicator variable. |
ext_flag_col |
character. The external cohort indicator. |
covariates |
character or formula. The covariates for model adjustment. |
weight_var |
character. An optional weight variable. |
Invisibly returns a matrix containing all variables to pass to create_analysis_obj().
Prints names of covariates columns to use with add_covariates().
dat <- survival::diabetic dat$ext <- dat$trt == 0 & dat$id > 1000 data_mat <- create_data_matrix( dat, outcome = c("time", "status"), trt_flag_col = "trt", ext_flag_col = "ext", covariates = ~ age + laser + log(risk) ) data_matdat <- survival::diabetic dat$ext <- dat$trt == 0 & dat$id > 1000 data_mat <- create_data_matrix( dat, outcome = c("time", "status"), trt_flag_col = "trt", ext_flag_col = "ext", covariates = ~ age + laser + log(risk) ) data_mat
Data Simulation
create_data_simulation( baseline, coefficients = numeric(), treatment_hr = 1, drift_hr = 1, event_dist, fixed_external_data )create_data_simulation( baseline, coefficients = numeric(), treatment_hr = 1, drift_hr = 1, event_dist, fixed_external_data )
baseline |
|
coefficients |
Named vector of coefficients for linear predictor. Must correspond to variables in baseline object |
treatment_hr |
Default treatment hazard ratio for simulations. Alternative simulation settings can be specified in generate. |
drift_hr |
Default drift hazard ratio between internal and external arms. Alternative simulation settings can be specified in generate. |
event_dist |
Specify time to event distribution with |
fixed_external_data |
A |
DataSimObject
baseline_obj <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 10, covariates = baseline_covariates( names = c("age", "score"), means_int = c(55, 5), means_ext = c(60, 5), covariance_int = covariance_matrix(c(5, 1)) ) ) sim_obj <- create_data_simulation( baseline_obj, coefficients = c(age = 0.001, score = 1.5), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) data_sim_list <- generate(sim_obj, treatment_hr = c(0.5, 1), drift_hr = 0.5)baseline_obj <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 10, covariates = baseline_covariates( names = c("age", "score"), means_int = c(55, 5), means_ext = c(60, 5), covariance_int = covariance_matrix(c(5, 1)) ) ) sim_obj <- create_data_simulation( baseline_obj, coefficients = c(age = 0.001, score = 1.5), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) data_sim_list <- generate(sim_obj, treatment_hr = c(0.5, 1), drift_hr = 0.5)
Uses simsurv::simsurv to generate time to event data. See simsurv help for more details.
create_event_dist( dist = NULL, lambdas = NULL, gammas = NULL, mixture = FALSE, pmix = 0.5, hazard = NULL, loghazard = NULL, cumhazard = NULL, logcumhazard = NULL, ... ) null_event_dist()create_event_dist( dist = NULL, lambdas = NULL, gammas = NULL, mixture = FALSE, pmix = 0.5, hazard = NULL, loghazard = NULL, cumhazard = NULL, logcumhazard = NULL, ... ) null_event_dist()
dist |
Specify the distribution |
lambdas |
Scale parameter |
gammas |
Second parameter needed for Weibull or Gompertz distributions |
mixture |
Use mixture model? |
pmix |
Proportion of mixtures |
hazard |
A user defined hazard function |
loghazard |
Alternatively, a user defined log hazard function |
cumhazard |
Alternatively, a user defined cumulative hazard function |
logcumhazard |
Alternatively, a user defined log cumulative hazard function |
... |
Other |
A SimDataEvent object
null_event_dist returns an object with no parameters specified that does not simulate event times.
weibull_surv <- create_event_dist(dist = "weibull", lambdas = 1 / 200, gammas = 1) exp_event_dist <- create_event_dist(dist = "exponential", lambdas = 1 / 36) null_event_dist()weibull_surv <- create_event_dist(dist = "weibull", lambdas = 1 / 200, gammas = 1) exp_event_dist <- create_event_dist(dist = "exponential", lambdas = 1 / 36) null_event_dist()
Compile MCMC sampler using STAN and create simulation object
create_simulation_obj( data_matrix_list, covariate = NULL, outcome, borrowing, treatment, quiet = TRUE )create_simulation_obj( data_matrix_list, covariate = NULL, outcome, borrowing, treatment, quiet = TRUE )
data_matrix_list |
|
covariate |
|
outcome |
|
borrowing |
|
treatment |
|
quiet |
logical. Whether to print messages ( |
Object of class Simulation.
base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), index = 1:2 ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "index" ) if (check_cmdstan()) { sim_object <- create_simulation_obj( data_matrix_list = sdl, outcome = outcome_bin_logistic("ep", prior_normal(0, 1000)), borrowing = sim_borrowing_list(list( full_borrowing = borrowing_full("ext"), bdb = borrowing_hierarchical_commensurate("ext", prior_exponential(0.0001)) )), treatment = treatment_details("trt", prior_normal(0, 1000)) ) }base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), index = 1:2 ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "index" ) if (check_cmdstan()) { sim_object <- create_simulation_obj( data_matrix_list = sdl, outcome = outcome_bin_logistic("ep", prior_normal(0, 1000)), borrowing = sim_borrowing_list(list( full_borrowing = borrowing_full("ext"), bdb = borrowing_hierarchical_commensurate("ext", prior_exponential(0.0001)) )), treatment = treatment_details("trt", prior_normal(0, 1000)) ) }
Create tau string
create_tau_string(borrowing_object) ## S4 method for signature 'Borrowing' create_tau_string(borrowing_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' create_tau_string(borrowing_object)create_tau_string(borrowing_object) ## S4 method for signature 'Borrowing' create_tau_string(borrowing_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' create_tau_string(borrowing_object)
borrowing_object |
borrowing object |
DataSimEnrollment ObjectCreate a DataSimEnrollment Object
custom_enrollment(fun, label)custom_enrollment(fun, label)
fun |
A function that takes one argument |
label |
A user-friendly label |
A DataSimEnrollment object
custom_enrollment( fun = function(n) rpois(n, lambda = 5), label = "Poisson enrollment distribution" )custom_enrollment( fun = function(n) rpois(n, lambda = 5), label = "Poisson enrollment distribution" )
Cut Off Functions
cut_off_none() cut_off_after_first(time) cut_off_after_last(time) cut_off_after_events(n)cut_off_none() cut_off_after_first(time) cut_off_after_last(time) cut_off_after_events(n)
time |
Time to cut off |
n |
Number of events |
A DataSimCutOff object containing a cut-off function
cut_off_none(): No cut off is specified
cut_off_after_first(): Cut off at time after first enrolled patient
cut_off_after_last(): Cut off at time after last enrolled patient
cut_off_after_events(): Cut off after the time of the n-th event
cut_off_none() cut_off_after_first(time = 36) cut_off_after_last(time = 36) cut_off_after_events(n = 20)cut_off_none() cut_off_after_first(time = 36) cut_off_after_last(time = 36) cut_off_after_events(n = 20)
Cut Off Object
cut_off_funA function that takes a data.frame with columns of enrollment time, survival time and outcome.
The function returns a modified data.frame after applied the cut-off rule.
Enrollment Object
funA function that takes one argument n the number of enrollment times to observe and returns a
vector of times.
labelA user-friendly label
Event Time Distribution Object
paramsParameters used for simulating event times with simsurv::simsurv().
labelDescription of the distribution.
Fixed External Control Data Object
A FixedExternalData
datadata.frame containing external control data
nNumber of observations
Data Simulation Object Class
A DataSimObject
baselineBaselineObject from create_baseline_object
coefficientsNamed numeric vector of beta coefficients for survival model. See beta at
?simsurv::simsurv
treatment_hrnumeric treatment effect as a hazard ration. log(treatment_hr) is included in beta with
coefficients and log(drift_hr). This default is overridden by generate
arguments
drift_hrnumeric hazard ratio between internal and external arms. Included as log(drift_hr).
fixed_external_datadata.frame for external data. Currently unused.
event_distDataSimEvent parameters for outcome distribution from create_event_dist()
enrollmentDataSimEnrollment object.
cut_offDataSimCutOff
Constant Enrollment Rates
enrollment_constant(rate, for_time = rep(1, length(rate)))enrollment_constant(rate, for_time = rep(1, length(rate)))
rate |
Number of patients to enroll per unit time |
for_time |
Number of time periods for each rate. Must be equal length to |
An object of class DataSimEnrollment to be passed to create_data_simulation()
# 10 patients/month for 6 months, then 5/month for 6 months enroll_obj <- enrollment_constant(rate = c(10, 5), for_time = c(6, 6)) enroll_obj@fun(n = 80)# 10 patients/month for 6 months, then 5/month for 6 months enroll_obj <- enrollment_constant(rate = c(10, 5), for_time = c(6, 6)) enroll_obj@fun(n = 80)
Evaluate constraints when these are called
eval_constraints(object) ## S4 method for signature 'Prior' eval_constraints(object)eval_constraints(object) ## S4 method for signature 'Prior' eval_constraints(object)
object |
|
A matrix containing data from a clinical trial with a treatment arm and a control arm, as well as data from an external control. In this simulated dataset, the true hazard ratio (HR) for the time-to-event endpoint comparing the experimental treatment to the control treatment is 0.70. The true odds ratio (OR) for the binary response endpoint comparing the experimental treatment to the control treatment is 1.20.
example_matrixexample_matrix
A data frame with 500 rows and 11 columns. The distributions of patients is: 50 internal control patients, 100 internal experimental patients, 350 external control patients.
patient identifier
0/1, flag for external controls
0/1, flag for treatment arm
0/1, baseline covariate
0/1, baseline covariate
0/1, baseline covariate
0/1, baseline covariate
numeric >0, survival time
0/1, indicator for event status (1 = had event, 0 = did not have event)
0/1, censoring indicator (1 = was censored, 0 = was not censored)
. This value is 1 - status.
0/1, indicator for response outcome (1 = had a response, 0 = did not have a response)
A data frame containing simulated data from a clinical trial with a treatment arm (n=200) and a control arm (n=158), as well as data from an external control (n=242).
example_survexample_surv
A data frame with 600 rows and 6 variables:
0/1, flag for treatment arm
0/1, flag for external controls
numeric >0, survival time
0/1, event indicator
0/1, censoring indicator
0/1, binary baseline covariate 1
integer in [0, 15], baseline covariate 2
continuous numeric, baseline covariate 3
Please use outcome_surv_exponential() instead.
exp_surv_dist(...)exp_surv_dist(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that exp_surv_dist() is deprecated and that
outcome_surv_exponential() should be used instead.
Please use prior_exponential() instead.
exponential_prior(...)exponential_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that exponential_prior() is deprecated and that
prior_exponential() should be used instead.
Please use prior_gamma() instead.
gamma_prior(...)gamma_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that gamma_prior() is deprecated and that
prior_gamma() should be used instead.
Generate Data from Object
generate(x, ...)generate(x, ...)
x |
object |
... |
Other arguments passed to methods |
Object of class SimDataList.
BaselineObject
Generate Data for a BaselineObject
## S4 method for signature 'BaselineObject' generate(x, ...)## S4 method for signature 'BaselineObject' generate(x, ...)
x |
a |
... |
additional parameters are ignored |
A BaselineDataFrame object
bl_biomarkers <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100, covariates = baseline_covariates( c("b1", "b2", "b3"), means_int = c(0, 0, 0), covariance_int = covariance_matrix(c(1, 1, 1), c(.8, .3, .8)) ), transformations = list( exp_b1 = function(data) exp(data$b1), b2 = binary_cutoff("b2", int_cutoff = 0.7, ext_cutoff = 0.5) ) ) generate(bl_biomarkers)bl_biomarkers <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 100, covariates = baseline_covariates( c("b1", "b2", "b3"), means_int = c(0, 0, 0), covariance_int = covariance_matrix(c(1, 1, 1), c(.8, .3, .8)) ), transformations = list( exp_b1 = function(data) exp(data$b1), b2 = binary_cutoff("b2", int_cutoff = 0.7, ext_cutoff = 0.5) ) ) generate(bl_biomarkers)
DataSimObject
Generate Data for a DataSimObject
## S4 method for signature 'DataSimObject' generate(x, n = 1, treatment_hr = NULL, drift_hr = NULL)## S4 method for signature 'DataSimObject' generate(x, n = 1, treatment_hr = NULL, drift_hr = NULL)
x |
a |
n |
number of data sets to simulate |
treatment_hr |
vector of numeric treatment effects |
drift_hr |
vector of numeric drift effects |
A SimDataList object for use with create_simulation_obj().
baseline_obj <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 10, covariates = baseline_covariates( names = c("age", "score"), means_int = c(55, 5), means_ext = c(60, 5), covariance_int = covariance_matrix(c(5, 1)) ) ) sim_obj <- create_data_simulation( baseline_obj, coefficients = c(age = 0.001, score = 1.5), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) data_sim_list <- generate(sim_obj, treatment_hr = c(0, 1), drift_hr = 0.5)baseline_obj <- create_baseline_object( n_trt_int = 100, n_ctrl_int = 50, n_ctrl_ext = 10, covariates = baseline_covariates( names = c("age", "score"), means_int = c(55, 5), means_ext = c(60, 5), covariance_int = covariance_matrix(c(5, 1)) ) ) sim_obj <- create_data_simulation( baseline_obj, coefficients = c(age = 0.001, score = 1.5), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) data_sim_list <- generate(sim_obj, treatment_hr = c(0, 1), drift_hr = 0.5)
CmdStanModel objects for MCMCSimulationResults
Show the CmdStanModel objects from MCMCSimulationResults objects.
get_cmd_stan_models(object) ## S4 method for signature 'MCMCSimulationResult' get_cmd_stan_models(object)get_cmd_stan_models(object) ## S4 method for signature 'MCMCSimulationResult' get_cmd_stan_models(object)
object |
|
List of lists of CmdStanModel objects for each model.
SimDataList objectRetrieves the simulated data from a SimDataList object by index.
get_data(object, index = 1, dataset = 1) ## S4 method for signature 'SimDataList' get_data(object, index = NULL, dataset = NULL)get_data(object, index = 1, dataset = 1) ## S4 method for signature 'SimDataList' get_data(object, index = NULL, dataset = NULL)
object |
|
index |
the index of the scenario (see guide with print( |
dataset |
the dataset out of |
Simulated data as a data frame if the index is specified, else as a list
Get prior string for all covariates
get_prior_string_covariates(covariates)get_prior_string_covariates(covariates)
covariates |
|
Helper for use within transformation functions for create_baseline_object().
get_quantiles(object, var)get_quantiles(object, var)
object |
a |
var |
character string name of the variable |
A numeric vector containing quantiles based on the data generating distribution.
MCMCSimulationResults objectsGet the results data.frame from MCMCSimulationResults objects.
get_results(object) ## S4 method for signature 'MCMCSimulationResult' get_results(object)get_results(object) ## S4 method for signature 'MCMCSimulationResult' get_results(object)
object |
|
data.frame with simulation results.
Get method for Stan model
get_stan_code(object) ## S4 method for signature 'Analysis' get_stan_code(object)get_stan_code(object) ## S4 method for signature 'Analysis' get_stan_code(object)
object |
|
String containing the Stan model
Gets the data variable names from an object.
get_vars(object) ## S4 method for signature 'Covariates' get_vars(object) ## S4 method for signature 'Treatment' get_vars(object) ## S4 method for signature 'Borrowing' get_vars(object) ## S4 method for signature 'TimeToEvent' get_vars(object) ## S4 method for signature 'BinaryOutcome' get_vars(object) ## S4 method for signature 'ContinuousOutcome' get_vars(object) ## S4 method for signature 'Analysis' get_vars(object) ## S4 method for signature 'NULL' get_vars(object) ## S4 method for signature 'BorrowingFixedPowerPrior' get_vars(object) ## S4 method for signature 'SimTreatmentList' get_vars(object) ## S4 method for signature 'SimOutcomeList' get_vars(object) ## S4 method for signature 'SimBorrowingList' get_vars(object) ## S4 method for signature 'SimCovariateList' get_vars(object) ## S4 method for signature 'Simulation' get_vars(object) ## S4 method for signature 'BaselineObject' get_vars(object)get_vars(object) ## S4 method for signature 'Covariates' get_vars(object) ## S4 method for signature 'Treatment' get_vars(object) ## S4 method for signature 'Borrowing' get_vars(object) ## S4 method for signature 'TimeToEvent' get_vars(object) ## S4 method for signature 'BinaryOutcome' get_vars(object) ## S4 method for signature 'ContinuousOutcome' get_vars(object) ## S4 method for signature 'Analysis' get_vars(object) ## S4 method for signature 'NULL' get_vars(object) ## S4 method for signature 'BorrowingFixedPowerPrior' get_vars(object) ## S4 method for signature 'SimTreatmentList' get_vars(object) ## S4 method for signature 'SimOutcomeList' get_vars(object) ## S4 method for signature 'SimBorrowingList' get_vars(object) ## S4 method for signature 'SimCovariateList' get_vars(object) ## S4 method for signature 'Simulation' get_vars(object) ## S4 method for signature 'BaselineObject' get_vars(object)
object |
Object |
A character vector containing variable names
get_vars(treatment_details( trt_flag_col = "treat_fl", trt_prior = prior_normal(0, 1000) ))get_vars(treatment_details( trt_flag_col = "treat_fl", trt_prior = prior_normal(0, 1000) ))
Please use prior_half_cauchy() instead.
half_cauchy_prior(...)half_cauchy_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that half_cauchy_prior() is deprecated and that
prior_half_cauchy() should be used instead.
Please use prior_half_normal() instead.
half_normal_prior(...)half_normal_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that half_normal_prior() is deprecated and that
prior_half_normal() should be used instead.
Load and interpolate Stan model
load_and_interpolate_stan_model(outcome, borrowing, analysis_obj)load_and_interpolate_stan_model(outcome, borrowing, analysis_obj)
outcome |
|
borrowing |
|
analysis_obj |
|
String containing the interpolated Stan model
psborrow2 templateThis function loads a Stan template file from the package's 'inst/stan' directory.
load_stan_file(...)load_stan_file(...)
... |
subdirectories |
template string
Please use outcome_bin_logistic() instead.
logistic_bin_outcome(...)logistic_bin_outcome(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that logistic_bin_outcome() is deprecated and that
outcome_bin_logistic() should be used instead.
Method to sample from compiled Stan model and
return a CmdStanMCMC object with draws.
mcmc_sample(x, ...) ## S4 method for signature 'ANY' mcmc_sample(x, ...) ## S4 method for signature 'Analysis' mcmc_sample( x, iter_warmup = 1000L, iter_sampling = 10000L, chains = 4L, verbose = FALSE, ... ) ## S4 method for signature 'Simulation' mcmc_sample( x, posterior_quantiles = c(0.025, 0.975), iter_warmup = 1000L, iter_sampling = 10000L, chains = 4L, verbose = FALSE, keep_cmd_stan_models = FALSE, ... )mcmc_sample(x, ...) ## S4 method for signature 'ANY' mcmc_sample(x, ...) ## S4 method for signature 'Analysis' mcmc_sample( x, iter_warmup = 1000L, iter_sampling = 10000L, chains = 4L, verbose = FALSE, ... ) ## S4 method for signature 'Simulation' mcmc_sample( x, posterior_quantiles = c(0.025, 0.975), iter_warmup = 1000L, iter_sampling = 10000L, chains = 4L, verbose = FALSE, keep_cmd_stan_models = FALSE, ... )
x |
object to sample, such as |
... |
additional arguments passed to the $sample() method of a
|
iter_warmup |
integer. The number of warm up iterations to run per chain. The default is 1000. |
iter_sampling |
integer. The number of post-warm up iterations to run per chain. The default is 10000. |
chains |
integer. The number of Markov chains to run. The default is 4. |
verbose |
logical. Whether to print sampler updates ( |
posterior_quantiles |
numeric vector of length two.
The posterior quantiles used for summarizing simulation results. The
default is |
keep_cmd_stan_models |
logical. Whether to keep the
|
This function takes draws from an MCMC sampler and summarizes results.
An object of class CmdStanMCMC
An object of class MCMCSimulationResult
## Analysis objects if (check_cmdstan()) { anls <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_weibull_ph( "time", "cnsr", shape_prior = prior_normal(0, 1000), baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details("trt", prior_normal(0, 1000)) ) mcmc_results <- mcmc_sample(anls, chains = 1, iter_warmup = 500L, iter_sampling = 1000L) } ## Simulation objects base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), index = 1:2 ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "index" ) if (check_cmdstan()) { sim_object <- create_simulation_obj( data_matrix_list = sdl, outcome = outcome_bin_logistic("ep", prior_normal(0, 1000)), borrowing = sim_borrowing_list(list( full_borrowing = borrowing_full("ext"), bdb = borrowing_hierarchical_commensurate("ext", prior_exponential(0.0001)) )), treatment = treatment_details("trt", prior_normal(0, 1000)) ) mcmc_sample(sim_object, chains = 1, iter_warmup = 500L, iter_sampling = 1000L) } ## Not run: library(future) # Use two separate R processes plan("multisession", workers = 2) # and two parallel threads in each. mcmc_sample(sim_object, chains = 1, iter_warmup = 500L, iter_sampling = 1000L, parallel_chains = 2) # Tidy up processes when finished plan("sequential") ## End(Not run)## Analysis objects if (check_cmdstan()) { anls <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_weibull_ph( "time", "cnsr", shape_prior = prior_normal(0, 1000), baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details("trt", prior_normal(0, 1000)) ) mcmc_results <- mcmc_sample(anls, chains = 1, iter_warmup = 500L, iter_sampling = 1000L) } ## Simulation objects base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), index = 1:2 ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "index" ) if (check_cmdstan()) { sim_object <- create_simulation_obj( data_matrix_list = sdl, outcome = outcome_bin_logistic("ep", prior_normal(0, 1000)), borrowing = sim_borrowing_list(list( full_borrowing = borrowing_full("ext"), bdb = borrowing_hierarchical_commensurate("ext", prior_exponential(0.0001)) )), treatment = treatment_details("trt", prior_normal(0, 1000)) ) mcmc_sample(sim_object, chains = 1, iter_warmup = 500L, iter_sampling = 1000L) } ## Not run: library(future) # Use two separate R processes plan("multisession", workers = 2) # and two parallel threads in each. mcmc_sample(sim_object, chains = 1, iter_warmup = 500L, iter_sampling = 1000L, parallel_chains = 2) # Tidy up processes when finished plan("sequential") ## End(Not run)
MCMCSimulationResult ClassA class for defining Simulation study results. Objects of class
MCMCSimulationResult should not be created directly but by
mcmc_sample().
resultsdata.frame. The results of the simulation study summarized
in a data.frame
cmd_stan_modelslist. List of lists of CmdStanmodels corresponding to the
different parameters in Simulation@guide and different datasets in
Simulation@data_matrix_list.
Please use prior_normal() instead.
normal_prior(...)normal_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that normal_prior() is deprecated and that
prior_normal() should be used instead.
Bernoulli distribution with logit parametrization
outcome_bin_logistic(binary_var, baseline_prior, weight_var = "")outcome_bin_logistic(binary_var, baseline_prior, weight_var = "")
binary_var |
character. Name of binary (1/0 or TRUE/FALSE) outcome variable in the model matrix |
baseline_prior |
|
weight_var |
character. Optional name of variable in model matrix for weighting the log likelihood. |
The baseline_prior argument specifies the prior distribution for the
baseline log odds. The interpretation of the baseline_prior differs
slightly between borrowing methods selected.
Dynamic borrowing using borrowing_hierarchical_commensurate():
the baseline_prior for Bayesian Dynamic Borrowing refers
to the log odds of the external control arm.
Full borrowing or No borrowing using
borrowing_full() or borrowing_none(): the baseline_prior for
these borrowing methods refers to the log odds for the
internal control arm.
Object of class OutcomeBinaryLogistic.
Other outcome models:
outcome_cont_normal(),
outcome_surv_exponential(),
outcome_surv_pem(),
outcome_surv_weibull_ph()
lg <- outcome_bin_logistic( binary_var = "response", baseline_prior = prior_normal(0, 1000) )lg <- outcome_bin_logistic( binary_var = "response", baseline_prior = prior_normal(0, 1000) )
Normal Outcome Distribution
outcome_cont_normal( continuous_var, baseline_prior, std_dev_prior, weight_var = "" )outcome_cont_normal( continuous_var, baseline_prior, std_dev_prior, weight_var = "" )
continuous_var |
character. Name of continuous outcome variable in the model matrix |
baseline_prior |
|
std_dev_prior |
|
weight_var |
character. Optional name of variable in model matrix for weighting the log likelihood. |
The baseline_prior argument specifies the prior distribution for the intercept of the linear model. The
interpretation of the baseline_prior differs slightly between borrowing methods selected.
Dynamic borrowing using borrowing_hierarchical_commensurate(): the baseline_prior for
Bayesian Dynamic Borrowing refers to the intercept of the external control arm.
Full borrowing or No borrowing using borrowing_full() or borrowing_none(): the
baseline_prior for these borrowing methods refers to the intercept for the internal control arm.
Object of class OutcomeContinuousNormal.
Other outcome models:
outcome_bin_logistic(),
outcome_surv_exponential(),
outcome_surv_pem(),
outcome_surv_weibull_ph()
norm <- outcome_cont_normal( continuous_var = "tumor_size", baseline_prior = prior_normal(0, 100), std_dev_prior = prior_half_cauchy(1, 5) )norm <- outcome_cont_normal( continuous_var = "tumor_size", baseline_prior = prior_normal(0, 100), std_dev_prior = prior_half_cauchy(1, 5) )
Exponential survival distribution
outcome_surv_exponential(time_var, cens_var, baseline_prior, weight_var = "")outcome_surv_exponential(time_var, cens_var, baseline_prior, weight_var = "")
time_var |
character. Name of time variable column in model matrix |
cens_var |
character. Name of the censorship variable flag in model matrix |
baseline_prior |
|
weight_var |
character. Optional name of variable in model matrix for weighting the log likelihood. |
The baseline_prior argument specifies the prior distribution for the
baseline log hazard rate. The interpretation of the baseline_prior differs
slightly between borrowing methods selected.
Dynamic borrowing using borrowing_hierarchical_commensurate():
the baseline_prior for Bayesian Dynamic Borrowing
refers to the log hazard rate of the external control arm.
Full borrowing or No borrowing using
borrowing_full() or borrowing_none(): the baseline_prior for
these borrowing methods refers to the log hazard rate for the
internal control arm.
Object of class OutcomeSurvExponential.
Other outcome models:
outcome_bin_logistic(),
outcome_cont_normal(),
outcome_surv_pem(),
outcome_surv_weibull_ph()
es <- outcome_surv_exponential( time_var = "time", cens_var = "cens", baseline_prior = prior_normal(0, 1000) )es <- outcome_surv_exponential( time_var = "time", cens_var = "cens", baseline_prior = prior_normal(0, 1000) )
Piecewise exponential survival distribution
outcome_surv_pem( time_var, cens_var, baseline_prior, weight_var = "", cut_points )outcome_surv_pem( time_var, cens_var, baseline_prior, weight_var = "", cut_points )
time_var |
character. Name of time variable column in model matrix |
cens_var |
character. Name of the censorship variable flag in model matrix |
baseline_prior |
|
weight_var |
character. Optional name of variable in model matrix for weighting the log likelihood. |
cut_points |
numeric. Vector of internal cut points for the piecewise exponential model. Note: the choice of
cut points will impact the amount of borrowing between arms when dynamic borrowing methods are selected. It is
recommended to choose cut points that contain an equal number of events
within each interval. Please include only internal
cut points in the vector. For instance, for cut points of
[0, 15], (15, 20], (20, Inf), the vector should be c(15, 20).
If you pass cut-points beyond the follow-up of the data, you will receive an informative warning when calling
|
The baseline_prior argument specifies the prior distribution for the
baseline log hazard rate within each cutpoint. Currently, there is no option to
consider different baseline priors within each cut point.
The interpretation of the baseline_prior differs
slightly between borrowing methods selected.
Dynamic borrowing using borrowing_hierarchical_commensurate():
the baseline_prior for Bayesian Dynamic Borrowing
refers to the log hazard rate of the external control arm.
Full borrowing or No borrowing using
borrowing_full() or borrowing_none(): the baseline_prior for
these borrowing methods refers to the log hazard rate for the
internal control arm.
Object of class OutcomeSurvPEM.
Other outcome models:
outcome_bin_logistic(),
outcome_cont_normal(),
outcome_surv_exponential(),
outcome_surv_weibull_ph()
es <- outcome_surv_pem( time_var = "time", cens_var = "cens", baseline_prior = prior_normal(0, 1000), cut_points = c(10, 15, 30) )es <- outcome_surv_pem( time_var = "time", cens_var = "cens", baseline_prior = prior_normal(0, 1000), cut_points = c(10, 15, 30) )
Weibull survival distribution (proportional hazards formulation)
outcome_surv_weibull_ph( time_var, cens_var, shape_prior, baseline_prior, weight_var = "" )outcome_surv_weibull_ph( time_var, cens_var, shape_prior, baseline_prior, weight_var = "" )
time_var |
character. Name of time variable column in model matrix |
cens_var |
character. Name of the censorship variable flag in model matrix |
shape_prior |
|
baseline_prior |
|
weight_var |
character. Optional name of variable in model matrix for weighting the log likelihood. |
The baseline_prior argument specifies the prior distribution for the
baseline log hazard rate. The interpretation of the baseline_prior differs
slightly between borrowing methods selected.
Dynamic borrowing using borrowing_hierarchical_commensurate():
the baseline_prior for Bayesian Dynamic Borrowing
refers to the log hazard rate of the external control arm.
Full borrowing or No borrowing using
borrowing_full() or borrowing_none(): the baseline_prior for
these borrowing methods refers to the log hazard rate for the
internal control arm.
Object of class OutcomeSurvWeibullPH.
Other outcome models:
outcome_bin_logistic(),
outcome_cont_normal(),
outcome_surv_exponential(),
outcome_surv_pem()
ws <- outcome_surv_weibull_ph( time_var = "time", cens_var = "cens", shape_prior = prior_exponential(1), baseline_prior = prior_normal(0, 1000) )ws <- outcome_surv_weibull_ph( time_var = "time", cens_var = "cens", shape_prior = prior_exponential(1), baseline_prior = prior_normal(0, 1000) )
Outcome classOutcome class
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
OutcomeBinaryLogistic classA class for defining a logistic regression with a binary outcome
to be translated to Stan code.
Objects of class OutcomeBinaryLogistic should not be created directly but by
the constructor outcome_bin_logistic().
n_paraminteger. Number of ancillary parameters for the model to estimate (0).
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
Empty for OutcomeBinaryLogistic.
binary_varcharacter. Variable used for outcome in OutcomeBinaryLogistic objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
OutcomeContinuousNormal classA class for defining a regression with a normal outcome
to be translated to Stan code.
Objects of class OutcomeContinuousNormal should not be created directly but by
the constructor outcome_cont_normal().
n_paraminteger. Number of ancillary parameters for the model to estimate (0).
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
Empty for OutcomeContinuousNormal.
continuous_varcharacter. Variable used for outcome in OutcomeContinuousNormal objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
OutcomeSurvExponential ClassA class for defining a time-to-event survival analysis with an
exponential survival distribution.
Objects of class OutcomeSurvExponential should not be created directly
but by the constructor outcome_surv_exponential().
n_paraminteger. Number of ancillary parameters for the model to estimate (0).
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
Empty for OutcomeSurvExponential.
time_varcharacter. Variable used for time in TimeToEvent objects.
cens_varcharacter. Variable used for censoring in TimeToEvent objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
OutcomeSurvPEM ClassA class for defining a time-to-event survival analysis with a
piecewise survival distribution.
Objects of class OutcomeSurvPEM should not be created directly
but by the constructor outcome_surv_pem().
function_stan_codecharacter. stan function code block containing text to interpolate into stan model.
Empty string for OutcomeSurvPEM.
param_stan_codecharacter. stan parameter code block containing text to interpolate into stan model.
Empty string for OutcomeSurvPEM.
n_paraminteger. Number of ancillary parameters for the model to estimate (0).
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
Empty for OutcomeSurvPEM.
time_varcharacter. Variable used for time in TimeToEvent objects.
cens_varcharacter. Variable used for censoring in TimeToEvent objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
n_periods.Number of periods.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvWeibullPH-class,
TimeToEvent-class
OutcomeSurvWeibullPH ClassA class for defining a time-to-event survival analysis with a
Weibull proportional hazards survival distribution.
Objects of class OutcomeSurvWeibullPH should not be created directly
but by the constructor outcome_surv_weibull_ph().
n_paraminteger. Number of ancillary parameters for the model to estimate (1).
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
time_varcharacter. Variable used for time in TimeToEvent objects.
cens_varcharacter. Variable used for censoring in TimeToEvent objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
TimeToEvent-class
Plot prior distributions as densities. Continuous distributions are plotted as curves and discrete distributions as bar plots.
## S4 method for signature 'Prior,missing' plot( x, y, default_limits, dist_type = c("continuous", "discrete"), density_fun, add, ... ) ## S4 method for signature 'PriorNormal,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorExponential,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorHalfCauchy,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorBernoulli,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorBeta,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorCauchy,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorGamma,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorHalfNormal,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorPoisson,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'UniformPrior,missing' plot(x, y, add = FALSE, ...)## S4 method for signature 'Prior,missing' plot( x, y, default_limits, dist_type = c("continuous", "discrete"), density_fun, add, ... ) ## S4 method for signature 'PriorNormal,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorExponential,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorHalfCauchy,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorBernoulli,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorBeta,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorCauchy,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorGamma,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorHalfNormal,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'PriorPoisson,missing' plot(x, y, add = FALSE, ...) ## S4 method for signature 'UniformPrior,missing' plot(x, y, add = FALSE, ...)
x |
Object inheriting from |
y |
Not used. |
default_limits |
Numeric range to plot distribution over. |
dist_type |
Plot a continuous or discrete distribution. |
density_fun |
Function which takes a vector of values and returns a vector of density values. |
add |
logical. Add density to existing plot. |
... |
Optional arguments for plotting. |
Plot ranges are selected by default to show 99% of the density for unbounded distributions.
The limits can be changed by specifying xlim = c(lower, upper).
Colors, line types, and other typical par() parameters can be used.
No return value, this function generates a plot in the current graphics device.
plot(prior_normal(1, 2)) plot(prior_exponential(0.1)) plot(prior_half_cauchy(0, 1), xlim = c(-20, 20)) plot(prior_half_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_bernoulli(0.4), xlim = c(0, 15)) plot(prior_beta(2, 2)) plot(prior_cauchy(0, 1), xlim = c(-20, 20)) plot(prior_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_gamma(0.1, 0.1)) plot(prior_half_normal(0, 1), xlim = c(-20, 20)) plot(prior_half_normal(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_poisson(5), xlim = c(0, 15)) plot(uniform_prior(1, 2), xlim = c(0, 3))plot(prior_normal(1, 2)) plot(prior_exponential(0.1)) plot(prior_half_cauchy(0, 1), xlim = c(-20, 20)) plot(prior_half_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_bernoulli(0.4), xlim = c(0, 15)) plot(prior_beta(2, 2)) plot(prior_cauchy(0, 1), xlim = c(-20, 20)) plot(prior_cauchy(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_gamma(0.1, 0.1)) plot(prior_half_normal(0, 1), xlim = c(-20, 20)) plot(prior_half_normal(0, 2), xlim = c(-20, 20), col = 2, add = TRUE) plot(prior_poisson(5), xlim = c(0, 15)) plot(uniform_prior(1, 2), xlim = c(0, 3))
Plot Probability Density Function Values
plot_pdf(x, y, ...)plot_pdf(x, y, ...)
x |
values |
y |
probability density values |
... |
passed to Plots the density values as a curve with the lower vertical limit set to 0. |
No return value, this function generates a plot in the current graphics device.
x <- seq(-2, 2, len = 100) y <- dnorm(x) plot_pdf(x, y)x <- seq(-2, 2, len = 100) y <- dnorm(x) plot_pdf(x, y)
Plot Probability Mass Function Values
plot_pmf(x, y, ..., col = "grey", add = FALSE)plot_pmf(x, y, ..., col = "grey", add = FALSE)
x |
values |
y |
probability mass values |
... |
|
col |
Fill color of bars. |
add |
Add bars to existing plot. Plots the probability values as a barplot. |
No return value, this function generates a plot in the current graphics device.
x <- seq(0, 5) y <- dpois(x, lambda = 2) plot_pmf(x, y)x <- seq(0, 5) y <- dpois(x, lambda = 2) plot_pmf(x, y)
Please use prior_poisson() instead.
poisson_prior(...)poisson_prior(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that poisson_prior() is deprecated and that
prior_poisson() should be used instead.
Get All Variable Names in Simulated Data Model Matrix
possible_data_sim_vars(object)possible_data_sim_vars(object)
object |
|
A vector of variable names
Prior bernoulli distribution
prior_bernoulli(theta)prior_bernoulli(theta)
theta |
numeric. Probability (in [0, 1]). |
Stan reference https://mc-stan.org/docs/functions-reference/bernoulli-distribution.html
Object of class PriorBernoulli.
Other priors:
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
bp <- prior_bernoulli(0.23)bp <- prior_bernoulli(0.23)
Prior beta distribution
prior_beta(alpha, beta)prior_beta(alpha, beta)
alpha |
numeric. Shape (>=0). |
beta |
numeric. Shape (>=0). |
Stan reference https://mc-stan.org/docs/functions-reference/beta-distribution.html
Object of class PriorBeta
Other priors:
prior_bernoulli(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
bp <- prior_beta(9, 235)bp <- prior_beta(9, 235)
Prior cauchy distribution
prior_cauchy(mu, sigma)prior_cauchy(mu, sigma)
mu |
numeric. Location. |
sigma |
numeric. Scale (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/cauchy-distribution.html
Object of class PriorCauchy.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
cp <- prior_cauchy(1, 1)cp <- prior_cauchy(1, 1)
Prior exponential distribution
prior_exponential(beta)prior_exponential(beta)
beta |
numeric. Inverse scale (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/exponential-distribution.html
Object of class PriorExponential.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
ep <- prior_exponential(1)ep <- prior_exponential(1)
Prior gamma distribution
prior_gamma(alpha, beta)prior_gamma(alpha, beta)
alpha |
numeric. Shape (>0). |
beta |
numeric. Inverse scale (>=0). |
Stan reference https://mc-stan.org/docs/functions-reference/gamma-distribution.html
Object of class PriorGamma.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
gp <- prior_gamma(0.001, 0.001)gp <- prior_gamma(0.001, 0.001)
Prior half-cauchy distribution
prior_half_cauchy(mu, sigma)prior_half_cauchy(mu, sigma)
mu |
numeric. Location. |
sigma |
numeric. Scale (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/cauchy-distribution.html
Object of class PriorHalfCauchy.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_normal(),
prior_normal(),
prior_poisson(),
uniform_prior()
hcp <- prior_half_cauchy(1, 1)hcp <- prior_half_cauchy(1, 1)
Prior half-normal distribution
prior_half_normal(mu, sigma)prior_half_normal(mu, sigma)
mu |
numeric. Location. |
sigma |
numeric. Scale (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/normal-distribution.html
Object of class PriorHalfNormal.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_normal(),
prior_poisson(),
uniform_prior()
hcp <- prior_half_normal(1, 1)hcp <- prior_half_normal(1, 1)
Prior normal distribution
prior_normal(mu, sigma)prior_normal(mu, sigma)
mu |
numeric. Location. |
sigma |
numeric. Scale (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/normal-distribution.html
Object of class PriorNormal.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_poisson(),
uniform_prior()
np <- prior_normal(1, 1)np <- prior_normal(1, 1)
Prior poisson distribution
prior_poisson(lambda)prior_poisson(lambda)
lambda |
numeric. Rate (>0). |
Stan reference https://mc-stan.org/docs/functions-reference/poisson.html
Object of class PriorPoisson.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
uniform_prior()
pp <- prior_poisson(100)pp <- prior_poisson(100)
Prior ClassA class for defining priors to be translated to Stan code. Objects of class
Prior should not be created directly but by one of the specific prior
class constructors.
stan_codecharacter. Stan implementation of the prior, with
placeholders for parameters surrounded with {{ and }} to be replaced
with glue::glue().
n_paraminteger. Number of prior parameters.
constraintcharacter. Support of prior distribution expressed as a
Stan constraint, e.g. "<lower=0, upper=1>".
Prior constructor functions: prior_bernoulli(), prior_beta(), prior_cauchy(), prior_half_cauchy(),
prior_gamma(), prior_normal(), prior_poisson(), uniform_prior()
Other prior classes:
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorBernoulli ClassA class for defining bernoulli priors to be translated to Stan code.
Objects of class PriorBernoulli should not be created directly but by
the constructor prior_bernoulli().
stan_codecharacter. Stan implementation of the prior, with
placeholders for bernoulli stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (1).
constraintcharacter. Support of prior distribution,
"<lower=0, upper=1>".
thetanumeric. Probability (in [0, 1]).
Other prior classes:
Prior-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorBeta ClassA class for defining beta priors to be translated to Stan code.
Objects of class PriorBeta should not be created directly but by
the constructor prior_beta().
stan_codecharacter. Stan implementation of the prior, with
placeholders for beta stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution,
"<lower=0, upper=1>".
alphanumeric. Shape (>=0).
betanumeric. Shape (>=0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorCauchy ClassA class for defining the cauchy priors to be translated to Stan code.
Objects of class PriorCauchy should not be created directly but by
the constructor prior_cauchy().
stan_codecharacter. Stan implementation of the prior, with
placeholders for cauchy stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution, (all values allowed in cauchy distribution).
munumeric. Location.
sigmanumeric. Scale (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorExponential ClassA class for defining exponential priors to be translated to Stan code.
Objects of class PriorExponential should not be created directly but by
the constructor prior_exponential().
stan_codecharacter. Stan implementation of the prior, with
placeholders for exponential Stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (1).
constraintcharacter. Support of prior distribution,
"<lower=0>".
betanumeric. Inverse scale (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorGamma ClassA class for defining gamma priors to be translated to Stan code.
Objects of class PriorGamma should not be created directly but by
the constructor prior_gamma().
stan_codecharacter. Stan implementation of the prior, with
placeholders for gamma stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution,
"<lower=0>".
alphanumeric. Shape (>0).
betanumeric. Inverse scale (>=0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorHalfCauchy ClassA class for defining half cauchy priors to be translated to Stan code.
Objects of class PriorHalfCauchy should not be created directly but by
the constructor prior_half_cauchy().
stan_codecharacter. Stan implementation of the prior, with
placeholders for the half cauchy stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution. In a half cauchy
prior, constraint is mu
munumeric. Location.
sigmanumeric. Scale (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorHalfNormal ClassA class for defining half normal priors to be translated to Stan code.
Objects of class PriorHalfNormal should not be created directly but by
the constructor prior_half_normal().
stan_codecharacter. Stan implementation of the prior, with
placeholders for the half normal stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution. In a half normal
prior, constraint is mu
munumeric. Location.
sigmanumeric. Scale (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorNormal ClassA class for defining normal priors to be translated to Stan code.
Objects of class PriorNormal should not be created directly but by
the constructor prior_normal().
stan_codecharacter. Stan implementation of the prior, with
placeholders for normal stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution, (all values allowed in normal distribution).
munumeric. Location.
sigmanumeric. Scale (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorPoisson-class,
UniformPrior-class
PriorPoisson ClassA class for defining poisson priors to be translated to Stan code.
Objects of class PriorPoisson should not be created directly but by
the constructor prior_poisson().
stan_codecharacter. Stan implementation of the prior, with
placeholders for poisson stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (1).
constraintcharacter. Support of prior distribution,
"<lower=0>".
lambdanumeric. Rate (>0).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
UniformPrior-class
draws ObjectRename Covariates in draws Object
rename_draws_covariates(draws, analysis)rename_draws_covariates(draws, analysis)
draws |
|
analysis |
|
A draws[posterior::draws] object with covariate names.
if (check_cmdstan()) { analysis_object <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ) ) samples <- mcmc_sample(analysis_object, 200, 400, 1) draws <- samples$draws() renamed_draws <- rename_draws_covariates(draws, analysis_object) summary(renamed_draws) }if (check_cmdstan()) { analysis_object <- create_analysis_obj( data_matrix = example_matrix, covariates = add_covariates( covariates = c("cov1", "cov2"), priors = prior_normal(0, 1000) ), outcome = outcome_surv_exponential( "time", "cnsr", baseline_prior = prior_normal(0, 1000) ), borrowing = borrowing_hierarchical_commensurate( "ext", prior_exponential(.001) ), treatment = treatment_details( "trt", prior_normal(0, 1000) ) ) samples <- mcmc_sample(analysis_object, 200, 400, 1) draws <- samples$draws() renamed_draws <- rename_draws_covariates(draws, analysis_object) summary(renamed_draws) }
Set Clinical Cut Off Rule
set_cut_off(object, internal = cut_off_none(), external = cut_off_none())set_cut_off(object, internal = cut_off_none(), external = cut_off_none())
object |
|
internal |
|
external |
|
A DataSimObject with updated cut_off_internal and cut_off_external slots.
data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_cut_off( data_sim, cut_off_after_events(n = 10), cut_off_after_first(time = 30) )data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_cut_off( data_sim, cut_off_after_events(n = 10), cut_off_after_first(time = 30) )
Set Drop Out Distribution
set_dropout(object, internal_treated, internal_control, external_control)set_dropout(object, internal_treated, internal_control, external_control)
object |
|
internal_treated |
|
internal_control |
|
external_control |
|
DataSimEvent objects can be specified with create_event_dist(). Currently no beta parameters can be
used in drop out distributions (unlike for the survival outcome).
A DataSimObject with updated internal_treated, internal_control and external_control slots.
data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_dropout( data_sim, internal_treated = create_event_dist(dist = "exponential", lambdas = 1 / 55), internal_control = create_event_dist(dist = "exponential", lambdas = 1 / 50), external_control = create_event_dist(dist = "exponential", lambdas = 1 / 40) )data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_dropout( data_sim, internal_treated = create_event_dist(dist = "exponential", lambdas = 1 / 55), internal_control = create_event_dist(dist = "exponential", lambdas = 1 / 50), external_control = create_event_dist(dist = "exponential", lambdas = 1 / 40) )
Set Enrollment Rates for Internal and External Trials
set_enrollment(object, internal, external = internal)set_enrollment(object, internal, external = internal)
object |
A |
internal |
|
external |
|
A DataSimObject with updated enrollment_internal and enrollment_external slots.
data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_enrollment( data_sim, internal = enrollment_constant(rate = c(10, 5), for_time = c(6, 6)), external = enrollment_constant(rate = c(5), for_time = c(20)) )data_sim <- create_data_simulation( create_baseline_object(10, 10, 10), event_dist = create_event_dist(dist = "exponential", lambdas = 1 / 36) ) set_enrollment( data_sim, internal = enrollment_constant(rate = c(10, 5), for_time = c(6, 6)), external = enrollment_constant(rate = c(5), for_time = c(20)) )
BaselineObject objectsSet transformations in BaselineObject objects
set_transformations(object, ..., overwrite = FALSE)set_transformations(object, ..., overwrite = FALSE)
object |
|
... |
Additional arguments passed to methods |
overwrite |
logical. Overwrite existing transformations? |
BaselineObject object with transformations
Set Transformations in Baseline Objects
## S4 method for signature 'BaselineObject' set_transformations(object, ..., overwrite = FALSE)## S4 method for signature 'BaselineObject' set_transformations(object, ..., overwrite = FALSE)
object |
|
... |
named transformation functions. See details for more information. |
overwrite |
If |
Transformation functions are evaluated in order and create or overwrite a column in the data.frame with that
name. The function should have signature function(data), taking a data.frame (specifically a
BaselineDataFrame object from generate(BaselineObject)) and return a vector with length identical to the total
number of patients. The @BaselineObject slot of the BaselineDataFrame may be accessed directly or with
get_quantiles() to create transformations. See binary_cutoff().
An updated BaselineObject
baseline <- create_baseline_object( 100, 50, 100, covariates = baseline_covariates( names = "age", means_int = 55, covariance_int = covariance_matrix(5) ) ) set_transformations(baseline, age_scaled = function(data) scale(data$age))baseline <- create_baseline_object( 100, 50, 100, covariates = baseline_covariates( names = "age", means_int = 55, covariance_int = covariance_matrix(5) ) ) set_transformations(baseline, age_scaled = function(data) scale(data$age))
Show the guide in Simulation objects.
show_guide(object) ## S4 method for signature 'Simulation' show_guide(object)show_guide(object) ## S4 method for signature 'Simulation' show_guide(object)
object |
|
A data.frame showing all simulation scenarios.
A function for defining which borrowing scenarios should be evaluated as part of a simulation study.
sim_borrowing_list(borrowing_list)sim_borrowing_list(borrowing_list)
borrowing_list |
named list of objects of class |
Object of class SimBorrowingList.
Other simulation classes:
sim_covariate_list(),
sim_data_list(),
sim_outcome_list(),
sim_treatment_list()
borrow_scenarios <- sim_borrowing_list( list( "No borrowing" = borrowing_none("ext"), "Full borrowing" = borrowing_full("ext"), "BDB, uninformative prior" = borrowing_hierarchical_commensurate( "ext", prior_gamma(0.001, 0.001) ), "BDB, informative prior" = borrowing_hierarchical_commensurate( "ext", prior_gamma(1, 0.001) ) ) )borrow_scenarios <- sim_borrowing_list( list( "No borrowing" = borrowing_none("ext"), "Full borrowing" = borrowing_full("ext"), "BDB, uninformative prior" = borrowing_hierarchical_commensurate( "ext", prior_gamma(0.001, 0.001) ), "BDB, informative prior" = borrowing_hierarchical_commensurate( "ext", prior_gamma(1, 0.001) ) ) )
A function for defining which covariate adjustment scenarios should be evaluated as part of a simulation study.
sim_covariate_list(covariate_list)sim_covariate_list(covariate_list)
covariate_list |
named list of objects of class |
This function allows the user to specify covariate adjustment details that will be included
as part of a simulation study. It is often of interest to compare several adjustment methods to
no adjustment. To specify no adjustment, pass NULL as a list item to covariate_list.
Object of class SimCovariateList.
Other simulation classes:
sim_borrowing_list(),
sim_data_list(),
sim_outcome_list(),
sim_treatment_list()
covariates <- sim_covariate_list( list( "No adjustment" = NULL, "Covariates 1 and 2" = add_covariates(c("cov1", "cov2"), prior_normal(0, 1000)) ) )covariates <- sim_covariate_list( list( "No adjustment" = NULL, "Covariates 1 and 2" = add_covariates(c("cov1", "cov2"), prior_normal(0, 1000)) ) )
Provide details on the desired covariate distributions and covariance for for a simulation study.
sim_covariates( covariates, covariance_internal, covariance_external = covariance_internal )sim_covariates( covariates, covariance_internal, covariance_external = covariance_internal )
covariates |
list. Named list of covariate mean values or probabilities as
generated through |
covariance_internal |
matrix. Covariance matrix before binarization for internal patients. |
covariance_external |
matrix. Covariance matrix before binarization for external patients. Defaults to the internal covariance. |
This function is intended to specify the number of covariates and
relationships between them for the purposes of designing a simulation
study in psborrow2. Because the outcome model does not necessarily
need to adjust for covariates, this function is not necessary in
create_simulation_obj(). The relationship between the treatment
and the outcome is specified elsewhere (i.e, in sim_survival() or
sim_binary_event()).
We need a few things to
Object of class SimCovariates
Other simulation:
sim_samplesize()
set.seed(123) covmat <- matrix(rWishart(1, 2, diag(2)), ncol = 2) covset1 <- sim_covariates( covariates = list( cov1 = bin_var(0.5, 0.5), cov2 = cont_var(100, 130) ), covariance_internal = covmat )set.seed(123) covmat <- matrix(rWishart(1, 2, diag(2)), ncol = 2) covset1 <- sim_covariates( covariates = list( cov1 = bin_var(0.5, 0.5), cov2 = cont_var(100, 130) ), covariance_internal = covmat )
SimCovariates object created by sim_covariates()
Summarize the number of continuous and binary covariates
in a SimCovariates object created by sim_covariates()
sim_covariates_summ(sim_covariates_obj)sim_covariates_summ(sim_covariates_obj)
sim_covariates_obj |
|
data.frame showing covariate names and types as well as counts of binary and continuous covariates.
A function for defining generated data for use as part of a simulation study.
sim_data_list(data_list, guide, effect, drift, index)sim_data_list(data_list, guide, effect, drift, index)
data_list |
list of lists of matrices. The lists at the highest
level differ in that the parameters used to generate the data. The matrices
at lowest level are different iterations of the same data generation
parameters. See |
guide |
data.frame. |
effect |
character. The column in |
drift |
character. The column in |
index |
character. The column in |
In this function, you are providing generated data for analysis in a
simulation study in psborrow2. Note that this function does not
do any data generation on your behalf; it assumes that you have generated
the data already. For a full working example, refer to the relevant vignette:
vignette('simulation_study', package = 'psborrow2').
More information on the inputs is provided below.
data_list
Each matrix embedded in data_list must have:
a flag for whether the patient is an external control
a flag for whether the patient is in the experimental treatment arm
outcome information (time and censorship for survival, flag for outcome in binary endpoints)
Optionally, the matrices may also contain covariates. See examples.
data_listEach set of distinct data generation parameters should be represented by
a single list of matrices. Because multiple scenarios may want to be
compared, a list of list of matrices is preferred. See examples.
guideThe guide should be a data.frame with one row per scenario. As a
consquence of this, the length of the list should equal the number of rows
in the guide. See examples.
Object of class SimDataList.
Other simulation classes:
sim_borrowing_list(),
sim_covariate_list(),
sim_outcome_list(),
sim_treatment_list()
base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), ind = c(1, 2) ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "ind" )base_mat <- matrix( c( rep(0, 200), rep(0, 200), rep(1, 200), rep(1, 200), rep(0, 200), rep(0, 200), rep(0, 600) ), ncol = 3, dimnames = list(NULL, c("ext", "trt", "driftOR")) ) add_binary_endpoint <- function(odds_ratio, base_matrix = base_mat) { linear_predictor <- base_matrix[, "trt"] * log(odds_ratio) prob <- 1 / (1 + exp(-linear_predictor)) bin_endpoint <- rbinom( NROW(base_matrix), 1, prob ) cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep"))) } data_list <- list( list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)), list(add_binary_endpoint(2.5), add_binary_endpoint(2.5)) ) guide <- data.frame( trueOR = c(1.5, 2.5), driftOR = c(1.0, 1.0), ind = c(1, 2) ) sdl <- sim_data_list( data_list = data_list, guide = guide, effect = "trueOR", drift = "driftOR", index = "ind" )
A function for defining which outcome scenarios should be evaluated as part of a simulation study.
sim_outcome_list(outcome_list)sim_outcome_list(outcome_list)
outcome_list |
named list of objects of class |
Object of class SimOutcomeList.
Other simulation classes:
sim_borrowing_list(),
sim_covariate_list(),
sim_data_list(),
sim_treatment_list()
outcome_scenarios <- sim_outcome_list( list( "Exponential" = outcome_surv_exponential("time", "cnsr", prior_normal(0, 10000)) ) )outcome_scenarios <- sim_outcome_list( list( "Exponential" = outcome_surv_exponential("time", "cnsr", prior_normal(0, 10000)) ) )
Set simulation study parameters for sample size
sim_samplesize(n_internal_control, n_external_control, n_internal_experimental)sim_samplesize(n_internal_control, n_external_control, n_internal_experimental)
n_internal_control |
integer. Number of patients to be simulated in the internal control arm. |
n_external_control |
integer. Number of patients to be simulated in the external control arm. |
n_internal_experimental |
integer. Number of patients to be simulated in the internal experimental arm. |
Object of class SimSampleSize
Other simulation:
sim_covariates()
ss <- sim_samplesize(200, 200, 500)ss <- sim_samplesize(200, 200, 500)
A function for defining which treatment scenarios should be evaluated as part of a simulation study.
sim_treatment_list(treatment_list)sim_treatment_list(treatment_list)
treatment_list |
named list of objects of class |
Object of class SimTreatmentList.
Other simulation classes:
sim_borrowing_list(),
sim_covariate_list(),
sim_data_list(),
sim_outcome_list()
treatment_scenarios <- sim_treatment_list( list( "Standard" = treatment_details("trt", prior_normal(0, 1000)) ) )treatment_scenarios <- sim_treatment_list( list( "Standard" = treatment_details("trt", prior_normal(0, 1000)) ) )
SimBorrowingList ClassA class for borrowing details as part of a simulation study.
Objects of class SimBorrowingList should not be created
directly but by the constructor sim_borrowing_list().
borrowing_listnamed list of object of class Borrowing, one object
for each parameter variation.
SimCovariateList ClassA class for covariate details as part of a simulation study.
Objects of class SimCovariateList should not be created
directly but by the constructor sim_covariate_list().
covariate_listnamed list of object of class Covariate, one object
for each parameter variation.
SimCovariates ClassA class for specifying covariate distributions and covariance for simulation studies.
covariateslist. List of covariate mean values or probabilities as
generated through bin_var() (class SimVarBin or cont_var()
(class SimVarCont).
covariance_internalmatrix. Covariance matrix before binarization for internal patients.
covariance_externalmatrix. Covariance matrix before binarization for external patients.
SimDataList ClassA class for defining generated data for use as part of a
simulation study. Objects of class SimDataList should not be created
directly but by the constructor sim_data_list().
data_listlist of lists of matrices. The lists at the highest level differ in that the parameters used to generate the data. The matrices at lowest level are different iterations of the same data generation parameters.
guidedata.frame. guide contains information on the parameters
that differ at the highest level of data_list.
effectcharacter. The column in guide that
corresponds to the true treatment effect estimate (hazard ratio or odds ratio).
driftcharacter. The column in guide that
corresponds to the drift between external and internal control arms. A
drift >1 means the external arm experiences greater effects.
indexcharacter. The column in guide that corresponds
to the index of the parameter situations in data_list.
SimOutcomeList ClassA class for outcome details as part of a simulation study.
Objects of class SimOutcomeList should not be created
directly but by the constructor sim_outcome_list().
outcome_listnamed list of object of class Outcome, one object
for each parameter variation.
SimSampleSize ClassA class for creating matrices for simulation studies
containing flags specifying whether the patient is from the concurrent
trial or not (ext = 0 for concurrent trial, ext = 1 for historical
data) and whether the patient is on the experimental therapy or not
(trt = 0 for no experimental therapy, trt = 1 for experimental therapy).
n_internal_controlinteger. Number of patients to be simulated in the internal control arm.
n_external_controlinteger. Number of patients to be simulated in the external control arm.
n_internal_experimentalinteger. Number of patients to be simulated in the internal experimental arm.
matmatrix. Matrix with two columns, ext (flag for being from
external data source) and trt (flag for receiving experimental
treatment)
SimTreatmentList ClassA class for treatment details as part of a simulation study.
Objects of class SimTreatmentList should not be created
directly but by the constructor sim_treatment_list().
treatment_listnamed list of object of class Treatment, one object
for each parameter variation.
Simulation ClassA class for defining Simulation study details. Objects of class
Simulation should not be created directly but by the constructor
create_simulation_obj().
data_matrix_listSimDataList. The list of lists of data matrices created
with sim_data_list().
outcomeSimOutcomeList. List of Outcome objects created with
sim_outcome_list().
borrowingSimBorrowingList. List of Borrowing objects created
with sim_borrowing_list().
covariateSimCovariateList or NULL. List of Covariate objects created
with sim_covariate_list() or NULL (no covariate adjustment).
treatmentSimTreatmentList. List of Treatment objects created
with sim_treatment_list().
guidedata.frame. Data.frame containing information on all combinations evaluated.
n_combosinteger. Number of combinations of parameters to be evaluated.
n_analysesinteger. Number of analyses (combos x datasets to be performed).
`analysis_obj_list`list. List of analysis objects indexed according to guide.
SimVar ClassA parent class for defining covariates to be created in the simulation study
calls to add_covariates().
SimVarBin classA constructor for making objects of class SimVarBin.
Objects of class SimVarBin are used to hold proportions of
binary variables specified in a simulation study.
prob_internalnumeric. Proportion for the internal arms.
prob_externalnumeric. Proportion for the external arm.
mu_internal_before_binnumeric. Mean value of covariate before binarization for the internal arms.
mu_external_before_binnumeric. Mean value of covariate before binarization for the external arm.
printval_intnumeric. Value to print to summarize internal arms.
printval_extnumeric. Value to print to summarize external arm.
type_stringcharacter. 'binary'
Other simvar classes:
SimVarCont-class
SimVarCont classA constructor for making objects of class SimVarCont.
Objects of class SimVarCont are used to hold mean values of
of continuous variables specified in a simulation study.
mu_internalnumeric. Mean covariate value for the internal arms.
mu_externalnumeric. Mean covariate value for the external arm.
printval_intnumeric. Value to print to summarize internal arms.
printval_extnumeric. Value to print to summarize external arm.
type_stringcharacter. 'continuous'
Other simvar classes:
SimVarBin-class
TimeToEvent classTimeToEvent class
n_paraminteger. Number of ancillary parameters for the model to estimate.
param_priorslist. Named list of prior distributions on the ancillary parameters in the model.
time_varcharacter. Variable used for time in TimeToEvent objects.
cens_varcharacter. Variable used for censoring in TimeToEvent objects.
baseline_priorPrior. Object of class Prior
specifying prior distribution for the baseline outcome.
name_beta_trt.Named vector for beta_trt.
name_exp_trt.Named vector for exponentiated beta_trt
alpha_type.How to interpret alpha.
name_addnl_params.Named vector for additional parameters.
Other outcome:
BinaryOutcome-class,
ContinuousOutcome-class,
Outcome-class,
OutcomeBinaryLogistic-class,
OutcomeContinuousNormal-class,
OutcomeSurvExponential-class,
OutcomeSurvPEM-class,
OutcomeSurvWeibullPH-class
Specify the treatment arm column name in the model matrix and set a prior distribution for the treatment effect (log hazard ratio or log odds ratio)
treatment_details(trt_flag_col, trt_prior)treatment_details(trt_flag_col, trt_prior)
trt_flag_col |
character. The name of the column
in the model matrix that corresponds to the treatment flag
( |
trt_prior |
Object of class |
Object of class Treatment.
sta <- treatment_details( trt_flag_col = "trt", trt_prior = prior_normal(0, 1000) )sta <- treatment_details( trt_flag_col = "trt", trt_prior = prior_normal(0, 1000) )
Treatment ClassA class for defining treatment details. Objects of class
Treatment should not be created directly but by the constructor
treatment_details().
trt_flag_colcharacter. Character specifying the name of the column
in the model matrix that corresponds to the treatment flag
(1/0 or TRUE/FALSE). This identifies patients as belonging
to the experimental treatment arm.
trt_priorPrior. Object of class Prior specifying the
prior distribution of the log effect estimate (log hazard ratio for
time to event endpoints and log odds ratio for binary endpoints).
Trim columns from Data Matrix Based on Borrowing object type
trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'Borrowing' trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingFixedPowerPrior' trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' trim_cols(borrowing_object, analysis_object)trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'Borrowing' trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingFixedPowerPrior' trim_cols(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingHierarchicalCommensurate' trim_cols(borrowing_object, analysis_object)
borrowing_object |
borrowing object |
analysis_object |
analysis object |
Trim Rows from Data Matrix Based on Borrowing object type
trim_rows(borrowing_object, analysis_object) ## S4 method for signature 'Borrowing' trim_rows(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingNone' trim_rows(borrowing_object, analysis_object)trim_rows(borrowing_object, analysis_object) ## S4 method for signature 'Borrowing' trim_rows(borrowing_object, analysis_object) ## S4 method for signature 'BorrowingNone' trim_rows(borrowing_object, analysis_object)
borrowing_object |
borrowing object |
analysis_object |
analysis object |
Prior uniform distribution
uniform_prior(alpha, beta)uniform_prior(alpha, beta)
alpha |
numeric. Lower bound. |
beta |
numeric. Upper bound (> |
Stan reference https://mc-stan.org/docs/functions-reference/uniform-distribution.html
Object of class UniformPrior.
Other priors:
prior_bernoulli(),
prior_beta(),
prior_cauchy(),
prior_exponential(),
prior_gamma(),
prior_half_cauchy(),
prior_half_normal(),
prior_normal(),
prior_poisson()
up <- uniform_prior(0, 1)up <- uniform_prior(0, 1)
UniformPrior ClassA class for defining uniform priors to be translated to Stan code.
Objects of class UniformPrior should not be created directly but by
the constructor uniform_prior().
stan_codecharacter. Stan implementation of the prior, with
placeholders for uniform stan function parameters surrounded with
{{ and }} to be replaced with glue::glue().
n_paraminteger. Number of prior parameters (2).
constraintcharacter. Support of prior distribution,
"<lower=alpha, upper=beta>".
alphanumeric. Lower bound.
betanumeric. Upper bound (>alpha).
Other prior classes:
Prior-class,
PriorBernoulli-class,
PriorBeta-class,
PriorCauchy-class,
PriorExponential-class,
PriorGamma-class,
PriorHalfCauchy-class,
PriorHalfNormal-class,
PriorNormal-class,
PriorPoisson-class
Create Variable Dictionary
variable_dictionary(analysis_obj)variable_dictionary(analysis_obj)
analysis_obj |
|
A data.frame with the names of Stan variables and the descriptions.
Please use outcome_surv_weibull_ph() instead.
weib_ph_surv_dist(...)weib_ph_surv_dist(...)
... |
Deprecated arguments to |
This function does not return a value. When called, it triggers an error
message indicating that weib_ph_surv_dist() is deprecated and that
outcome_surv_weibull_ph() should be used instead.