Skip to contents

Implements a generalized Kishor-Koenig (KK) model for nowcasting and forecasting with state-space models, allowing for multiple vintages of data, efficient estimation, and Kalman filtering and smoothing.

Usage

kk_nowcast(
  df,
  e,
  h = 0,
  model = "Kishor-Koenig",
  method = "SUR",
  solver_options = list()
)

Arguments

df

A data frame containing the time series data in either "long" or "wide" format. It must include columns for the time index and the different release vintages.

e

An integer indicating the number of data vintages to include in the model. Must be greater than 0.

h

An integer specifying the forecast horizon. Default is 0, which implies no forecasts. Must be greater than or equal to 0.

model

A string specifying the type of model to use. Options are:

  • "Kishor-Koenig" or "KK" (default): Full Kishor-Koenig model.

  • "Howrey": Howrey's simplified framework.

  • "Classical": Classical model without vintage effects.

method

A string specifying the estimation method to use. Options are "SUR" (default) and "OLS".

solver_options

An optional list to control the behaviour of the underlying systemfit::nlsystemfit() and stats::nlm() solvers:

  • trace: An integer controlling the level of output for the optimization procedure. Default is 0 (minimal output).

  • maxiter: An integer specifying the maximum number of iterations for the optimization procedure. Default is 1000.

  • startvals: A list of starting values for the optimization procedure (must match the number of parameters of the model).

  • solvtol: Tolerance for detecting linear dependencies in the columns of X in the qr function calls (See systemfit::nlsystemfit()). Default is .Machine$double.eps.

  • gradtol: A a positive scalar giving the tolerance at which the scaled gradient is considered close enough to zero to terminate the algorithm (See stats::nlm()). Default is 1e-6.

  • steptol: A positive scalar providing the minimum allowable relative step length (See stats::nlm()). Default is 1e-6.

Value

A list with the following components:

filtered_z

A tibble of filtered latent state variables based on the Kalman filter.

filtered_y

A tibble of filtered observed variables based on the Kalman filter.

smoothed_z

A tibble of smoothed latent state variables obtained using the Kalman smoother.

smoothed_y

A tibble of smoothed observed variables obtained using the Kalman smoother.

forecast_z

A tibble of forecasted latent state variables. Returned only if h > 0.

forecast_y

A tibble of forecasted observed variables. Returned only if h > 0.

kk_model_mat

A list of KK model matrices, such as transition and observation matrices.

ss_model_mat

A list of state-space model matrices derived from the KK model.

params

Estimated model parameters, including covariance terms.

fit

The fitted model object from the SUR estimation procedure.

e

The number of the efficient release (0-indexed).

data

The input data in wide format.

Details

The function supports multiple models, including the full Kishor-Koenig framework, Howrey's model, and a classical approach. It handles data preprocessing, estimation of system equations using Seemingly Unrelated Regressions (SUR), and application of the Kalman filter and smoother. This is the first openly available implementation of the Kishor-Koenig model (See the vignette vignette("nowcasting_revisions") for more details).

References

Kishor, N. Kundan and Koenig, Evan F., "VAR Estimation and Forecasting When Data Are Subject to Revision", Journal of Business and Economic Statistics, 2012.

Examples

# Example usage:
df <- get_nth_release(
  tsbox::ts_span(
    tsbox::ts_pc(
      dplyr::filter(reviser::gdp, id=="US")
      ),
      start = "1980-01-01"
     ),
     n = 0:1
   )
df <- dplyr::select(df, -c(id, pub_date))
df <- na.omit(df)

e <- 1  # Number of efficient release
h <- 2  # Forecast horizon
model_result <- kk_nowcast(df, e, h = h, model = "Kishor-Koenig")

model_result$params
#>           F0         G0_0         G0_1           v0         eps0 
#>  0.200853533  0.995630065 -0.001694615  1.598322193  0.006664367