fanplot_stationary: Display stationary distribution as a fanplot

View source: R/fanplot_stationary.R

fanplot_stationaryR Documentation

Display stationary distribution as a fanplot

Description

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

Usage

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

Arguments

stat_mom

the stationary moments as returned by stationary_moments_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_pred_means

logical: add line showing the the predictive means

fan.col, ln, ln.col, rlab, style

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?

timepoints

vector giving the x-coordinates for the fanplot (generates start and frequency for fanplot::fan)

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

hlines, vlines

coordinates for horizontal and vertical grid lines

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

means_col, mean_lty

graphical parameters for display of predictive means

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)
# specify and fit model
control_salmonella <- list(end = list(f = addSeason2formula(~ 1), lag = 1),
                           ar = list(f = addSeason2formula(~ 1), lag = 1),
                           family = "NegBinM")
fit_salmonella <- hhh4(salmonella, control_salmonella)
# obtain periodically stationary moments:
stat_mom <- stationary_moments(fit_salmonella)
# plot periodically stationary means:
fanplot_stationary(stat_mom, add_legend = TRUE)
# add paths of the six seasons in the data set:
for(i in 0:5){
 lines(1:52/52, salmonella@observed[(i*52 + 1):((i + 1)*52)], col = "blue")
}
legend("topleft", col = "blue", lty = 1, legend = "observed seasons")

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