/Bayesian-multivariate-time-series-causal-inference

R code for ''Bayesian method for causal inference in spatially-correlated multivariate time series''

Primary LanguageR

Bayesian multivariate time series causal inference

We provide the R code for the new Bayesian causal inference method proposed in our paper: Bayesian method for causal inference in spatially-correlated multivariate time series (https://arxiv.org/abs/1801.06282).

The multivariate basic structural time series model is:

Two-stage algorithm

Stage 1: EMVS step

Use EMVS algorithm to estimate beta and obtain EMVS

Stage 2: MCMC step

(a) Generate alpha using the Kalman-filter and simulation smoother method

(b) Generate phi using the Metropolis-Hastings algorithm

(c) Generate D from its posterior

(d) Generate covariance matrices from their respective G-Wishart posterior

(e) Go to Step (a) and repeat until the chain converges.

Skip Step (b) and (c) if no stationarity restriction is imposed on tau

The folder includes:

example.R: uses to simulate a dataset. The simulation process the same as the one described in that paper.

BayesianCausalImpact folder: includes the code for runing the causal inference analysis

-- two.stage.estimate.R: the main code for the two-stage algorithm

-- estimate.counterfactual.R: the code for the EMVS step in the two-stage algorithm, the output is Ytilde

-- EMVS.R: the code for the EMVS algorithm

-- MCMC.multivariate.ssm.R: the code for the MCMC step in the two-stage algorithm, the outputs are the parameter posterior draws

-- koopmanfilter.R: the code for the Kalman filter and simulation smoother algorithm

-- kalmflter.R: the code for the Kalman-filter and Backward smoother algorithm

-- stationaryRestrict.R & varp.R: the codes for making stationarity constraint on tau

-- MultiCausalImpact.R: the code for conducting our new causal inference method

-- MungeMatrix.R: the code to convert a computationally singular matrix into a non-singular matrix

-- ks.distance-plot.R: the code for generating plots of estimated KS distances and thresholds