epidplot | R Documentation |
visualize the cummulated time series and its derivative (news). Add smoothed lines of the news. Additional plots shows the 1st and 2nd derivatives of the smoothed, interpreted as the absolute increase and velocity.
epidplot(
x,
y,
log10 = TRUE,
which = list(1:2, c(3, 5), 4, 6),
w = exp(-sqrt(1:14)) * 0.686,
leg.args = NULL,
lxlab = NULL,
lylab = NULL,
ask = prod(par("mfcol")) < length(which) && dev.interactive(),
...
)
x |
a date or numeric vector |
y |
the cummulated number of cases |
log10 |
length one or two logical to indicate if accumulated and new series are shown in the log10 transformation. |
which |
integer vector or list of integers to specify which plots will be produced in each figure. See detais. |
w |
numeric vector to compute the expected number of new cases given past cases. See details. |
leg.args |
a named list with arguments passed to the legend of the first plot. |
lxlab |
a list with the xlab for each plot. |
lylab |
a list with the xlab for each plot. |
ask |
logical if ‘TRUE’, the user is _ask_ed
before each plot, see |
... |
additional arguments passed to |
This function produces up to 6 plots.
1st: accumulated, provided y, with smoothed line
2nd: new cases with smoothed line
3nd: derivative, change on the trend, of the
smoothed line for new cases.
4th: derivative divided by the smoothed new cases line
5th: second derivative of the smoothed line for the
new cases series, representing the velocity of
the absolute change.
6th: effective reproduction number.
The first and second plots can be joined into one.
The smoothed line for the second plot is computed
using the mgcv::gam
function with
mgcv::s()
on x
considering
family=poisson()
.
The line for the 1st plot is the cumsum of the
line being fitted for the 2nd plot.
The last plot consider
R_t = s_t/E_t
where E_t = sum_j w_j s_t-j,
for j = 1, ..., k=length(w).
In this plot it will be shown the last (n-k)
values for R_t, if type!='n'.
up to six plots
## COVID19 cases in Nova Scotia, Canada
ns.cases <- c(5, 7, 12, 14, 15, 21, 28, 41,
51, 68, 73, 90, 110, 122, 127, 147, 173,
193, 207, 236, 262, 293, 310, 310, 342,
407, 428, 445, 474, 517, 549, 579, 606,
649, 675, 721, 737, 772, 827, 850, 865,
873, 900, 915, 935, 947, 959, 963, 971,
985, 991, 998, 1007, 1008, 1011, 1018,
1019, 1020, 1024, 1026, 1034, 1037, 1040,
1043, 1044, 1045, 1046, 1048, 1049, 1050,
1051, 1052, 1053, 1055, 1055, 1056, 1056,
1057, 1057, 1058, 1058, 1058, 1058, 1059,
1059, 1060, 1061, 1061, 1061, 1061)
date <- as.Date('2020-03-15') + 1:length(ns.cases)
pw <- pgamma(0:14, shape=(5/3)^2, scale=3^2/5)
w <- diff(pw)/sum(diff(pw))
par(mfrow=c(2,2), mar=c(2,3,1,1),
mgp=c(2, 0.5, 0), las=1)
epidplot(date, ns.cases, logbase=10, w=w)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.