Description Usage Arguments Details Aesthetics Examples
The prediction_band geom/stat
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | stat_prediction_band(
  mapping = NULL,
  data = NULL,
  geom = "polygon",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  pb_type = c("delta_ball", "kde", "spherical_ball", "convex_hull"),
  grid_size = rep(100, 2),
  conf_level = 0.9,
  over_delta = 0.1,
  dist_params = list(dist_approach = "auto", num_steps = "auto", quantile_approach =
    "depth", quantile_approach_params = list()),
  ...
)
geom_prediction_band(
  mapping = NULL,
  data = NULL,
  stat = list("PredBandDeltaBall", "PredBandKDE", "PredBandSpherical",
    "PredBandConvexHull")[c("delta_ball", "kde", "spherical_ball", "convex_hull") ==
    pb_type][[1]],
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE,
  pb_type = c("delta_ball", "kde", "spherical_ball", "convex_hull"),
  grid_size = rep(100, 2),
  conf_level = 0.9,
  over_delta = 0.1,
  dist_params = list(dist_approach = "auto", num_steps = "auto", quantile_approach =
    "depth", quantile_approach_params = list()),
  ...
)
 | 
| mapping | Set of aesthetic mappings created by
 | 
| data | The data to be displayed in this layer. There are three options:
If  A  A  | 
| geom | string associated with desired geom.  | 
| position | Position adjustment, either as a string, or the result of a call to a position adjustment function. | 
| na.rm | If  | 
| show.legend | logical. Should this layer be included in the legends?
 | 
| inherit.aes | If  | 
| pb_type | String indicating which prediction band type to use. Currently
only  | 
| grid_size | integer vector, length 2. Size of the grid which is going to be used to approximate prediction band (if needed). Can be reduced to speed-up computation. | 
| conf_level | confidence level for prediction band. Aka, with  | 
| over_delta | defines small extension of box around actual points to define contour. | 
| dist_params | list of parameters for distance based approaches (convex hull and delta ball). See details for more information | 
| ... | Other arguments passed on to  | 
| stat | string associated with desired stat  | 
Prediction Bands:
This stat/geom can create 1 of 4 prediction band structures. These approaches can be broken into 2 subgroups, "pointwise" and "uniform" prediction bands. The rational for these splits relate to containment properties and the 'original' ideas are discussed more here: Arvix: 1906.08832
Prediction Bands - Pointwise:
spherical_ball: This prediction band is defined
relative to the time points that paths take. For each time point, we take a
ellipsoid defined by the prediction region that would contain
conf_level probability mass if the distribution of points were a
multivariate gaussian. We then take a union of all these ellipsoids to create
the full prediction band.
kde: This prediction band is defined as the kde level contour
for conf_level relative to all points.
Prediction Bands - Uniform:
These approaches focus on containing the paths/curves/filaments in
uniformity. This approach uses depth (specifically a distance-based depth
developed by Geenens & Nieto-Reyes, 2017), to select to top
conf_level curves and then creates a geometric representation of
where the curves lie.
delta_ball: relative to all the points in the top
conf_level curves, we find the minimum delta such all of these points
are contained in at least 1 ball around another point with radius delta. This
can be mathematically expressed as: δ = \max_{i} \min_{j} d(x_i,
x_j). Then we take the union of delta-balls surround all the points as the
prediction band.
convex_hull: with to all the points in the top
conf_level curves we just create a convex hull and define our
prediction band as such.
Distance attributes
The dist_params list parameter informs us about what type of 
distance comparisons we do between simulations. The values in the list 
include:
"dist_approach": Options are c("auto", "equa_dist",
"temporal"). Naturally we recommend "auto" - which is just 
"equa_dist". This parameter defines we calculate the distance between 
2 curves using l_2 distance. If "equa_dist" we re-define the 
curves relative to points spaced equa-distant apart.
num_steps: Options are either "auto" or a numerical 
value. If "dist_approach" parameter is "equa_dist" then this
will define the number of points the curves are re-defined along. If 
"auto" then we use 20 equa-spaced points.
"quantile_approach": Options are c("depth", "local_depth",
"pseudo-density"). Default is "depth" (but we recommend "pseudo-density"). 
This relates to the type of ordering approach to define. 
"quantile_approach_params": this is a list of parameters 
values that are passed to the "quantile_approach", for 
"loal_depth" we expect a tau value, for "psuedo-density" 
it's sigma, both can either take associated values or associated 
quantile string percentages. 
Debugging
If you get a
| 1 2 | 
Then that probably means you've input a parameter incorrectly (ggplot
is slightly finicky.) We invite you to submit an issue if you're pretty sure
all parameters are input correctly.
stat_prediction_band/geom_prediction_band
understands the following aesthetics (required aesthetics are in bold):
x
y
z
alpha
colour
group
linetype
size
For prediction band types = "kde", "delta_ball":
sim_group - note: this cannot be a factor 
For prediction band type = "spherical_balls":
t - note:
this cannot be a factor 
Learn more about setting these aesthetics in
vignette("ggplot2-specs").
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | library(ggplot2)
library(dplyr)
library(ggtern); EpiCompare:::update_approved_layers()
#                ^ this doesn't generally need to be done
# for speed purposes
smaller_pomp_df <- EpiCompare::pomp_df %>% filter(.id < 10)
vis_data <- smaller_pomp_df %>%
 rename(x = "S", y = "I", z = "R") %>%
 ggplot(aes(x = x, y =y, z = z, group = .id)) +
 geom_path(alpha = .3) +
 coord_tern() +
 labs(title = "Actually data paths")
vis_spherical <- smaller_pomp_df %>%
 rename(x = "S", y = "I", z = "R", t = "time") %>%
 ggplot(aes(x = x, y = y, z = z, t = t)) +
 geom_prediction_band(pb_type = "spherical_ball",
                      grid_size = rep(100,2),
                      conf_level = .95) +
 coord_tern() +
 labs(title = "Spherical CB")
vis_delta_ball <- smaller_pomp_df %>%
 rename(x = "S", y = "I", z = "R") %>%
 mutate(.id = as.numeric(.id)) %>%
 ggplot(aes(x = x, y = y, z = z, sim_group = .id)) +
 geom_prediction_band(pb_type = "delta_ball",
                      grid_size = rep(100,2),
                      conf_level = .95) +
 coord_tern() +
 labs(title = "Delta-ball CB")
vis_kde <- smaller_pomp_df %>%
 rename(x = "S", y = "I", z = "R") %>%
 mutate(.id = as.numeric(.id)) %>%
 ggplot(aes(x = x, y = y, z = z, sim_group = .id)) +
 geom_prediction_band(pb_type = "kde",
                      grid_size = rep(100,2),
                      conf_level = .95) +
 coord_tern() +
 labs(title = "KDE CB")
vis_convex_hull <- smaller_pomp_df %>%
 rename(x = "S", y = "I", z = "R") %>%
 mutate(.id = as.numeric(.id)) %>%
 ggplot(aes(x = x, y = y, z = z, sim_group = .id)) +
 geom_prediction_band(pb_type = "convex_hull",
                      conf_level = .95) +
 coord_tern() +
 labs(title = "Convex hull CB")
# run this if you want to see them all
grid.arrange(vis_data, vis_spherical,
            vis_delta_ball, vis_kde,
            vis_convex_hull, nrow = 2)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.