The function creates an interactive exposure plot for one or more exposure
objects. When a list of objects is provided the estimates are overlaid on the
same plot, each rendered in a distinct color. The plot shows the instantaneous
event rate (events per unit time per system at risk) as a step function,
calculated from recurrence data by dividing the event count in each interval
by the total system-time at risk during that interval.
Usage
plotly_exposure(
exposure_obj,
showGrid = TRUE,
main = "Exposure Plot",
xlab = "Time",
ylab = "Event Rate",
fitCol = "black",
gridCol = "lightgray",
signif = 3,
cols = NULL
)Arguments
- exposure_obj
An object of class 'exposure', or a list of such objects. Each object is created using the `exposure()` function from the `ReliaGrowR` package.
- showGrid
Show grid (TRUE) or hide grid (FALSE). Default is TRUE.
- main
Main title. Default is "Exposure Plot".
- xlab
X-axis label. Default is "Time".
- ylab
Y-axis label. Default is "Event Rate".
- fitCol
Color of the event rate step function. Default is "black". Used only for a single exposure object; ignored when `cols` is provided or multiple objects are supplied.
- gridCol
Color of the grid. Default is "lightgray".
- signif
Significant digits of results. Default is 3. Must be a positive integer.
- cols
Optional character vector of colors, one per exposure object. When provided, each object's step function is drawn in the corresponding color. Recycled if shorter than the number of objects.
Details
Unlike [plotly_mcf()] which shows cumulative events, the exposure plot shows the instantaneous event rate: the number of events per unit time per system at risk in each interval. A flat exposure plot suggests a constant event rate (homogeneous Poisson process); a declining rate suggests improvement; a rising rate suggests degradation. Use this plot alongside [plotly_mcf()] to diagnose time-dependence in the event process.
Examples
library(ReliaGrowR)
ids <- c("A", "A", "A", "B", "B", "C", "C", "C", "C")
times <- c(50, 150, 350, 100, 300, 80, 200, 320, 450)
fit <- exposure(id = ids, time = times)
plotly_exposure(fit)
# Overlay two exposure objects
fit2 <- exposure(id = c("X", "X", "Y"), time = c(60, 220, 180))
plotly_exposure(list(fit, fit2), cols = c("steelblue", "tomato"))
