This repository contains the R and C++ codes that can be used to replicate the empirical results obtained in the paper "Time-varying state correlations in state space models and their estimation via indirect inference" by Caterina Schiavoni, Siem Jan Koopman, Franz Palm, Stephan Smeekes and Jan van den Brakel.
This R script should be run in order to replicate the analyses, since it calls the TV_corr.cpp script.
The R script contains the following functions:
Weights
creates the cubic splines weights.link
is a link function that bounds its argument between -1 and 1.KF_CC_known_corr
performs the Kalman filter estimation (and log-likelihood evaluation) with known values for the time-varying correlation.KF_CC_splines
performs the Kalman filter estimation (and log-likelihood evaluation) of the cubic splines model.KF_CC_const
performs the Kalman filter estimation (and log-likelihood evaluation) of the model with a time-constant correlation.IndInf_CC
performs the estimation of the static parameters of the nonlinear model by indirect inference.
Some inputs are common to many functions. Below you can find the list (in alphabetical order) of all inputs:
beta_hat
is the vector with the maximum likelihood estimates of the static parameters of the cubic splines model, except for the estimated parameter vector (phi) used in the cubic splines specification of the time-varying correlation.d
is the number of state variables for which a diffuse initialisation of the Kalman filter is used.eps_sim
is a matrix withnstates-length(states_noerr)+2
rows andlen
timessim_h
columns, and it contains the generated innovations used in the indirect inference estimation.gamma_draw
is the vector containing the Rao-Blackwellised bootstrap filter estimates of the unbounded version of the correlation parameter (gamma).hyper_tan
: ifTRUE
, it uses the hyperbolic tangent to bound the correlation parameter, otherwise thelink
function.k
is the number of cubic splines knots.knots
is the vector of the observations corresponding to the cubic splines knots.len
is the sample size.nstates
is the number of state variables in the model.opti
: ifTRUE
, it optimises the objective function.outofsample
: ifTRUE
, it computes the log-likelihood based on the out-of-sample forecast errors, from the Kalman filter recursions.par
is the vector of the (inital) values for the static parameters.parP10
is a large number used for the diffuse initialisation of the Kalman filter.restricted
: ifTRUE
, it restricts the model to have a time-constant correlation.se
is thelen
times 5 matrix of the standard errors of the GREG estimates.sim_h
is the number of simulations used in the indirect inference estimation.states_noerr
is a vector of indices for the state variables that do not have an error term in the transition equation.VARgamma
is the variance of the estimated (by maximum likelihood) parameter vector (phi) used in the cubic splines specification of the time-varying correlation.W
is thelen
timesk
matrix of cubic splines weights (it is the output of theWeights
function).y
is the 6 timeslen
matrix that contains the observed series.
Since also some outputs are common to many functions, below you find another list with all (alphabetically ordered) outputs:
logl
is the value of the maximised log-likelihood.opt_fun
is the value of the minimised objective function used in the indirect inference estimation.Ptt
is the list of the estimated (co)variance matrices of the Kalman filter estimates of the state variables.Pttm1
is the list of the predicted (co)variance matrices of the one-step-ahead predictions of the state variables, based on the Kalman filter recursions.st_for
is the matrix with the standardised forecast errors, based on the Kalman filter recursions.W
is thelen
timesk
matrix of cubic splines weights.xtt
is the matrix with the Kalman filter estimates of the state variables.xttm1
is the matrix with the one-step-ahead predictions of the state variables, based on the Kalman filter recursions.
This C++ script contains a first set of functions that are needed in order to perform some mathematical operations. The functions that are instead related to the estimation of the time-varying correlation are:
stratifiedResampling_rcpp
performs the startified resampling step of the Rao-Blackwellised bootstrap filter's algorithm.KF_CC_splines_rcpp
performs the Kalman filter estimation (and log-likelihood evaluation) of the cubic splines model.ucminf_rcpp_splines
maximises the the log-likelihood function evaluated in theKF_CC_splines_rcpp
function.KF_t_rcpp
computes the prediction step of the Kalman filter, for only one point in time (i.e., it does not iterate the Kalman filter recursions over time).boot_filter_CC_rcpp
performs the Rao-blackwellised bootstrap filter estimation of the correlation parameter in the nonlinear model.
Most of the inputs/outputs of the functions included in the C++ script are the same as the ones listed above. We therefore here report only the addtional ones.
draw_m
andM
both corresponds the number of particles used for the Rao-Blackwellised bootstrap filter.init_gamma
is the value that is used to initialise the Rao-Blackwellised bootstrap filter of gamma (the unbounded version of the correlation parameter).init_val
is the vector of the inital values for the static parameters.Rsel
is selection matrix of the innovations in the transition equation.tau_hat
is the vector with the indirect inference estimates of the static parameters of the nonlinear model, except for the estimate of the variance of the innovation in the transition equation for the unbounded version of the correlation parameter (gamma).w
is a vector of unstandardised weights calculated for the resampling step of the Rao-Blackwellised bootstrap filter's algorithm.
Notice that in the KF_t_rcpp
function, the inputs se
, xttm1
and y
are vectors instead of matrices, and Pttm1
is a matrix instead of a list.
att_BF
is the vector containing the Rao-Blackwellised bootstrap filter estimates of the unbounded version of the correlation parameter (gamma).CV
is the vector containing the values for the coefficient of variation, calculated in the Rao-Blackwellised bootstrap filter's algorithm.ESS
is the vector containing the values for the effective sample size, calculated in the Rao-Blackwellised bootstrap filter's algorithm.Ptt_BF
is the vector containing the estimated variances of the Rao-Blackwellised bootstrap filter estimates of the unbounded version of the correlation parameter (gamma).resample_set
is a vector of indices for the particles that have been resampled.