get_data_func <- function() {
group_sizes <- rbinom(n = 5, size = 50, prob = c(0.1, 0.3, 0.3, 0.2, 0.1))
group_responses <- rbinom(n = 5, size = group_sizes,
prob = c(0.2, 0.5, 0.2, 0.2, 0.2))
list(
group_responses = group_responses, group_sizes = group_sizes,
mu_mean = gtools::logit(0.1), mu_sd = 1, tau_alpha = 2, tau_beta = 20
)
}
fit_model_func <- function(data) {
data <- append(data, list(refresh = 0))
do.call(stan_hierarchical_response_thall, args = data)
}
summarise_func <- function(data, fit) {
# Probability that estimate response rate exceeds 30%
unname(colMeans(as.data.frame(fit, 'prob_response') > 0.3))
}
if (FALSE) {
sims <- trialr_simulate(N = 20, get_data_func, fit_model_func, summarise_func)
# Posterior probabilities that the response rate in each cohort exceeds 30%:
do.call(rbind, sims)
# Cohorts are in columns; simulated iterations are in rows.
}
Run the code above in your browser using DataLab