get_nowcast: Get nowcast from the bayesian DFM

Description Usage Arguments Value Examples

View source: R/get_nowcast.R

Description

function extends the data matrix by the forecasting period, draw extended factor conditional on posterior parameters and makes forecast.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
get_nowcast(
  Xmat,
  s,
  q,
  alpha_0,
  P_0,
  inventory,
  target,
  flows,
  lambda_mean,
  phi_mean,
  R_mean,
  Q_mean,
  const
)

Arguments

Xmat

Demeaned and standardized matrix of time series data.

s

Number of periods for aggregation rule.

q

Lag length for state equation.

alpha_0

Vector of dimension m x 1 (Initial conditions for Kalman filter).

P_0

Diagonal matrix of dimension m (Initial conditions for Kalman filter).

inventory

Inventory of the corresponding data.

target

Defines the target variable.

flows

A list of time series variable (flow variables).

lambda_mean

A vector of dimension n x k of the posterior mean factor loadings.

phi_mean

Diagonal matrix of dimension k x k with vector of posterior mean autoregressive coefficients.

R_mean

Diagonal matrix of dimension n of posterior mean idiosyncratic component.

Q_mean

matrices of posterior mean variance covariance matrices.

const

A scalar, where const = 1 for model with intercept, const = 0 for model without intercept.

Value

A time series of the target variable including forecast.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
yt <- as.matrix(t(Xmat))
k <- 2
n <- dim(yt)[1]
q <- 1
const <- 0
m <- k*q
s <- 2*(k - 1)
alpha_0 <- matrix(0,m,1)
P_0 <- diag(m)
inventory <- create_inventory(flows = data$flows, stocks = data$stocks)
target <- c("UKGDPM.YQ")
flows = data$flows
out$lambda_mean <- apply(simplify2array(out$lambda_all), 1:2, mean)
out$phi_mean <- apply(simplify2array(out$phi_all), 1:2, mean)
out$Q_mean <- apply(simplify2array(out$Q_all), 1:2, mean)
out$R_mean <- apply(simplify2array(out$R_all), 1:2, mean)
out$ncst <- get_nowcast(Xmat = Xmat, s = s, q = q, alpha_0 = alpha_0,
P_0 = P_0, inventory = inventory, target = target, flows = flows,
lambda_mean = out$lambda_mean, phi_mean = out$phi_mean, R_mean = out$R_mean,
Q_mean = out$Q_mean, const = const)

h4sci/packagr documentation built on Jan. 7, 2021, 10:40 p.m.