# Running example (runs across compute_posterior, plot_data and plot_simplex)
# based on real data from chloroquine-treated participant 52 of the Vivax
# History Trial (Chu et al. 2018a, https://doi.org/10.1093/cid/ciy319)
y <- ys_VHX_BPD[["VHX_52"]] # y is a list of length two (two episodes)
post <- compute_posterior(y, fs_VHX_BPD, progress.bar = FALSE)
plot_simplex(p.coords = post$marg, p.labels = "", pch = 20, cex = 2)
# Basic example
plot_simplex(p.coords = diag(3),
p.labels = c("(1,0,0)", "(0,1,0)", "(0,0,1)"),
p.labels.pos = c(1,3,3))
# ==============================================================================
# Given data on an enrollment episode and a recurrence,
# compute the posterior probabilities of the 3Rs and plot the deviation of the
# posterior from the prior
# ==============================================================================
# Some data:
y <- list(list(m1 = c('a', 'b'), m2 = c('c', 'd')), # Enrollment episode
list(m1 = c('a'), m2 = c('c'))) # Recurrent episode
# Some allele frequencies:
fs <- list(m1 = setNames(c(0.4, 0.6), c('a', 'b')),
m2 = setNames(c(0.2, 0.8), c('c', 'd')))
# A vector of prior probabilities:
prior <- array(c(0.2, 0.3, 0.5), dim = c(1,3),
dimnames = list(NULL, c("C", "L", "I")))
# Compute posterior probabilities
post <- compute_posterior(y, fs, prior, progress.bar = FALSE)
# Plot simplex with the prior and posterior
plot_simplex(p.coords = rbind(prior, post$marg),
p.labels = c("Prior", "Posterior"),
pch = 20)
# Add the deviation between the prior and posterior: requires obtaining 2D
# coordinates manually
xy_prior <- project2D(as.vector(prior))
xy_post <- project2D(as.vector(post$marg))
arrows(x0 = xy_prior["x"], x1 = xy_post["x"],
y0 = xy_prior["y"], y1 = xy_post["y"], length = 0.1)
Run the code above in your browser using DataLab