Print and plot methods for surveil model results

# S3 method for surveil
print(x, scale = 1, ...)

# S3 method for surveil
plot(
  x,
  scale = 1,
  style = c("mean_qi", "lines"),
  facet = FALSE,
  facet_scales = c("fixed", "free"),
  ncol = NULL,
  base_size = 14,
  palette = "Dark2",
  M = 250,
  alpha,
  lwd,
  fill = "gray80",
  size = 1.5,
  ...
)

# S3 method for list
plot(
  x,
  scale = 1,
  style = c("mean_qi", "lines"),
  facet = FALSE,
  ncol,
  facet_scales = c("fixed", "free"),
  M = 250,
  base_size = 14,
  palette = "Dark2",
  fill = "gray80",
  size = 1.5,
  alpha,
  lwd,
  ...
)

Arguments

x

A fitted surveil model, or a list of stand_surveil objects (as produced by standardize).

scale

Scale the rates by this amount; e.g., scale = 100e3 will print rates per 100,000 at risk.

...

For the plot method, additional arguments will be passed to `theme; for the print method, additional arguments will be passed to print.data.frame.

style

If style = "mean_qi", then the posterior mean and 95 percent credible interval will be plotted; if style = "lines", then M samples from the joint probability distribution of the annual rates will be plotted.

facet

If facet = TRUE, facet_wrap will be used instead of differentiating by line color.

facet_scales

When facet = TRUE, this argument controls behavior of the scales for each sub-plot. See the scales argument to facet_wrap.

ncol

Number of columns for the plotting device; optional and only used if facet = TRUE. If ncol = 1, the three plots will be aligned vertically in one column; if ncol = 3 they will b aligned horizontally in one row. Defaults to ncol = NULL to allow facet_wrap to automatically determine the number of columns.

base_size

Passed to theme_classic() to control size of plot components (text).

palette

For multiple groups, choose the color palette. For a list of options, see scale_color_brewer. The default is palette = "Dark2". Not used if facet = TRUE.

M

If style = "lines", then M is the number of samples from the posterior distribution that will be plotted; the default is M = 250.

alpha

Numeric value from zero to one. When style = "lines", this controls transparency of lines; passed to geom_line. For `style = "mean_qi", this controls the transparency of the shaded credible interval; passed to geom_ribbon.

lwd

Numeric value indicating linewidth. Passed to geom_line

fill

Color for the shaded credible intervals; only used when style = "mean_qi".

size

Positive numeric value. For style = "mean_qi", this controls the size of the points representing crude rates. To exclude these points from the plot altogether, use size = 0.

Value

The plot method returns a ggplot object; the print method returns nothing but prints a summary of results to the R console. If x is a list of stand_surveil objects, the plotted lines will be labeled using the names returned by names(x); if elements of the list are not named, plotted lines will simply be numbered.

See also

Author

Connor Donegan (Connor.Donegan@UTSouthwestern.edu)

Examples

data(msa)
dat <- aggregate(cbind(Count, Population) ~ Year + Race, data = msa, FUN = sum)
fit <- stan_rw(dat, time = Year, group = Race,
               iter = 1e3, chains = 2) # for speed only, use 4 chains

print(fit)
plot(fit, facet = TRUE, scale = 100e3)

 ## as a ggplot, you can customize the output
library(ggplot2)
plot(fit) + theme_bw()