Title: | Free Knot-Bayesian Model Averaging |
---|---|
Description: | Analysis of Bayesian adaptive enrichment clinical trial using Free-Knot Bayesian Model Averaging (FK-BMA) method of Maleyeff et al. (2024) for Gaussian data. Maleyeff, L., Golchi, S., Moodie, E. E. M., & Hudson, M. (2024) "An adaptive enrichment design using Bayesian model averaging for selection and threshold-identification of predictive variables" <doi:10.1093/biomtc/ujae141>. |
Authors: | Lara Maleyeff [aut, cre], Shirin Golchi [aut], Erica E. M. Moodie [aut] |
Maintainer: | Lara Maleyeff <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2025-01-31 12:47:10 UTC |
Source: | CRAN |
This function extracts the posterior means of the intercept, treatment parameters, and binary parameters from the results of an rjMCMC model.
## S3 method for class 'rjMCMC' coef(object, ...)
## S3 method for class 'rjMCMC' coef(object, ...)
object |
An object of class rjMCMC containing the output from the |
... |
Additional arguments to be passed to other methods or functions. |
A numeric vector containing the posterior mean of the intercept, treatment, and binary parameters.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) coef(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) coef(results)
This function calculates the posterior mean and credible intervals for parameters from the rjMCMC results, including both intercept/treatment parameters and binary parameters. The credible intervals are computed based on the specified confidence level.
credint(results, level = 0.95)
credint(results, level = 0.95)
results |
An object of class rjMCMC containing the output from the |
level |
The level for the credible intervals (default is 0.95). |
A data frame with estimates, lower, and upper bounds of the credible intervals.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) credint(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) credint(results)
This function generates posterior fitted values from an rjMCMC model based on the provided data. It combines the fixed effects, spline terms, and binary parameters.
## S3 method for class 'rjMCMC' fitted(object, newdata = NULL, ...)
## S3 method for class 'rjMCMC' fitted(object, newdata = NULL, ...)
object |
An object of class rjMCMC containing the output from the |
newdata |
A data frame for which fited values are to be computed. If NA, the original fitted data is used. |
... |
Additional arguments to be passed to other methods or functions. |
A matrix of fitted values.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) fitted(results) fitted(results,newdata)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) fitted(results) fitted(results,newdata)
This function generates posterior fitted treatment effects from an rjMCMC model based on the provided data. It combines the fixed effects, spline terms, and binary parameters.
fittedTrtEff(results, newdata = NULL)
fittedTrtEff(results, newdata = NULL)
results |
An object of class rjMCMC containing the output from the |
newdata |
A data frame for which fitted values are to be computed. If NA, the original fitted data is used. |
A matrix of fitted values.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) fittedTrtEff(results) fittedTrtEff(results,newdata)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) fittedTrtEff(results) fittedTrtEff(results,newdata)
This function identifies the "effective subspace" where treatment is effective based on posterior inference results from the FK-BMA model. It analyzes interaction terms between treatment and covariates, allowing for both binary and continuous variables.
getEffectiveSubspace(results, newdata = NULL, alpha = 0.05, pip_cutoff = 0.1)
getEffectiveSubspace(results, newdata = NULL, alpha = 0.05, pip_cutoff = 0.1)
results |
A fitted model object from |
newdata |
Optional. A new dataset for evaluating the effective subspace.
If |
alpha |
Numeric. The alpha level used for computing quantiles. Default is |
pip_cutoff |
Numeric. The minimum Posterior Inclusion Probability (PIP)
threshold for selecting covariates. Default is |
The function computes the posterior treatment effect for each observation in the
dataset using the fittedTrtEff
function and evaluates its quantiles at the
specified alpha
level.
Binary variables with high posterior inclusion probabilities (PIP) are used to define subgroups, and the corresponding effective subspaces for a continuous variable are identified by checking where the treatment effect quantiles are strictly positive.
If the number of binary variables is <= 3
and there is exactly one continuous variable,
the function describes the effective subspace in terms of disjoint intervals.
For more complex cases, a warning is issued suggesting alternative methods such as Bayesian regression trees for interpretation.
A list with the following components:
quantiles |
A vector of quantile values for the treatment effect in the new dataset. |
is_effective_subspace |
A logical vector indicating whether the treatment effect is positive in the effective subspace. |
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) getEffectiveSubspace(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) getEffectiveSubspace(results)
This function returns the posterior inclusion probabilities (PIPs) for all variables, including the intercept and treatment, based on the results from an rjMCMC model.
pip(results)
pip(results)
results |
An object of class rjMCMC containing the output from the |
A numeric vector with the PIPs for the intercept, treatment, and other variables.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) pip(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) pip(results)
rjMCMC
resultsThis function generates plots for model results from rjMCMC
based on specified sample type, effect type, and plot type.
The function is flexible for various combinations of sample_type
, effect_type
, and plot_type
, as outlined below.
## S3 method for class 'rjMCMC' plot( x, ..., variables = NULL, sample_type = "fitted", effect_type = "treatment_effect", plot_type = "cred", level = 0.95, aux_vars = list(), facet_by = NULL, pip_cutoff = 0.1 )
## S3 method for class 'rjMCMC' plot( x, ..., variables = NULL, sample_type = "fitted", effect_type = "treatment_effect", plot_type = "cred", level = 0.95, aux_vars = list(), facet_by = NULL, pip_cutoff = 0.1 )
x |
A fitted model object from |
... |
Additional arguments to be passed to other methods or functions. |
variables |
A vector of variable names to include in the plot. Automatically set to continuous variables if |
sample_type |
Character string specifying the type of sample: "fitted", "predictive", or "estimand".
"fitted" and "predictive" are compatible with |
effect_type |
Character string indicating the effect type: "treatment_effect" or "outcome". For "treatment_effect", the function plots the fitted or predictive effect of treatment; for "outcome", it plots outcome values without interaction with treatment. |
plot_type |
Character string specifying the plot type: "cred" for credible interval plots, or "hist"/"trace" for histogram or trace plots
of individual parameters (only for |
level |
Numeric value for the credible interval level (default is 0.95). |
aux_vars |
A list of auxiliary variables and their fixed values. Each element name must match a model variable. |
facet_by |
A vector of variable names to facet by in the plot. Automatically set to binary model variables if |
pip_cutoff |
Numeric threshold for the posterior inclusion probability (PIP) of model variables to include in the plot. |
Sample and Plot Compatibility:
For sample_type = "estimand"
, only plot_type = "hist"
or "trace" is allowed, as these are designed to visualize the posterior distribution
or MCMC trajectory of individual parameters. Parameters like intercept
, trt
, and sigma
are agnostic to effect_type
as they
do not interact with treatment.
plot_type = "cred"
is designed for use with sample_type = "fitted"
or "predictive" and shows credible intervals for the outcome (y-axis)
across biomarker values (x-axis) by covariate pattern. effect_type
controls whether the treatment effect or main effect is displayed.
Effect Types:
outcome
plots either the fitted or predictive values without treatment interaction, allowing for treatment (trt
) values to be specified.
treatment_effect
plots the interaction of the treatment effect across different covariate patterns.
A ggplot2
object or a grid of plots.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) plot(results, sample_type = "fitted", effect_type = "treatment_effect", plot_type = "cred") plot(results, sample_type = "estimand", plot_type = "hist")
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) plot(results, sample_type = "fitted", effect_type = "treatment_effect", plot_type = "cred") plot(results, sample_type = "estimand", plot_type = "hist")
This function generates posterior predictions from an rjMCMC model based on the provided data. It combines the fixed effects, spline terms, and binary parameters, and includes residual variance in the predictions.
## S3 method for class 'rjMCMC' predict(object, newdata = NULL, ...)
## S3 method for class 'rjMCMC' predict(object, newdata = NULL, ...)
object |
An object of class rjMCMC containing the output from the |
newdata |
A data frame for which predictions are to be made. If NA, the original fitted data is used. |
... |
Additional arguments to be passed to other methods or functions. |
A matrix of predicted values.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) predict(results) predict(results,newdata)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) predict(results) predict(results,newdata)
This function predicts the treatment effect for new data based the Reversible Jump MCMC (rjMCMC) results.
predictTrtEff(results, newdata = NULL)
predictTrtEff(results, newdata = NULL)
results |
An object of class rjMCMC containing the output from the |
newdata |
A data frame for which predicted values are to be computed If NA, the original fitted data is used. |
The function:
Checks if the required columns in results$candinter
are present in newdata
.
Computes the fitted posterior treatment effect based on main treatment effects, spline interactions, and binary interactions.
Adds noise to the fitted posterior using the residual variance results$sigma_sq
to generate predictive posterior samples.
Spline interactions are handled by interpolating the spline coefficients for the values in newdata
.
A matrix of predictive posterior samples for the treatment effect, where each row corresponds to a posterior sample
and each column corresponds to an observation in newdata
.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) predictTrtEff(results) predictTrtEff(results,newdata)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) newdata = data.frame(Z_1 = 1, Z_2 = 1, Z_3 = 1, Z_4 = 1, Z_5 = 1, trt = 1, X_1 = seq(0,1,by=0.01)) predictTrtEff(results) predictTrtEff(results,newdata)
This function provides a detailed summary of the results from the rjMCMC
procedure, including
model information, parameter estimates, posterior inclusion probabilities, convergence diagnostics,
and plots for spline terms. The function also prints the model formula with fbs()
notation for spline terms,
indicating the use of free-knot B-splines.
## S3 method for class 'rjMCMC' print(x, ...)
## S3 method for class 'rjMCMC' print(x, ...)
x |
An object of class rjMCMC containing the output from the
|
... |
Additional arguments to be passed to other methods or functions. |
The function produces detailed summaries similar to those from brms
, including
diagnostics, estimates, posterior inclusion probabilities, and spline effects. The spline terms
are wrapped in fbs()
notation, indicating the use of free-knot B-splines in the model. If the sampler
did not converge, a warning is issued. The function also allows the user to view diagnostic plots for fitted
treatment effects.
Prints the following summary information:
The model formula with spline terms wrapped in fbs()
, indicating free-knot B-splines, and interaction terms appropriately formatted.
Reports any convergence issues based on Geweke diagnostics.
Displays MCMC sampler arguments, including the number of posterior samples, burn-in, thinning, and chains.
Posterior mean, standard error, 95% credible intervals, effective sample size (ESS), Gelman-Rubin statistic (Rhat), and posterior inclusion probabilities (PIP) for binary parameters, treatment intercept, and treatment effect.
Posterior summary for the residual standard error (sigma).
Prints the posterior inclusion probabilities for spline terms.
Plots the mean and 95% credible intervals for each spline term vs fitted treatment effects.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) print(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) print(results)
This function calculates the Rhat diagnostic for convergence based on the posterior samples of individual treatment effects, intercept, and main treatment effect from an rjMCMC model. It prints the median, minimum, and maximum Rhat values for the treatment effects, as well as the Rhat for the intercept and treatment effect.
rhats(results)
rhats(results)
results |
An
|
This function calculates R-hat statistics to assess MCMC convergence for both treatment effects and model parameters. Diagnostic plots are generated to visually inspect the chains across iterations.
A list containing:
Vector of R-hat values for each individual's treatment effect.
R-hat value for the intercept parameter.
R-hat value for the main effect of treatment.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) rhats(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) rhats(results)
This function performs a Reversible Jump MCMC (rjMCMC) procedure to generate the posterior distribution, using Bayesian model averaging and free-knot B-splines.
rjMCMC( data, candsplinevars, candbinaryvars, candinter, mcmc_specs = NULL, prior_params = NULL )
rjMCMC( data, candsplinevars, candbinaryvars, candinter, mcmc_specs = NULL, prior_params = NULL )
data |
A data frame containing the observations, including the following columns:
|
candsplinevars |
A vector of names for continuous predictive candidate variables (default = NULL). |
candbinaryvars |
A vector of names for binary predictive candidate variables (default = NULL). |
candinter |
A vector indicating which of the candidate variables are tailoring (default = NULL). |
mcmc_specs |
A list containing:
|
prior_params |
A list containing prior parameters:
|
An rjMCMC object with the following components:
Logical indicating whether the MCMC chains converged based on Geweke diagnostics.
Geweke diagnostic for the posterior treatment effects across the dataset.
Geweke diagnostic for the posterior distribution of residual variance (sigma squared).
Matrix indicating the acceptance of variable inclusion/removal for each iteration.
Matrix indicating acceptance of knot addition for each spline term across iterations.
Matrix indicating acceptance of knot removal for each spline term across iterations.
Matrix indicating acceptance of knot movement for each spline term across iterations.
List of matrices, one per spline interaction term, containing fitted spline values across iterations.
Matrix containing posterior samples of binary variable parameters.
Matrix containing posterior samples of the treatment intercept and main effect.
Matrix of posterior samples for the residual variance (sigma squared).
Matrix indicating the inclusion of variables across iterations (1 for included, 0 for excluded).
Posterior inclusion probabilities for all candidate variables (spline and binary).
Matrix indicating the number of knots for each spline term across iterations.
Matrix of posterior treatment effect estimates, including spline effects.
The original dataset passed to the function.
A character vector indicating the spline interaction terms.
A character vector of candidate spline variables.
A character vector of candidate binary variables.
A character vector of interaction terms with treatment (can include splines and binary variables).
The MCMC specifications used in the procedure.
The prior parameters used in the procedure.
Maleyeff, L., Golchi, S., Moodie, E. E. M., & Hudson, M. (2024) "An adaptive enrichment design using Bayesian model averaging for selection and threshold-identification of predictive variables" doi:10.1093/biomtc/ujae141
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params)
trt
).This dataset was generated using the formula:
,
where
.
data(simulated_data)
data(simulated_data)
A data frame with 1000 rows and 8 variables:
A continuous variable sampled from U(0, 1)
.
A binary variable sampled from Bernoulli(0.35)
.
A binary variable sampled from Bernoulli(0.5)
.
A binary variable sampled from Bernoulli(0.65)
.
A binary variable sampled from Bernoulli(0.2)
.
A binary variable sampled from Bernoulli(0.35)
.
A binary treatment variable sampled from Bernoulli(0.5)
.
The outcome variable calculated using the formula above.
data(simulated_data) head(simulated_data)
data(simulated_data) head(simulated_data)
This function provides a detailed summary of the results from the rjMCMC
procedure, including
model information, parameter estimates, posterior inclusion probabilities, convergence diagnostics,
and plots for spline terms. The function also prints the model formula with fbs()
notation for spline terms,
indicating the use of free-knot B-splines.
## S3 method for class 'rjMCMC' summary(object, digits = 2, level = 0.95, ...)
## S3 method for class 'rjMCMC' summary(object, digits = 2, level = 0.95, ...)
object |
An object of class rjMCMC containing the output from the
|
digits |
Number of digits in summary output |
level |
Credible interval level |
... |
Additional arguments to be passed to other methods or functions. |
The function produces detailed summaries similar to those from brms
, including
diagnostics, estimates, posterior inclusion probabilities, and spline effects. The spline terms
are wrapped in fbs()
notation, indicating the use of free-knot B-splines in the model. If the sampler
did not converge, a warning is issued. The function also allows the user to view diagnostic plots for fitted
treatment effects.
Prints the following summary information:
The model formula with spline terms wrapped in fbs()
, indicating free-knot B-splines, and interaction terms appropriately formatted.
Reports any convergence issues based on Geweke diagnostics.
Displays MCMC sampler arguments, including the number of posterior samples, burn-in, thinning, and chains.
Posterior mean, standard error, 95% credible intervals, effective sample size (ESS), Gelman-Rubin statistic (Rhat), and posterior inclusion probabilities (PIP) for binary parameters, treatment intercept, and treatment effect.
Posterior summary for the residual standard error (sigma).
Prints the posterior inclusion probabilities for spline terms.
Plots the mean and 95% credible intervals for each spline term vs fitted treatment effects.
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) summary(results)
# Example dataset data("simulated_data") candsplinevars <- c("X_1") candbinaryvars <- paste0("Z_", 1:5) candinter <- c(candsplinevars, candbinaryvars) mcmc_specs <- list(B = 2000, burnin = 1000, thin = 1, chains = 2, sigma_v = 0.1, bma = TRUE) prior_params <- list(lambda_1 = 0.1, lambda_2 = 1, a_0 = 0.01, b_0 = 0.01, degree = 3, k_max = 9, w = 1, sigma_B = sqrt(20)) results <- rjMCMC(simulated_data, candsplinevars, candbinaryvars, candinter, mcmc_specs, prior_params) summary(results)