View source: R/plot_convergence.R
plot_convergence | R Documentation |
Plots performance metrics according to the number of simulations conducted
for multiple simulated trials. The simulated trial results may be split into
a number of batches to illustrate stability of performance metrics across
different simulations. Calculations are done according to specified selection
and restriction strategies as described in extract_results()
and
check_performance()
. Requires the ggplot2
package installed.
plot_convergence(
object,
metrics = "size mean",
resolution = 100,
select_strategy = "control if available",
select_last_arm = FALSE,
select_preferences = NULL,
te_comp = NULL,
raw_ests = FALSE,
final_ests = NULL,
restrict = NULL,
n_split = 1,
nrow = NULL,
ncol = NULL,
cores = NULL
)
object |
|
metrics |
the performance metrics to plot, as described in
|
resolution |
single positive integer, the number of points calculated
and plotted, defaults to |
select_strategy |
single character string. If a trial was not stopped
due to superiority (or had only 1 arm remaining, if
|
select_last_arm |
single logical, defaults to |
select_preferences |
character vector specifying a number of arms used
for selection if one of the |
te_comp |
character string, treatment-effect comparator. Can be either
|
raw_ests |
single logical. If |
final_ests |
single logical. If |
restrict |
single character string or |
n_split |
single positive integer, the number of consecutive batches the
simulation results will be split into, which will be plotted separately.
Default is |
nrow , ncol |
the number of rows and columns when plotting multiple
metrics in the same plot (using faceting in |
cores |
|
A ggplot2
plot object.
check_performance()
, summary()
, extract_results()
,
check_remaining_arms()
.
#### Only run examples if ggplot2 is installed ####
if (requireNamespace("ggplot2", quietly = TRUE)){
# Setup a trial specification
binom_trial <- setup_trial_binom(arms = c("A", "B", "C", "D"),
control = "A",
true_ys = c(0.20, 0.18, 0.22, 0.24),
data_looks = 1:20 * 100)
# Run multiple simulation with a fixed random base seed
res_mult <- run_trials(binom_trial, n_rep = 25, base_seed = 678)
# NOTE: the number of simulations in this example is smaller than
# recommended - the plots reflect that, and show that performance metrics
# are not stable and have likely not converged yet
# Convergence plot of mean sample sizes
plot_convergence(res_mult, metrics = "size mean")
}
if (requireNamespace("ggplot2", quietly = TRUE)){
# Convergence plot of mean sample sizes and ideal design percentages,
# with simulations split in 2 batches
plot_convergence(res_mult, metrics = c("size mean", "idp"), n_split = 2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.