#' normal_hier
#'
#' Runs Asymmetric Gaussian MCMC with a hierarchical mean structure accross the groups
#'
#' @param y response variable which follows binomial dist
#' @param x explanatory variable
#' @param count n in binomial dist
#' @param group groups of response
#' @param priors list of priors
#' @param niter number of interations to be run (default=2000)
#' @param nchains number of chains to be run (default=3)
#' @param nclusters number of clusters to be used (default=nchains)
#' @param burnin number of samples to be used as burnin (technically adaption, see link below)
#' @param thin when you want to thin (default=10)
#'
#' @seealso \url{http://www.mikemeredith.net/blog/2016/Adapt_or_burn.htm}
#'
#' @return A MCMC object
#'
#' @examples
#' priors <- list()
#' priors$vm <- 10
#' priors$mx <- 15
#' priors$vmx <- 10
#' priors$vs <- 10
#'
#'
#' @export
normal_hier <- function(y, x, count, group, priors, niter=2000, nchains=3, nclusters=nchains, burnin=niter/2, thin=10){
# Load Library
require(R2jags)
# Setup data for model
dat <- list(y=y, x=x, num=count, n=length(y),nG=length(unique(group)), group=as.numeric(group))
# Set priors
dat <- c(dat, priors)
list2env(dat, envir=globalenv() )
# Set up the model in Jags
m = jags.parallel(data=dat,
inits=NULL,
parameters.to.save=c("theta","mu","sigma","beta","nu","m_n","m_x","t_m","t_n","t_beta","t_a","t_b"),
model.file = system.file("model", "n_hier.txt", package = "functform"),
n.chains = nchains,
n.iter = niter,
n.burnin=burnin,
n.thin=thin,
n.cluster= nclusters
)
return(coda::as.mcmc(m))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.