# NOT RUN {
## Example 1
## A single Bayesian assurance value obtained given a scalar sample size
## n and p=1. Note that setting p=1 implies that
## beta is a scalar parameter.
bayesassurance::bayes_sim(n=100, p = 1, u = 1, C = 0.15, Xn = NULL,
Vbeta_d = 1e-8, Vbeta_a_inv = 0, Vn = NULL, sigsq = 0.265, mu_beta_d = 0.3,
mu_beta_a = 0, alt = "two.sided", alpha = 0.05, mc_iter = 5000)
## Example 2
## Illustrates a scenario in which weak analysis priors and strong
## design priors are assigned to enable overlap between the frequentist
## power and Bayesian assurance.
# }
# NOT RUN {
library(ggplot2)
n <- seq(100, 250, 5)
## Frequentist Power
power <- bayesassurance::pwr_freq(n, sigsq = 0.265, theta_0 = 0.15,
theta_1 = 0.25, alt = "greater", alpha = 0.05)
## Bayesian simulation values with specified values from the n vector
assurance <- bayesassurance::bayes_sim(n, p = 1, u = 1, C = 0.15, Xn = NULL,
Vbeta_d = 1e-8, Vbeta_a_inv = 0, Vn = NULL, sigsq = 0.265, mu_beta_d = 0.25,
mu_beta_a = 0, alt = "greater", alpha = 0.05, mc_iter = 1000)
## Visual representation of plots overlayed on top of one another
df1 <- as.data.frame(cbind(n, power = power$pwr_table$Power))
df2 <- as.data.frame(cbind(n, assurance =
assurance$assurance_table$Assurance))
plot_curves <- ggplot2::ggplot(df1, alpha = 0.5, ggplot2::aes(x = n, y = power,
color="Frequentist")) + ggplot2::geom_line(lwd=1.2)
plot_curves <- plot_curves + ggplot2::geom_point(data = df2, alpha = 0.5,
aes(x = n, y = assurance, color="Bayesian"),lwd=1.2) +
ggplot2::ggtitle("Bayesian Simulation vs. Frequentist Power Computation")
plot_curves
# }
# NOT RUN {
## Example 3
## Longitudinal example where n now denotes the number of repeated measures
## per subject and design matrix is determined accordingly.
## subject ids
n <- seq(10, 100, 5)
ids <- c(1,2)
sigsq <- 100
Vbeta_a_inv <- matrix(rep(0, 16), nrow = 4, ncol = 4)
Vbeta_d <- (1 / sigsq) *
matrix(c(4, 0, 3, 0, 0, 6, 0, 0, 3, 0, 4, 0, 0, 0, 0, 6),
nrow = 4, ncol = 4)
assur_out <- bayes_sim(n = n, p = NULL, u = c(1, -1, 1, -1), C = 0,
Xn = NULL, Vbeta_d = Vbeta_d,
Vbeta_a_inv = Vbeta_a_inv,
Vn = NULL, sigsq = 100,
mu_beta_d = as.matrix(c(5, 6.5, 62, 84)),
mu_beta_a = as.matrix(rep(0, 4)), mc_iter = 1000,
alt = "two.sided", alpha = 0.05,
longitudinal = TRUE, ids = ids,
from = 10, to = 120)
assur_out$assurance_plot
# }
Run the code above in your browser using DataLab