Skip to content

Instantly share code, notes, and snippets.

@kieranrcampbell
Created October 25, 2016 11:27
Show Gist options
  • Save kieranrcampbell/c016616b4641ea27476214f913109ac3 to your computer and use it in GitHub Desktop.
Save kieranrcampbell/c016616b4641ea27476214f913109ac3 to your computer and use it in GitHub Desktop.
// [[Rcpp::export]]
NumericMatrix sample_tau_pg(NumericMatrix beta,
double a_beta, double b_beta) {
int P = beta.nrow();
int G = beta.ncol();
NumericMatrix tau_pg(P, G);
for(int p = 0; p < P; p++) {
for(int g = 0; g < G; g++) {
double beta_new = b_beta + beta(p,g) * beta(p,g) / 2;
tau_pg(p,g) = as<double>(rgamma(1, a_beta + 1, 1 / beta_new));
}
}
return tau_pg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment