Raw File
Tip revision: be291479202d9ca826914b9bf0fe0b8efa26e6c3 authored by Martin Lysy on 22 August 2022, 08:20:12 UTC
version 1.1.4
Tip revision: be29147
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/
\title{Posterior sampling from a hierarchical Unconstrained-Multinomial model}
\usage{, X, popId, rhoId, full.stan.out = FALSE, ...)
\item{nsamples}{Number of posterior samples}

\item{X}{4-column or 5-column matrix of observations in the correct format.  See \code{\link{UM.suff}}.}

\item{popId}{Optional vector of population identifiers.  See \code{\link{UM.suff}}.}

\item{rhoId}{Populations for which posterior samples of the genotype probability vector \code{rho} are desired.  Defaults to all populations.  Set \code{rhoId = NULL} not to output these for any populations.}

\item{full.stan.out}{Logical.  Whether or not to return the full \code{stan} output.  For monitoring convergence of the MCMC sampling.}

\item{...}{Further arguments to be passed to the \code{\link[rstan]{sampling}} function in \pkg{rstan}.}
A list with elements
  \item \code{A}: The unique allele names.
  \item \code{G}: The 4-column matrix Package libcurl was not found in the pkg-config search path.of unique genotype combinations.
  \item \code{rho}: A matrix with \code{ncol(rho) == nrow(G)}, where each row is a draw from the posterior distribution of inheritance probabilities.
  \item \code{sfit}: If \code{full.stan.out = TRUE}, the fitted \code{stan} object.
MCMC sampling from a Dirichlet-Multinomial model using \code{\link[rstan]{stan}}.
The hierarchical Dirichlet-Multinomial model is given by
  Y_k \mid \rho_k \sim_{\textrm{ind}} \textrm{Multinomial}(\rho_k, N_k),
  Y_k | \rho_k ~ind Multinomial(\rho_k, N_k),
  \rho_k \sim_{\textrm{iid}} \textrm{Dirichlet}(\alpha).
  \rho_k ~iid Dirichlet(\alpha).
where \eqn{\alpha_0 = \sum_{i=1}^C \alpha_i} and \eqn{\bar \alpha = \alpha/\alpha_0}{\alpha_bar = \alpha/\alpha_0}.  MCMC sampling is achieved with the \pkg{rstan} package, which is listed as a dependency for \pkg{MADPop} so as to expose \pkg{rstan}'s sophisticated tuning mechanism and convergence diagnostics.
# fit hierarchical model to fish215 data

# only output posterior samples for lake Simcoe
rhoId <- "Simcoe"
nsamples <- 500 <- = nsamples, X = fish215,
                    rhoId = rhoId,
                    chains = 1) # number of MCMC chains

# plot first 20 posterior probabilities in lake Simcoe <-$rho[,1,]
boxplot([,1:20], las = 2,
        xlab = "Genotype", ylab = "Posterior Probability",
        pch = ".", col = "grey")
back to top