Title: | Cointegrated ICU Forecasting |
---|---|
Description: | Set of forecasting tools to predict ICU beds using a Vector Error Correction model with a single cointegrating vector. Method described in Berta, P. Lovaglio, P.G. Paruolo, P. Verzillo, S., 2020. "Real Time Forecasting of Covid-19 Intensive Care Units demand" Health, Econometrics and Data Group (HEDG) Working Papers 20/16, HEDG, Department of Economics, University of York, <https://www.york.ac.uk/media/economics/documents/hedg/workingpapers/2020/2016.pdf>. |
Authors: | Paolo Berta [aut], Paolo Paruolo [aut, cre] , Stefano Verzillo [ctb], Pietro Giorgio Lovaglio [ctb] |
Maintainer: | Paolo Paruolo <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-12-24 06:47:51 UTC |
Source: | CRAN |
Computes at which observation vector yfor crosses yref for the first time if it is not crossed, then 0 is returned
crossing(yfor, ref = 0)
crossing(yfor, ref = 0)
yfor |
yfor is either a vector and a matrix |
ref |
ref is the refence value |
whensign, a matrix with observation number at which there is crossing
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
appends NA at beginning of diff(y) and creates column names accordingly when y is either a vector and a matrix
diffe(y)
diffe(y)
y |
either a vector and a matrix |
Dy contains the differences of y, with NA appended at the start
P. Paruolo
Berta et al. 2020
builds the companion matrix of the VAR
ec.companion(est, p = 2, nlag = 4)
ec.companion(est, p = 2, nlag = 4)
est |
is the output of ec.EG1.R |
p |
(positive integer) is the dimension of the VAR |
nlag |
(positive integer) is the number of lags in the VAR |
mA companion matrix
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Prepares deterministic data
ec.datadet1(n, befpn, breaks)
ec.datadet1(n, befpn, breaks)
n |
is the number of obs in available data |
befpn |
is a vector with (begtrim,endtrim,nforecast,npred,nhstar) |
breaks |
is a vector of integers where the trend breaks should be |
matdet1 a matrix with the following columns (1_vec, t_vec) and (n+npred) rows
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Prepares deterministic dummies for de-meaned daily seasonal and difference point dummies
ec.datadet2(det1, booseas = NA, pntdates = NA)
ec.datadet2(det1, booseas = NA, pntdates = NA)
det1 |
is the det term with constant and trend created by ec.datadet1.R |
booseas |
is a boolean for daily seasonal dummies |
pntdates |
is a vector of integers where the point dummies should be |
det2mat a matrix with the following columns (daily_seas, point_dummies) and n+npred rows
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Prepares data for estimation
ec.datalag(y, nlag = 4)
ec.datalag(y, nlag = 4)
y |
is the data matrix of variables in the VAR |
nlag |
is the number of lags in the VAR (min = 2) |
ymat contains the folloiwing columns Dy y_1 Dy_1 ... Dy_nlag-1
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Estimates the EC with EG. Cointegration rank fixed at 1
ec.EG1(det1, det2, ymat, npl, befpn, ndet, drop1 = NA, drop2 = NA)
ec.EG1(det1, det2, ymat, npl, befpn, ndet, drop1 = NA, drop2 = NA)
det1 |
deterministic matrix of constant(s) and trend(s) |
det2 |
deterministic matrix of seasonals and point dummies |
ymat |
matrix of lags |
npl |
n, p, nlag |
befpn |
begtrim, endtrim, nforecast, npred |
ndet |
order of the model d(i,j) |
drop1 |
selection of det1 regressors in first stage to drop |
drop2 |
selection of det1 regressors in second stage to drop |
out a list with estimates
P. Berta, P. Paruolo, S. Verzillo, P.G. Lovaglio
Berta et al. 2020
plots forecasts of difference with confidence bars
ec.gfd(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)
ec.gfd(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)
obj |
output of ec.main |
whichseries |
series number |
nsigma |
how many standard deviations in confidence bars |
xvec |
vector of dates to place on x axis |
yvec |
vector of exp(y) values to display on y axis |
cal |
calendar vector |
lar |
length of arrows in error bars |
... |
other plot parameters |
does not return output, just creates a graph
P. Paruolo,
plots level forecasts with confidence bars
ec.gfl(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)
ec.gfl(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)
obj |
output of ec.main |
whichseries |
series number |
nsigma |
how many standard deviations in confidence bars |
xvec |
vector of dates to place on x axis |
yvec |
vector of exp(y) values to display on y axis |
cal |
calendar vector |
lar |
length of arrows in error bars |
... |
other plot parameters |
does not return output, just creates a graph
P. Paruolo
plots forecasts of levels and difference with confidence bars
ec.gfld( obj, whichseries = 1, nsigma = 3, jointboo = TRUE, epsboo = TRUE, filename = "whatever", xvec, yvec, cal, lar = 0.025, ... )
ec.gfld( obj, whichseries = 1, nsigma = 3, jointboo = TRUE, epsboo = TRUE, filename = "whatever", xvec, yvec, cal, lar = 0.025, ... )
obj |
output of ec.main |
whichseries |
series number |
nsigma |
how many standard deviations in confidence bars |
jointboo |
boolean: TRUE if 1x2 graph, FALSE otherwise |
epsboo |
boolean: TRUE eps graph, FALSE pdf graph |
filename |
string, name of the file (no extension) |
xvec |
vector of dates to place on x axis |
yvec |
vector of exp(y) values to display on y axis |
cal |
calendar vector |
lar |
length of arrows in error bars |
... |
other plot parameters |
does not return output, just creates a double graph
P. Paruolo
indices of forecast performance
ec.ifp(afdlin, rwsigma, rwabsmean, kval = 1.959964)
ec.ifp(afdlin, rwsigma, rwabsmean, kval = 1.959964)
afdlin |
actual + forecast values + fcse |
rwsigma |
standard deviation of Random Walk in sample |
rwabsmean |
mean absolute deviation of Random Walk in sample |
kval |
how many se to use, default kval = 1.959964 |
list of indices of forecast performance 1: index for model forecast 0: index for Random Walk forecast
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
This function estimate VECM model. Selects begtrim and entrim period, define lag and run.
ec.main( y, ndet = c(2, 1), nlag, befpn, breaks = NA, booseas = NA, pntdates = NA, drop1 = NA, drop2 = NA, cal, kval = 1.959964 )
ec.main( y, ndet = c(2, 1), nlag, befpn, breaks = NA, booseas = NA, pntdates = NA, drop1 = NA, drop2 = NA, cal, kval = 1.959964 )
y |
matrix with time across rows and variables in columns |
ndet |
vector of lenght 3, (i,j,q): i for EG1-st stage, j for EG-2nd stage, q number of breaks i,j=0 no deterministics i,j=1 constant i,j=2 constant and trend |
nlag |
number of lags in the VAR |
befpn |
begtrim, endtrim, nforecast, npred |
breaks |
vector with observation numbers for T1,T2,... |
booseas |
boolean =T if seasonal dummies, =F otherwise |
pntdates |
vector with observation numbers for point dummies |
drop1 |
selection of det1 regressors in first stage to drop |
drop2 |
selection of det1 regressors in second stage to drop |
cal |
calendar for the y matrix |
kval |
how many se to use, default kval=1.959964 |
results Output contains the a set of estimates and forecasting results.
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
plot actual and forecast intervals
ec.plotfor( y, x = NA, lcolact = NA, lcolfor = NA, ltypefor = NA, polycol = NA, myylim = NA, ... )
ec.plotfor( y, x = NA, lcolact = NA, lcolfor = NA, ltypefor = NA, polycol = NA, myylim = NA, ... )
y |
actual values and forecasts (point forecast, lower bound, upper bound) |
x |
time calendar |
lcolact |
color actual (scalar) |
lcolfor |
color forecasts |
ltypefor |
type forecasts |
polycol |
color polygons if one wishes to have different lcolfor,ltypefor,polycol by week > make linecol, linetype, polycol vectors, indexed by week |
myylim |
vector with min and max for y axis |
... |
other plot parameters |
does not return output, just creates a graph
P. Paruolo
Berta et al. 2020
plots roots and the unit circle
ec.plotroots(roots)
ec.plotroots(roots)
roots |
are the roots of the companion matrix, see ec.companion.R |
does not return output, just creates a graph
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Predicts both in-sample (1 step ahead) and out-of-sample (1 step ahead and dynamic forecasts)
ec.predict(est, det1, det2, ymat, npl, befpn, ndet, cal, kval = 1.959964)
ec.predict(est, det1, det2, ymat, npl, befpn, ndet, cal, kval = 1.959964)
est |
output from estimation by ec.EG1.R |
det1 |
deterministic matrix of constant(s) and trend(s) |
det2 |
deterministic matrix of seasonals and point dummies |
ymat |
matrix of lags |
npl |
n, p, nlag |
befpn |
begtrim, endtrim, nforecast, npred, nhstar |
ndet |
order of the model d(i,j) |
cal |
calendar, should match the number of rows in ymat |
kval |
how many se to use, default kval= 1.959964 |
list with contains: afl (actual and 1 step ahead fitted levels) afd (actual and 1 step ahead fitted differences) fit (1 step ahead fit) dynpred (dynamic predictions) mAt mB (companion matrix and selection of it) Sigmah (Sigmah for dyn forecasts) forstartdate (starting date for dyn forecast) outcal (dates for the prediction) h1star (h1star) cspred (table with change in sign of pred for Dx_1) indexfa (indices of forecast accuracy)
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Search for location of break points in 1st-stage of Engle-Granger
ec.searchbreaks(qse, ymat, npl, befpn, ndet, gfillmin = 10, fixed = NA)
ec.searchbreaks(qse, ymat, npl, befpn, ndet, gfillmin = 10, fixed = NA)
qse |
q: number of (additional) breaks, s: start date for search, e: end date for search |
ymat |
matrix of lags |
npl |
n, p, nlag |
befpn |
begtrim, endtrim, nforecast, npred |
ndet |
order of the model d(i,j) |
gfillmin |
gfill value |
fixed |
vector of breaks to be taken as fixed (not between s=start and e=end) |
out list with break dates and values of regression average sum of squares
P. Paruolo
Berta et al. 2020
Data from Italian Civil Protection
data(iculomb)
data(iculomb)
A dataset including 324 obs and 24 columns.
https://github.com/pcm-dpc/COVID-19/
Italian Civil Protection
data(iculomb)
data(iculomb)
lagn(y,j,fill=NA) produces lag j of matrix or vector y, with fill in missing j cells REM: alternative to "lead-lag" dplyr which applies to vector y
lagn(y, j, fill = NA)
lagn(y, j, fill = NA)
y |
column vector or matrix |
j |
number of lags |
fill |
value to be used to fill the missing values at the beginning, default = NA |
y lagged j cells, with fill in the missing j positions
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
computes length-4 vector with number of terms in the search for 1,2,3,4 number of breaks
listsize(myT, gfill, start)
listsize(myT, gfill, start)
myT |
sample size |
gfill |
number of gap periods |
start |
beginning |
a vector of 4 elements, with the number of candidate models for 1,2,3,4 breaks
P. Paruolo
Multivariate Least-Squares regression y = x beta + u
mls(y, x, df_flag = FALSE)
mls(y, x, df_flag = FALSE)
y |
left hand side data matrix (one or more columns) |
x |
right hand side data matrix (one or more columns) |
df_flag |
flag = TRUE for degrees of freedom correction for the variance |
out regression coefficients and related statistics
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Summary function for presize
## S3 method for class 'cif' summary(object, ..., digits = 4)
## S3 method for class 'cif' summary(object, ..., digits = 4)
object |
is the name of the cif object created by cif |
... |
other parameters |
digits |
integer indicating the number of decimal places (round) or significant digits (signif) to be used. |
returns summary output from model estimation and forecasting
P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio
Berta et al. 2020
Wald test for multivariate Least-Squares regression
Wald.mls(mlsresults)
Wald.mls(mlsresults)
mlsresults |
output of mls, mlsresults<-mls(y, x, df_flag) |
wald table of Wald tests on significance of single regressors and pvalues based on chi square distribution
P. Paruolo
Berta et al. 2020