geom_prediction_band: The prediction_band geom/stat

Description Usage Arguments Details Aesthetics Examples

View source: R/bands.R

Description

The prediction_band geom/stat

Usage

 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()),
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes or aes_. If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping

data

The data to be displayed in this layer. There are three options: If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot.

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data. A function can be created from a formula (e.g. ~ head(.x, 10)).

geom

string associated with desired geom. stat is otherwise controlled by the pb_type parameter.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders.

pb_type

String indicating which prediction band type to use. Currently only "kde" and "delta_ball" inputs are expected. See details for more information.

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 alpha = 1-conf_level, it creates a 1 - alpha level prediction band.

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 layer. These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.

stat

string associated with desired stat geom is otherwise controlled by the pb_type parameter.

Details

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:

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.

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:

Debugging

If you get a

1
2
Error: Problem with `mutate()` input `piece_old`. x Column `piece` 
not found in `.data` ℹ Input `piece_old` is `.data$piece`.

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.

Aesthetics

stat_prediction_band/geom_prediction_band understands the following aesthetics (required aesthetics are in bold):

For prediction band types = "kde", "delta_ball":

For prediction band type = "spherical_balls":

Learn more about setting these aesthetics in vignette("ggplot2-specs").

Examples

 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)

skgallagher/EpiCompare documentation built on Sept. 14, 2021, 5:45 a.m.