Plot an incidence timeseries
Usage
plot_incidence(
modelled = i_incidence_model,
raw = i_incidence_data,
...,
mapping = if (interfacer::is_col_present(modelled, class)) ggplot2::aes(colour = class)
else ggplot2::aes(),
events = i_events
)
Arguments
- modelled
An optional estimate of the incidence time series. If
modelled
is missing then it is estimated fromraw
using apoisson_locfit_model
. In this case parameterswindow
anddeg
may be supplied to control the fit.A dataframe containing the following columns:
time (as.time_period + group_unique) - A (usually complete) set of singular observations per unit time as a
time_period
incidence.fit (double) - an estimate of the incidence rate on a log scale
incidence.se.fit (double) - the standard error of the incidence rate estimate on a log scale
incidence.0.025 (positive_double) - lower confidence limit of the incidence rate (true scale)
incidence.0.5 (positive_double) - median estimate of the incidence rate (true scale)
incidence.0.975 (positive_double) - upper confidence limit of the incidence rate (true scale)
No mandatory groupings.
No default value.
modelled
can also be the output fromnormalise_incidence
in which case the plot uses the per capita rates calculated by that function- raw
The raw count data
A dataframe containing the following columns:
count (positive_integer) - Positive case counts associated with the specified timeframe
time (as.time_period + group_unique) - A (usually complete) set of singular observations per unit time as a `time_period`
No mandatory groupings.
No default value.
- ...
Arguments passed on to
geom_events
,poisson_locfit_model
window
a number of data points defining the bandwidth of the estimate, smaller values result in less smoothing, large value in more. The default value of 14 is calibrated for data provided on a daily frequency, with weekly data a lower value may be preferred. - (defaults to
14
)deg
polynomial degree (min 1) - higher degree results in less smoothing, lower values result in more smoothing. A degree of 1 is fitting a linear model piece wise. - (defaults to
1
)frequency
the density of the output estimates as a time period such as
7 days
or2 weeks
. - (defaults to"1 day"
)
- mapping
a
ggplot2::aes
mapping. Most importantly setting thecolour
to something if there are multiple incidence timeseries in the plot- events
Significant events or time spans
A dataframe containing the following columns:
label (character) - the event label
start (date) - the start date, or the date of the event
end (date) - the end date or NA if a single event
No mandatory groupings.
A default value is defined.
Examples
# example code
tmp = growthrates::england_covid %>%
time_aggregate(count=sum(count))
tmp_pop = growthrates::england_demographics %>%
dplyr::ungroup() %>%
dplyr::summarise(population = sum(population))
# If the incidence is normalised by population
tmp2 = tmp %>%
poisson_locfit_model() %>%
normalise_incidence(tmp_pop)
plot_incidence(tmp2,tmp %>% dplyr::cross_join(tmp_pop),colour="blue",size=0.25)