Package 'cif'

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

Help Index


computes at which observation a vector y crosses ref for the first time

Description

Computes at which observation vector yfor crosses yref for the first time if it is not crossed, then 0 is returned

Usage

crossing(yfor, ref = 0)

Arguments

yfor

yfor is either a vector and a matrix

ref

ref is the refence value

Value

whensign, a matrix with observation number at which there is crossing

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


appends NA at beginning of diff(y)

Description

appends NA at beginning of diff(y) and creates column names accordingly when y is either a vector and a matrix

Usage

diffe(y)

Arguments

y

either a vector and a matrix

Value

Dy contains the differences of y, with NA appended at the start

Author(s)

P. Paruolo

References

Berta et al. 2020


computes companion matrix of the VAR

Description

builds the companion matrix of the VAR

Usage

ec.companion(est, p = 2, nlag = 4)

Arguments

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

Value

mA companion matrix

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


prepares deterministics D^(1)

Description

Prepares deterministic data

Usage

ec.datadet1(n, befpn, breaks)

Arguments

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

Value

matdet1 a matrix with the following columns (1_vec, t_vec) and (n+npred) rows

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


prepares deterministics D^(2)

Description

Prepares deterministic dummies for de-meaned daily seasonal and difference point dummies

Usage

ec.datadet2(det1, booseas = NA, pntdates = NA)

Arguments

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

Value

det2mat a matrix with the following columns (daily_seas, point_dummies) and n+npred rows

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


prepares Dy y_1 Dy_1 ... Dy_nlag-1 for estimation

Description

Prepares data for estimation

Usage

ec.datalag(y, nlag = 4)

Arguments

y

is the data matrix of variables in the VAR

nlag

is the number of lags in the VAR (min = 2)

Value

ymat contains the folloiwing columns Dy y_1 Dy_1 ... Dy_nlag-1

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


estimates the VECM with the 2-stage procedure of Engle & Granger

Description

Estimates the EC with EG. Cointegration rank fixed at 1

Usage

ec.EG1(det1, det2, ymat, npl, befpn, ndet, drop1 = NA, drop2 = NA)

Arguments

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

Value

out a list with estimates

Author(s)

P. Berta, P. Paruolo, S. Verzillo, P.G. Lovaglio

References

Berta et al. 2020


plots forecasts of difference with confidence bars

Description

plots forecasts of difference with confidence bars

Usage

ec.gfd(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)

Arguments

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

Value

does not return output, just creates a graph

Author(s)

P. Paruolo,


plots level forecasts with confidence bars

Description

plots level forecasts with confidence bars

Usage

ec.gfl(obj, whichseries = 1, nsigma = 3, xvec, yvec, cal, lar = 0.025, ...)

Arguments

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

Value

does not return output, just creates a graph

Author(s)

P. Paruolo


ec.gfld plots forecasts of levels and difference with confidence bars

Description

plots forecasts of levels and difference with confidence bars

Usage

ec.gfld(
  obj,
  whichseries = 1,
  nsigma = 3,
  jointboo = TRUE,
  epsboo = TRUE,
  filename = "whatever",
  xvec,
  yvec,
  cal,
  lar = 0.025,
  ...
)

Arguments

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

Value

does not return output, just creates a double graph

Author(s)

P. Paruolo


Computes Indices of Forecast Performance

Description

indices of forecast performance

Usage

ec.ifp(afdlin, rwsigma, rwabsmean, kval = 1.959964)

Arguments

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

Value

list of indices of forecast performance 1: index for model forecast 0: index for Random Walk forecast

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


Forecast with Vector Error Correction Model

Description

This function estimate VECM model. Selects begtrim and entrim period, define lag and run.

Usage

ec.main(
  y,
  ndet = c(2, 1),
  nlag,
  befpn,
  breaks = NA,
  booseas = NA,
  pntdates = NA,
  drop1 = NA,
  drop2 = NA,
  cal,
  kval = 1.959964
)

Arguments

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

Value

results Output contains the a set of estimates and forecasting results.

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


plots forecasts

Description

plot actual and forecast intervals

Usage

ec.plotfor(
  y,
  x = NA,
  lcolact = NA,
  lcolfor = NA,
  ltypefor = NA,
  polycol = NA,
  myylim = NA,
  ...
)

Arguments

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

Value

does not return output, just creates a graph

Author(s)

P. Paruolo

References

Berta et al. 2020


Companion matrix of the VAR

Description

plots roots and the unit circle

Usage

ec.plotroots(roots)

Arguments

roots

are the roots of the companion matrix, see ec.companion.R

Value

does not return output, just creates a graph

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


produces predictions for the VECM via its VAR companion form

Description

Predicts both in-sample (1 step ahead) and out-of-sample (1 step ahead and dynamic forecasts)

Usage

ec.predict(est, det1, det2, ymat, npl, befpn, ndet, cal, kval = 1.959964)

Arguments

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

Value

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)

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


search for breaks dates for given q (=1,2,3,4)

Description

Search for location of break points in 1st-stage of Engle-Granger

Usage

ec.searchbreaks(qse, ymat, npl, befpn, ndet, gfillmin = 10, fixed = NA)

Arguments

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)

Value

out list with break dates and values of regression average sum of squares

Author(s)

P. Paruolo

References

Berta et al. 2020


Data from Italian Civil Protection

Description

Data from Italian Civil Protection

Usage

data(iculomb)

Format

A dataset including 324 obs and 24 columns.

Source

https://github.com/pcm-dpc/COVID-19/

References

Italian Civil Protection

Examples

data(iculomb)

lag j of matrix or vector y

Description

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

Usage

lagn(y, j, fill = NA)

Arguments

y

column vector or matrix

j

number of lags

fill

value to be used to fill the missing values at the beginning, default = NA

Value

y lagged j cells, with fill in the missing j positions

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


listsize number of terms in the search for 1,2,3,4 number of breaks

Description

computes length-4 vector with number of terms in the search for 1,2,3,4 number of breaks

Usage

listsize(myT, gfill, start)

Arguments

myT

sample size

gfill

number of gap periods

start

beginning

Value

a vector of 4 elements, with the number of candidate models for 1,2,3,4 breaks

Author(s)

P. Paruolo


Multivariate Least-Squares regression

Description

Multivariate Least-Squares regression y = x beta + u

Usage

mls(y, x, df_flag = FALSE)

Arguments

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

Value

out regression coefficients and related statistics

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


summary function for cif

Description

Summary function for presize

Usage

## S3 method for class 'cif'
summary(object, ..., digits = 4)

Arguments

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.

Value

returns summary output from model estimation and forecasting

Author(s)

P. Berta, P. Paruolo, S. Verzillo, PG. Lovaglio

References

Berta et al. 2020


Wald test for Multivariate Least-Squares regression

Description

Wald test for multivariate Least-Squares regression

Usage

Wald.mls(mlsresults)

Arguments

mlsresults

output of mls, mlsresults<-mls(y, x, df_flag)

Value

wald table of Wald tests on significance of single regressors and pvalues based on chi square distribution

Author(s)

P. Paruolo

References

Berta et al. 2020