plot.micsim_reestimation: Plot supplied against recovered transition rates

View source: R/plot_reestimation.R

plot.micsim_reestimationR Documentation

Plot supplied against recovered transition rates

Description

Draws one figure per declared transition. The left panel shows the rate the model was given; the right panel shows the rate recovered from the simulated population (reestimate()): the occurrence/exposure rate of each band as a point whose size reflects its person-years, with its exact 95% Poisson interval, the smooth Poisson-spline fit with its 95% band, and the supplied rate as a dashed reference. Both panels share the x and the y axis.

Usage

## S3 method for class 'micsim_reestimation'
plot(
  x,
  which = NULL,
  log = NULL,
  ask = NULL,
  panels = c("both", "supplied", "recovered"),
  legend = NULL,
  layout = TRUE,
  style = NULL,
  ...
)

## S3 method for class 'micsim_result'
plot(
  x,
  which = NULL,
  log = NULL,
  ask = NULL,
  panels = c("both", "supplied", "recovered"),
  legend = NULL,
  layout = TRUE,
  style = NULL,
  ...
)

## S3 method for class 'micsim_rate_check'
plot(
  x,
  log = NULL,
  panels = c("both", "supplied", "recovered"),
  legend = NULL,
  layout = TRUE,
  style = NULL,
  ...
)

Arguments

x

A micsim_reestimation, a micsim_result, or one element of a reestimation.

which

Transitions to draw: positions or labels (the names of the reestimation). All by default.

log

TRUE or FALSE to force a logarithmic or linear y axis; NULL decides per transition.

ask

Wait between figures? Defaults to TRUE on an interactive device when there is more than one.

panels

"both" (default), "supplied" or "recovered": which panels to draw.

legend

Draw the legend? NULL (default) means TRUE in the full layout and FALSE with layout = FALSE.

layout

TRUE (default) arranges each figure on its own page. FALSE draws the panels into the figure regions already set up, e.g. with par(mfrow = ).

style

Named list of colours overriding the defaults: groups (up to three), truth, points, smooth, forced, grid, axis, muted.

...

Graphical arguments main and sub (one per figure, recycled), xlab, ylab, xlim, ylim (in rate units, also on a log axis) and cex. Others are ignored with a warning.

Details

If the rate depends on a second time scale (age and calendar time, for example), each period of that scale has its own colour in both panels, and the supplied rate is drawn at the middle of each period.

The dashed reference in the right panel is the supplied rate itself when it depends only on the time scale on the x axis. Otherwise it is the supplied rate averaged over the exposure in each band, which is exactly what the band estimate estimates.

The y axis is logarithmic when the values span more than 2.5 orders of magnitude, unless log says otherwise. Points beyond the axis are marked by a triangle at the edge. Shaded regions are where the rate is infinite (a forced transition); there is no hazard to smooth there, and the band estimates reflect the timing rule rather than a rate.

Several figures are drawn in turn; on an interactive device the plot waits for confirmation between them (ask). To keep them, draw to a file device, e.g. pdf("rates.pdf", width = 11, height = 5), or select one with which. A size of about 11 by 5 inches suits them.

Before drawing, the size of the device is checked. If the full layout does not fit, a compact one without legend, subtitle and notes is used. If that does not fit either, an error says so and nothing is drawn.

Use panels and layout = FALSE to draw into a grid of your own, e.g. par(mfrow = c(2, 2)); plot(result, which = 1:4, panels = "recovered", layout = FALSE).

Value

x, invisibly.

See Also

reestimate(), simulate.micsim_model()

Examples

mort <- function(age) 0.0005 * exp(0.07 * age)
model <- micsim_model(
  state_space(sex = c("m", "f")),
  transitions(transition(NA, "dead", mort)),
  data.frame(ID = 1:500, birthDate = "19400101", initState = "f"),
  horizon = c(20000101, 20291231)
)
result <- simulate(model, seed = 1)
plot(result)


MicSim documentation built on Dec. 2, 2026, 1:09 a.m.