From ccae0f28ac716dbfbc1efe52ea4e8c465742793e Mon Sep 17 00:00:00 2001 From: Franz Mohr Date: Thu, 19 Oct 2023 21:27:40 +0200 Subject: [PATCH] Add post_gamma_state_variance --- R/RcppExports.R | 2 +- man/post_gamma_state_variance.Rd | 2 +- src/post_gamma_state_variance.cpp | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index 5fa2cc0..7893a79 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -476,7 +476,7 @@ post_coint_kls_sur <- function(y, beta, w, sigma_i, v_i, p_tau_i, g_i, x = NULL, #' #' @return A matrix. #' -post_gamma_state_variance <- function(a, a_init, shape_prior, rate_prior, inverse = FALSE) { +post_gamma_state_variance <- function(a, a_init, shape_prior, rate_prior, inverse) { .Call(`_bvartools_post_gamma_state_variance`, a, a_init, shape_prior, rate_prior, inverse) } diff --git a/man/post_gamma_state_variance.Rd b/man/post_gamma_state_variance.Rd index aa95682..f6104fd 100644 --- a/man/post_gamma_state_variance.Rd +++ b/man/post_gamma_state_variance.Rd @@ -4,7 +4,7 @@ \alias{post_gamma_state_variance} \title{Posterior Draws of Error Variances} \usage{ -post_gamma_state_variance(a, a_init, shape_prior, rate_prior, inverse = FALSE) +post_gamma_state_variance(a, a_init, shape_prior, rate_prior, inverse) } \arguments{ \item{a}{a \eqn{K \times T} matrix of time varying parameter draws.} diff --git a/src/post_gamma_state_variance.cpp b/src/post_gamma_state_variance.cpp index 7e420a7..ca4ec9f 100644 --- a/src/post_gamma_state_variance.cpp +++ b/src/post_gamma_state_variance.cpp @@ -50,7 +50,7 @@ //' @return A matrix. //' // [[Rcpp::export]] -arma::mat post_gamma_state_variance(arma::mat a, arma::vec a_init, arma::vec shape_prior, arma::vec rate_prior, bool inverse = false) { +arma::mat post_gamma_state_variance(arma::mat a, arma::vec a_init, arma::vec shape_prior, arma::vec rate_prior, bool inverse) { int k = a.n_rows; int tt = a.n_cols; @@ -59,16 +59,16 @@ arma::mat post_gamma_state_variance(arma::mat a, arma::vec a_init, arma::vec sha a_lag.cols(1, tt - 1) = a.cols(0, tt - 2); arma::mat a_v = arma::trans(a - a_lag); arma::vec psi_sigma_v_post_scale = 1 / (rate_prior + arma::vectorise(arma::sum(arma::pow(a_v, 2))) * 0.5); - arma::mat psi_sigma = arma::zeros(k, k); + arma::mat result = arma::zeros(k, k); arma::vec shape_post = shape_prior + tt * 0.5; for (int i = 0; i < k; i++) { - psi_sigma(i, i) = arma::randg(arma::distr_param(shape_post(i), psi_sigma_v_post_scale(i))); - if (inverse) { - psi_sigma(i, i) = 1 / psi_sigma(i, i); + // Inverse + result(i, i) = arma::randg(arma::distr_param(shape_post(i), psi_sigma_v_post_scale(i))); + if (!inverse) { + result(i, i) = 1 / result(i, i); } } - - return psi_sigma; + return result; } /*** R