美文网首页大数据部落大数据大数据,机器学习,人工智能
随机搜索变量选择SSVS估计贝叶斯向量自回归(BVAR)模型

随机搜索变量选择SSVS估计贝叶斯向量自回归(BVAR)模型

作者: 拓端tecdat | 来源:发表于2020-03-25 15:18 被阅读0次

原文链接:http://tecdat.cn/?p=9390

介绍

向量自回归(VAR)模型的一般缺点是,估计系数的数量与滞后的数量成比例地增加。因此,随着滞后次数的增加,每个参数可用的信息较少。在贝叶斯VAR文献中,减轻这种所谓的维数诅咒的一种方法是随机搜索变量选择(SSVS),由George等人提出(2008)。SSVS的基本思想是将通常使用的先验方差分配给应包含在模型中的参数,将不相关参数的先验方差接近零。这样,通常就可以估算出相关参数,并且无关变量的后验值接近于零,因此它们对预测和冲激响应没有显着影响。这是通过在模型之前添加层次结构来实现的,其中在采样算法的每个步骤中评估变量的相关性。

这篇文章介绍了使用SSVS估计贝叶斯向量自回归(BVAR)模型。它使用Lütkepohl(2007)的数据集E1,其中包含有关1960Q1至1982Q4十亿德国马克的西德固定投资,可支配收入和消费支出的数据。加载数据并生成数据:

<- diff(log(e1))\n\n# Generate VAR\ndata <- gen_var(e1, p = 4, deterministic = \"const\")\n\n# Get data matrices\ny <- data$Y[, 1:71]\nx <- data$Z[, 1:71]","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet">library(bvartools) # install.packages("bvartools") # Load and transform data data("e1") e1 <- diff(log(e1)) # Generate VAR data <- gen_var(e1, p = 4, deterministic = "const") # Get data matrices y <- data$Y[, 1:71] x <- data$Z[, 1:71]

need-to-insert-img

估算值

根据George等人所述的半自动方法来设置参数的先验方差(2008)。对于所有变量,先验包含概率设置为0.5。误差方差-协方差矩阵的先验信息不足。

<- ncol(y) # Number of observations\nk <- nrow(y) # Number of endogenous variables\nm <- k * nrow(x) # Number of estimated coefficients\n\n# Coefficient priors\na_mu_prior <- matrix(0, m) # Vector of prior means\n\n# SSVS priors (semiautomatic approach)\nols <- tcrossprod(y, x) %*% solve(tcrossprod(x)) # OLS estimates\nsigma_ols <- tcrossprod(y - ols %*% x) / (t - nrow(x)) # OLS error covariance matrix\ncov_ols <- kronecker(solve(tcrossprod(x)), sigma_ols)\nse_ols <- matrix(sqrt(diag(cov_ols))) # OLS standard errors\n\ntau0 <- se_ols * 0.1 # Prior if excluded\ntau1 <- se_ols * 10 # Prior if included\n\n# Prior for inclusion parameter\nprob_prior <- matrix(0.5, m)\n\n# Prior for variance-covariance matrix\nu_sigma_df_prior <- 0 # Prior degrees of freedom\nu_sigma_scale_prior <- diag(0, k) # Prior covariance matrix\nu_sigma_df_post <- t + u_sigma_df_prior # Posterior degrees of freedom","classes":{"has":1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"># Reset random number generator for reproducibility set.seed(1234567) t <- ncol(y) # Number of observations k <- nrow(y) # Number of endogenous variables m <- k * nrow(x) # Number of estimated coefficients # Coefficient priors a_mu_prior <- matrix(0, m) # Vector of prior means # SSVS priors (semiautomatic approach) ols <- tcrossprod(y, x) %*% solve(tcrossprod(x)) # OLS estimates sigma_ols <- tcrossprod(y - ols %*% x) / (t - nrow(x)) # OLS error covariance matrix cov_ols <- kronecker(solve(tcrossprod(x)), sigma_ols) se_ols <- matrix(sqrt(diag(cov_ols))) # OLS standard errors tau0 <- se_ols * 0.1 # Prior if excluded tau1 <- se_ols * 10 # Prior if included # Prior for inclusion parameter prob_prior <- matrix(0.5, m) # Prior for variance-covariance matrix u_sigma_df_prior <- 0 # Prior degrees of freedom u_sigma_scale_prior <- diag(0, k) # Prior covariance matrix u_sigma_df_post <- t + u_sigma_df_prior # Posterior degrees of freedom

need-to-insert-img

初始参数值设置为零,这意味着在Gibbs采样器的第一步中应相对自由地估算所有参数。

可以直接将SSVS添加到VAR模型的标准Gibbs采样器算法中。在此示例中,常数项从SSVS中排除,这可以通过指定来实现include = 1:36。

具有SSVS的Gibbs采样器的输出可以用通常的方式进一步分析。因此,可以通过计算参数的绘制方式获得点估计:

## invest income cons ## invest.1 -0.102 0.011 -0.002 ## income.1 0.044 -0.031 0.168 ## cons.1 0.074 0.140 -0.287 ## invest.2 -0.013 0.002 0.004 ## income.2 0.015 0.004 0.315 ## cons.2 0.027 -0.001 0.006 ## invest.3 0.033 0.000 0.000 ## income.3 -0.008 0.021 0.013 ## cons.3 -0.043 0.007 0.019 ## invest.4 0.250 0.001 -0.005 ## income.4 -0.064 -0.010 0.025 ## cons.4 -0.023 0.001 0.000 ## const 0.014 0.017 0.014

还可以通过计算变量的均值来获得每个变量的后验概率。从下面的输出中可以看出,在VAR(4)模型中似乎只有几个变量是相关的。常数项的概率为100%,因为它们已从SSVS中排除。

## invest income cons ## invest.1 0.43 0.23 0.10 ## income.1 0.10 0.18 0.67 ## cons.1 0.11 0.40 0.77 ## invest.2 0.11 0.09 0.14 ## income.2 0.08 0.07 0.98 ## cons.2 0.07 0.06 0.08 ## invest.3 0.19 0.07 0.06 ## income.3 0.06 0.13 0.10 ## cons.3 0.09 0.07 0.12 ## invest.4 0.78 0.09 0.16 ## income.4 0.13 0.09 0.18 ## cons.4 0.09 0.07 0.06 ## const 1.00 1.00 1.00

给定这些值,研究人员可以按照常规方式进行操作,并根据Gibbs采样器的输出获得预测和脉冲响应。这种方法的优势在于它不仅考虑了参数不确定性,而且还考虑了模型不确定性。这可以通过系数的直方图来说明,该直方图描述了收入的第一个滞后项与消费当前值之间的关系。

相关文章

网友评论

    本文标题:随机搜索变量选择SSVS估计贝叶斯向量自回归(BVAR)模型

    本文链接:https://www.haomeiwen.com/subject/ibxxuhtx.html