nowcast(now,when,data,dEventCol="dHospital",dReportCol="dReport",
method=c("bayes.notrunc","bayes.notrunc.bnb","lawless","bayes.trunc",
"unif","bayes.trunc.ddcp"),
aggregate.by="1 day",
D=15, m=NULL,
control=list(
dRange=NULL,alpha=0.05,nSamples=1e3,
N.tInf.prior=c("poisgamma","pois","unif"),
N.tInf.max=300, gd.prior.kappa=0.1,
ddcp=list(ddChangepoint=NULL,
logLambda=c("iidLogGa","tps","rw1","rw2"),
tau.gamma=1,eta.mu=NULL, eta.prec=NULL,
mcmc=c(burnin=2500,sample=10000,thin=1)),
score=FALSE,predPMF=FALSE))
Date
denoting the day at which to do the
nowcast. This corresponds to $T$ in the notation of
Date
objects denoting the day(s) for which
the projections are to be done. One needs to ensure that each
element in when
is smaller or equal to now
.data
which contains the
date of the event, e.g. hospitalization. Default: "dHospital"
.data
containing the date at
which the report arrives at the respective register. Default:
"dReport"
.data
. See
linelist2sts
and seq.Date
for further
informataggregate.by
). Default: 15.NULL
, i.e. take all values at all times.nowcast
returns an object of "stsNC "
. The
upperbound
slot contains the median of the method specified at
the first position the argument method
. The slot pi
(for
prediction interval)
contains the equal tailed (1-$\alpha$)*100% prediction
intervals, which are calculated based on the predictive distributions
in slot predPMF
.
Furthermore, slot truth
contains an sts
object
containing the true number of cases (if possible to compute it based on
the data in data
. Finally, slot SR
contains the results
for the proper scoring rules (requires truth to be calculable).data("husO104Hosp")
#Extract the reporting triangle at a specific day
t.repTriangle <- as.Date("2011-07-04")
#Use 'void' nowcasting procedure (we just want the reporting triangle)
nc <- nowcast(now=t.repTriangle,when=t.repTriangle,
dEventCol="dHosp",dReportCol="dReport",data=husO104Hosp,
D=15,method="unif")
#Show reporting triangle
reportingTriangle(nc)
#Perform Bayesian nowcasting assuming the delay distribution is stable over time
nc.control <- list(N.tInf.prior=structure("poisgamma",
mean.lambda=50,var.lambda=3000),
nSamples=1e2)
t.repTriangle <- as.Date("2011-06-10")
when <- seq(t.repTriangle-3,length.out=10,by="-1 day")
nc <- nowcast(now=t.repTriangle,when=when,
dEventCol="dHosp",dReportCol="dReport",data=husO104Hosp,
D=15,method="bayes.trunc",control=nc.control)
#Show time series and posterior median forecast/nowcast
plot(nc,xaxis.tickFreq=list("%d"=atChange,"%m"=atChange),
xaxis.labelFreq=list("%d"=at2ndChange),xaxis.labelFormat="%d-%b",
xlab="Time (days)",lty=c(1,1,1,1),lwd=c(1,1,2))
nc.control.ddcp <- modifyList(nc.control,
list(gd.prior.kappa=0.1,
ddcp=list(ddChangepoint=as.Date(c("2011-05-23")),
logLambda="tps",
tau.gamma=1,
mcmc=c(burnin=1000,sample=1000,thin=1))))
###Using runjags to do Bayesian model with changepoint(s) -- this might take
###a while.
nc.ddcp <- nowcast(now=t.repTriangle,when=when,
dEventCol="dHosp",dReportCol="dReport",
data=husO104Hosp, aggregate.by="1 day",
method="bayes.trunc.ddcp", D=15,
control=nc.control.ddcp)
plot(nc.ddcp,legend.opts=NULL,,
xaxis.tickFreq=list("%d"=atChange,"%m"=atChange),
xaxis.labelFreq=list("%d"=at2ndChange),xaxis.labelFormat="%d-%b",
xlab="Time (days)",lty=c(1,1,1,1),lwd=c(1,1,2))
lambda <- attr(delayCDF(nc.ddcp)[["bayes.trunc.ddcp"]],"model")$lambda
showIdx <- seq(which( max(when) == epoch(nc.ddcp))) #seq(ncol(lambda))
matlines( showIdx,t(lambda)[showIdx,],col="gray",lwd=c(1,2,1),lty=c(2,1,2))
legend(x="topright",c(expression(lambda(t)),"95
Run the code above in your browser using DataLab