fanplot_prediction: Display prediction as a fan plot

View source: R/fanplot_prediction.R

fanplot_predictionR Documentation

Display prediction as a fan plot

Description

Plots a fanplot to display quantiles of (negative binomial approximations) of the week-wise predictive distributions

Usage

fanplot_prediction(
  pred,
  unit = 1,
  probs = 1:99/100,
  interpolate_probs = TRUE,
  add_observed = TRUE,
  add_pred_means = TRUE,
  fan.col = colorRampPalette(c("darkgreen", "gray90")),
  pt.col = "red",
  pt.cex = 0.6,
  l.col = "black",
  mean_col = "black",
  mean_lty = "dashed",
  ln = NULL,
  rlab = NULL,
  add = FALSE,
  add_legend = FALSE,
  width_legend = 0.1 * (max(pred$timepoints) - min(pred$timepoints))/pred$freq,
  probs_legend = c(1, 25, 50, 75, 99)/100,
  ylim = NULL,
  xlab = "t",
  ylab = "No. infected",
  return_matrix = FALSE,
  ...
)

Arguments

pred

the prediction as returned by longterm_prediction_hhh4 (and potentially aggregated using aggregate_prediction)

unit

numeric denoting the unit to display

probs

vector of probabilities: which quantiles shall be displayed in the fan plot?

interpolate_probs

logical: smooth curves by simple interpolation of quantiles

add_observed

logical: shall observed values be added?

fan.col, ln, rlab

graphical parameters passed on to fanplot::fan

pt.col, pt.cex, l.col

graphical parameters for display of observed values

add

logical: add to existing plot?

add_legend

logical: shall a color key legend be added?

width_legend

width of box for color key legend in user coordinates

probs_legend

vecor of probabilities to display in the legend

ylim

limit for the y-axis, passed to plot()

xlab, ylab

axis labels

return_matrix

logical: return matrix passed to fanplot::fan; useful to make more sophisticated plots.

...

other arguments passed on to plot()

Value

Only if return_matrix set to TRUE: the matrix passed to fanplot::fan

Examples

data("salmonella.agona")
# convert old "disProg" to new "sts" data class:
salmonella <- disProg2sts(salmonella.agona)
control_salmonella <- list(end = list(f = addSeason2formula(~ 1), lag = 1),
                           ar = list(f = addSeason2formula(~ 1), lag = 1),
                           family = "NegBinM", subset = 6:250)
fit_salmonella <- hhh4_lag(salmonella, control_salmonella) # fit model
# obtain prediction:
pred_mom <- predictive_moments(fit_salmonella, t_condition = 250, lgt = 52)
# plot the prediction only:
fanplot_prediction(pred_mom, add_legend = TRUE)
# or plot it along with the fit:
plot(fit_salmonella)
fanplot_prediction(pred_mom, add = TRUE) # add fan plot


jbracher/hhh4addon documentation built on Feb. 16, 2024, 1:45 a.m.