<commit_before>\part{Discrete Distributions}\label{discrete-prob-functions.part}


\chapter{Binary Distributions}

\noindent
Binary probability distributions have support on $\setlist{0,1}$,
where 1 represents the value true and 0 the value false.

\section{Bernoulli Distribution}

\subsubsection{Probability Mass Function}

If $\theta \in [0,1]$, then for $y \in \setlist{0,1}$, 
\[
\distro{Bernoulli}(y|\theta)
=
\left\{
\begin{array}{ll}
\theta & \mbox{if } y = 1, \mbox{ and}
\\
1 - \theta & \mbox{if } y = 0.
\end{array}
\right.
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{bernoulli\_log}{ints \farg{y}, reals \farg{theta}}{The
  log Bernoulli probability mass of \farg{y} given chance of success
  \farg{theta}}
%
\end{description}

\begin{description}
%
\fitem{real}{bernoulli\_cdf}{ints \farg{y}, reals \farg{theta}}{The
  Bernoulli cumulative distribution function of \farg{y} given chance of success
  \farg{theta}}
%
\end{description}
%
\begin{description}
\fitem{int}{bernoulli\_rng}{real \farg{theta}}{Generate a Bernoulli
  variate with chance of success \farg{theta}; may only be used in
  generated quantities block}
\end{description}

\section{Bernoulli Distribution, Logit Parameterization}

\Stan also supplies a direct parameterization in terms of a
logit-transformed chance-of-success parameter.  This parameterization
is more numerically stable if the chance-of-success parameter is on
the logit scale, as with the linear predictor in a logistic
regression.  

\subsubsection{Probability Mass Function}

If $\alpha \in \reals$, then for $c \in \setlist{0,1}$,
\[
\distro{BernoulliLogit}(c|\alpha)
=
\distro{Bernoulli}(c|\mbox{logit}^{-1}(\alpha))
= 
\left\{
\begin{array}{ll}
\mbox{logit}^{-1}(\alpha) & \mbox{if } y = 1, \mbox{ and}
\\
1 - \mbox{logit}^{-1}(\alpha) & \mbox{if } y = 0.
\end{array}
\right.
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{bernoulli\_logit\_log}{ints \farg{y}, reals \farg{alpha}}{The
  log Bernoulli probability mass of \farg{y} given logit chance of success
  \code{exp(\farg{alpha})}}
%
\end{description}



\chapter{Bounded Discrete Distributions}\label{betafun.chapter}

\noindent
Bounded discrete probability functions have support on
$\setlist{0,\ldots,N}$ for some upper bound $N$.


\section{Binomial Distribution}

\subsubsection{Probability Mass Function}

Suppose $N \in \nats$ and $\theta \in [0,1]$, and $n \in
\{0,\ldots,N\}$.
\[
\distro{Binomial}(n|N,\theta)
= {N \choose n} \theta^n (1 - \theta)^{N - n}.
\]


\subsubsection{Log Probability Mass Function}

\begin{eqnarray*}
\log \distro{Binomial}(n|N,\theta)
& = &
\log \Gamma(N+1) - \log \Gamma(n + 1) - \log \Gamma(N- n + 1)
\\[4pt]
& & { } + n \log \theta + (N - n) \log (1 - \theta), 
\end{eqnarray*}


\subsubsection{Gradient of Log Probability Mass Function}

\[
\frac{\partial}{\partial \theta} \log \distro{Binomial}(n|N,\theta)
= \frac{n}{\theta}
- \frac{N - n}{1 - \theta}
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{binomial\_log}{ints \farg{n}, ints \farg{N}, reals
    \farg{theta}}{The log binomial probability mass of \farg{n}
    successes in \farg{N} trials given chance of success \farg{theta}}
%
  \fitem{real}{binomial\_cdf}{ints \farg{n}, ints \farg{N}, reals
    \farg{theta}}{The binomial cumulative distribution function of \farg{n}
    successes in \farg{N} trials given chance of success \farg{theta}}
%
\end{description}
%
\begin{description}
\fitem{int}{binomial\_rng}{int \farg{N}, real \farg{theta}}{Generate a binomial
  variate with \farg{N} trials and chance of success \farg{theta}; may only be used in
  generated quantities block}
\end{description}



\section{Binomial Distribution, Logit Parameterization}

Stan also provides a version of the binomial probability mass function
distribution with the chance of success parameterized on the
unconstrained logistic scale.  

\subsubsection{Probability Mass Function}

Suppose $N \in \nats$, $\alpha \in \reals$, and $n \in
\{0,\ldots,N\}$.

\begin{eqnarray*}
\distro{BinomialLogit}(n|N,\alpha)
& = & \distro{BinomialLogit}(n|N,\mbox{logit}^{-1}(\alpha))
\\[6pt]
& = & {N \choose n} \left( \mbox{logit}^{-1}(\alpha) \right)^{n}
                    \left( 1 - \mbox{logit}^{-1}(\alpha) \right)^{N - n}.
\end{eqnarray*}


\subsubsection{Log Probability Mass Function}

\begin{eqnarray*}
\log \distro{BinomialLogit}(n|N,\alpha)
& = &
\log \Gamma(N+1) - \log \Gamma(n + 1) - \log \Gamma(N- n + 1)
\\[4pt]
& & { } + n \log \mbox{logit}^{-1}(\alpha) + (N - n) \log \left( 1 -
  \mbox{logit}^{-1}(\alpha) \right), 
\end{eqnarray*}


\subsubsection{Gradient of Log Probability Mass Function}

\[
\frac{\partial}{\partial \alpha} \log \distro{BinomialLogit}(n|N,\alpha)
= \frac{n}{\mbox{logit}^{-1}(-\alpha)}
- \frac{N - n}{\mbox{logit}^{-1}(\alpha)}
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{binomial\_logit\_log}{ints \farg{n}, ints \farg{N}, reals
    \farg{alpha}}{The log binomial probability mass of \farg{n}
    successes in \farg{N} trials given logit-scaled chance of success \farg{alpha}}
%
\end{description}



\section{Beta-Binomial Distribution}

\subsubsection{Probability Mass Function}

If $N \in \nats$, $\alpha \in \posreals$, and $\beta \in \posreals$,
then for $n \in \setlist{0,\ldots,N}$,
\[
\distro{BetaBinomial}(n|N,\alpha,\beta)
= 
{N \choose n} \frac{\Betafun(n+\alpha, N -n +
  \beta)}{\Betafun(\alpha,\beta)},
\]
%
where the beta function $\Betafun(x,y)$ is defined for $x \in
\posreals$ and $y \in \posreals$ by
%
\[
\Betafun(x,y)
= \frac{\Gamma(x) \ \Gamma(y)}{\Gamma(x + y)}.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{beta\_binomial\_log}{ints \farg{n}, ints \farg{N}, reals
  \farg{alpha}, reals \farg{beta}}{The log beta-binomial probability mass
  of \farg{n} successes in \farg{N} trials given prior success count
  (plus one) of \farg{alpha} and prior failure count (plus one) of
  \farg{beta}}
%
\fitem{real}{beta\_binomial\_cdf}{ints \farg{n}, ints \farg{N}, reals
  \farg{alpha}, reals \farg{beta}}{The beta-binomial cumulative
  distribution function
  of \farg{n} successes in \farg{N} trials given prior success count
  (plus one) of \farg{alpha} and prior failure count (plus one) of
  \farg{beta}}
\end{description}
%
\begin{description}
\fitem{int}{beta\_binomial\_rng}{int \farg{N}, real \farg{alpha}, real \farg{beta}}{Generate a beta-binomial variate with \farg{N} trials, prior success count
  (plus one) of \farg{alpha}, and prior failure count (plus one) of
  \farg{beta}; may only be used in
  generated quantities block}
\end{description}




\section{Hypergeometric Distribution}

\subsubsection{Probability Mass Function}

If $a \in \nats$, $b \in \nats$, and $N \in \setlist{0,\ldots,a+b}$,
then for $n \in \setlist{\max(0,N-b),\ldots,\min(a,N)}$, 
\[
\distro{Hypergeometric}(n|N,a,b)
=
\frac{\normalsize{a \choose n} {b \choose {N - n}}}
     {\normalsize{{a + b} \choose N}}.
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{hypergeometric\_log}{int \farg{n}, int \farg{N}, int
    \farg{a}, int \farg{b}}{The log hypergeometric probability mass of
    \farg{n} successes in \farg{N} trials given total success count of
    \farg{a} and total failure count of \farg{b}}

%
\end{description}
%
\begin{description}
\fitem{int}{hypergeometric\_rng}{int \farg{N}, real \farg{a}, real \farg{b}}{Generate a hypergeometric variate with \farg{N} trials, total success count of
    \farg{a}, and total failure count of \farg{b}; may only be used in
  generated quantities block}
\end{description}




\section{Categorical Distribution}

\subsubsection{Probability Mass Function}

If $N \in \nats$ and $\theta \in \mbox{$N$-simplex}$, then for $y \in
\setlist{1,\ldots,N}$, 
\[
\distro{Categorical}(y|\theta) = \theta_n.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{categorical\_log}{int \farg{y}, vector \farg{theta}}{The
  log categorical probability mass function with outcome \farg{y} in 
$1:N$ given $N$-simplex distribution parameter \farg{theta}}
\end{description}
%
\begin{description}
\fitem{int}{categorical\_rng}{vector \farg{theta}}{Generate a
  categorical variate with $N$-simplex distribution parameter 
\farg{theta}; may only be used in generated quantities block}
\end{description}



\section{Ordered Logistic Distribution}

\subsubsection{Probability Mass Function}

If $K \in \nats$ with $K > 2$, $c \in \reals^{K-1}$ such that $c_k <
c_{k+1}$ for $k \in \setlist{1,\ldots,K-2}$, and $\eta \in \reals$, then for $k \in
\setlist{1,\ldots,K}$,
\[
\distro{OrderedLogistic}(k|\eta,c)
=
\left\{
\begin{array}{ll}
1 - \mbox{logit}^{-1}(\eta - c_1) & \mbox{if } k = 1,
\\[4pt]
\mbox{logit}^{-1}(\eta - c_{k-1}) - \mbox{logit}^{-1}(\eta -
c_{k})
& \mbox{if } 1 < k < K, \mbox{and}
\\[4pt]
\mbox{logit}^{-1}(\eta - c_{K-1}) - 0
& \mbox{if } k = K.
\end{array}
\right.
\]
%
The $k=1$ and $k=K$ edge cases can be subsumed into the general definition
by setting $c_0 = -\infty$ and $c_K = +\infty$ with
$\mbox{logit}^{-1}(-\infty) = 0$ and $\mbox{logit}^{-1}(\infty) = 1$.

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{ordered\_logistic\_log}{int \farg{k}, real \farg{eta},
    vector \farg{c}}{The log ordered logistic probability mass of
    \farg{k} given linear predictor \farg{eta} and cutpoints
    \farg{c}.}
%
\fitem{int}{ordered\_logistic\_rng}{real \farg{eta}, vector \farg{c}}{Generate an
  ordered logistic variate with linear predictor \farg{eta} and cutpoints
    \farg{c}; may only be used in generated quantities block}
\end{description}



\chapter{Unbounded Discrete Distributions}

\noindent
The unbounded discrete distributions have support over the natural
numbers (i.e., the non-negative integers).


\section{Negative Binomial Distribution}

\subsubsection{Probability Mass Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $n \in
\nats$,
\[
\distro{NegativeBinomial}(n|\alpha,\beta)
 = 
{{n + \alpha - 1} \choose {\alpha - 1}}
\,
\left( \frac{\beta}{\beta+1} \right)^{\!\alpha}
\,
\left( \frac{1}{\beta + 1} \right)^{\!n} \!.
\]
\begin{eqnarray*}
\log \distro{NegativeBinomial}(n|\alpha,\beta)
& = & \log \Gamma(n + \alpha) 
  - \log \Gamma(n + 1)
  - \log \Gamma(\alpha)
\\[4pt]
& & 
  {} + \alpha \left(\log \beta - \log (\beta + 1) \right)
  - n \log (\beta + 1)
\end{eqnarray*}
\[
\frac{\partial}{\partial \alpha} 
\log \distro{NegativeBinomial}(n|\alpha,\beta)
= \Psi(n + \alpha)
- \Psi(\alpha)
+ \log \beta
- \log (\beta + 1)
\]
\[
\frac{\partial}{\partial \beta} 
\log \distro{NegativeBinomial}(n|\alpha,\beta)
= \frac{\alpha}{\beta} - \frac{\alpha + n}{\beta + 1}
\]
where $\Psi$ is the digamma function, defined as
\[
\Psi(x) = \frac{\partial}{\partial x} \log \Gamma(x).
\]

\subsubsection{Stan Functions}

\begin{description}
%
 \fitem{real}{neg\_binomial\_log}{ints \farg{n}, reals
   \farg{alpha}, reals \farg{beta}}{The log negative binomial probability
   mass of \farg{n} given shape \farg{alpha} and inverse scale \farg{beta}}
%
 \fitem{real}{neg\_binomial\_cdf}{ints \farg{n}, reals
   \farg{alpha}, reals \farg{beta}}{The negative binomial cumulative
   distribution function
   of \farg{n} given shape \farg{alpha} and inverse scale \farg{beta}}
%
\fitem{int}{neg\_binomial\_rng}{real \farg{alpha}, real \farg{beta}}{Generate a
  negative binomial variate with shape \farg{alpha} and inverse scale
  \farg{beta}; may only be used in generated quantities block}
\end{description}


\section{Poisson Distribution}

\subsubsection{Probability Mass Function}

If $\lambda \in \posreals$, then for $n \in \nats$,
\[
\distro{Poisson}(n|\lambda)
= 
\frac{1}{n!}
\,
\lambda^n 
\,
\exp(-\lambda).
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{poisson\_log}{ints \farg{n}, reals \farg{lambda}}{The
  log Poisson probability mass of \farg{n} given rate \farg{lambda}}
%
\fitem{real}{poisson\_cdf}{ints \farg{n}, reals \farg{lambda}}{The
  Poisson cumulative distribution function of \farg{n} given rate \farg{lambda}}
%
\fitem{int}{poisson\_rng}{real \farg{lambda}}{Generate a
  poisson variate with rate \farg{lambda}; may only be used in generated quantities block}
\end{description}


\section{Poisson Distribution, Log Parameterization}


Stan also provides a parameterization of the Poisson using the log
rate $\alpha = \log \lambda$ as a parameter.  This is useful for
log-linear Poisson regressions so that the predictor does not need to
be exponentiated and passed into the standard Poisson probability
function.

\subsubsection{Probability Mass Function}

If $\alpha \in \reals$, then for $n \in \nats$,
\[
\distro{PoissonLog}(n|\alpha)
= 
\frac{1}{n!}
\,
\exp \left(n\alpha - \exp(\alpha) \right).
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{poisson\_log\_log}{ints \farg{n}, reals \farg{alpha}}{The
  log Poisson probability mass of \farg{n} given log rate \farg{alpha}}
\end{description}




\chapter{Multivariate Discrete Distributions}

\noindent
The multivariate discrete distributions are over multiple integer
values, which are expressed in Stan as arrays.

\section{Multinomial Distribution}

\subsubsection{Probability Mass Function}

If $K \in \nats$, $N \in \nats$, and $\theta \in \mbox{$K$-simplex}$,
then for $y \in \nats^K$ such that $\sum_{k=1}^K y_k = N$,
%
\[
\distro{Multinomial}(y|\theta,N)
= {N \choose {y_1,\ldots,y_K}} 
\prod_{k=1}^K \theta_k^{y_k},
\]
where the multinomial coefficient is defined by
\[
{N \choose {y_1,\ldots,y_k}}
= \frac{N!}{\prod_{k=1}^K y_k!}.
\]

\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{multinomial\_log}{int[] \farg{y}, vector
    \farg{theta}, int \farg{N}}{The log multinomial probability mass function with
    outcome array \code{y} of size $K$ given the $K$-simplex
    distribution parameter \farg{theta} and (implicit) total count
    \code{N = sum(\farg{y})}}
%
\fitem{vector}{multinomial\_rng}{vector \farg{theta}, int \farg{N}}{Generate a
  multinomial variate with simplex distribution parameter \farg{theta} and (implicit) total count $N$; may only be used in generated quantities block}
\end{description}



\part{Continuous Distributions}\label{continuous-prob-functions.part}



\chapter{Unbounded Continuous Distributions}

\noindent
The unbounded univariate continuous probability distributions have
support on all real numbers.


\section{Normal Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in
\reals$,
\[
\distro{Normal}(y|\mu,\sigma)
=
\frac{1}{\sqrt{2 \pi} \ \sigma}
\exp\left( - \, \frac{1}{2}
           \left(  \frac{y - \mu}{\sigma} \right)^2
    \right)
\!.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{normal\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{sigma}}{The log of the normal density of \farg{y} given
    location \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{normal\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}}{The cumulative normal distribution of \farg{y}
  given location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{normal\_rng}{real \farg{mu}, real \farg{sigma}}{Generate a normal
  variate with location \farg{mu} and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}


\section{Exponentially Modified Normal Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$, $\sigma \in \posreals$, and $\lambda \in
\posreals$, then for $y \in \reals$,
\[
\distro{ExpModNormal}(y|\mu,\sigma,\lambda)
=
\frac{\lambda}{\sqrt{\pi}}
\
\exp \left(\frac{\lambda}{2} \left(2\mu + \lambda \sigma^2 - 2y\right)\right) \erfc\left(\frac{\mu + \lambda\sigma^2 - y}{\sqrt{2}\sigma}\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{exp\_mod\_normal\_log}{reals \farg{y}, \\ reals
    \farg{mu}, reals \farg{sigma}, \newline reals \farg{lambda}}{The
    log of the exponentially modified normal density of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}}
%
  \fitem{real}{exp\_mod\_normal\_cdf}{reals \farg{y}, reals \farg{mu},
    reals \farg{sigma}, reals \farg{lambda}}{The cumulative
    exponentially modified normal distribution of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}}
\end{description}
%
\begin{description}
\fitem{real}{exp\_mod\_normal\_rng}{real \farg{mu}, real \farg{sigma},
real \farg{lambda}}{Generate a exponentially modified normal variate 
with location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}; 
may only be used in generated quantities block}
\end{description}

\section{Skew Normal Distribution}

\subsubsection{Probabilty Density Function}

If $\mu \in \reals$, $\sigma \in \posreals$, and $\alpha \in \reals$,
then for $y \in \reals$,
\[
\distro{SkewNormal}(y|\mu,\sigma,\alpha)
=
\frac{1}{\sigma\sqrt{2\pi}}
\
\exp\left( - \, \frac{1}{2}
           \left(  \frac{y - \mu}{\sigma} \right)^2
    \right)
\
\left(1 + \erf\left( \alpha\left(\frac{y - \mu}{\sigma\sqrt{2}}\right)\right)\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{skew\_normal\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{sigma}, reals \farg{alpha}}{The log of the skew normal density of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{alpha}}
%
\fitem{real}{skew\_normal\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}, reals \farg{alpha}}{The cumulative skew normal
  distribution of \farg{y} given location \farg{mu}, scale
  \farg{sigma}, and shape \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{real}{skew\_normal\_rng}{real \farg{mu}, real \farg{sigma},
  real \farg{alpha}}{Generate a skew normal variate with location
  \farg{mu}, scale \farg{sigma}, and shape \farg{alpha}; may only be used in
  generated quantities block}
\end{description}


\section{Student-$t$ Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, $\mu \in \reals$, and $\sigma \in \posreals$,
then for $y \in \reals$,
\[
\distro{StudentT}(y|\nu,\mu,\sigma)
=
\frac{\Gamma\left((\nu + 1)/2\right)}
     {\Gamma(\nu/2)}
\
\frac{1}{\sqrt{\nu \pi} \ \sigma}
\
\left(
1 + \frac{1}{\nu} \left(\frac{y - \mu}{\sigma}\right)^2
\right)^{-(\nu + 1)/2}
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{student\_t\_log}{reals \farg{y}, reals \farg{nu}, reals
    \farg{mu}, reals \farg{sigma}}{The log of the Student-$t$ density of \farg{y}
    given degrees of freedom \farg{nu}, location \farg{mu}, and scale
    \farg{sigma}}
%
  \fitem{real}{student\_t\_cdf}{reals \farg{y}, reals \farg{nu}, reals
    \farg{mu}, reals \farg{sigma}}{The Student-$t$ cumulative
    distribution function of \farg{y}
    given degrees of freedom \farg{nu}, location \farg{mu}, and scale
    \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{student\_t\_rng}{real \farg{nu}, real \farg{mu}, real
  \farg{sigma}}{Generate a Student-$t$ variate with degrees of freedom 
\farg{nu}, location \farg{mu}, and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}



\section{Cauchy Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$,
\[
\distro{Cauchy}(y|\mu,\sigma)
= 
\frac{1}{\pi \sigma}
\
\frac{1}{1 + \left((y - \mu)/\sigma\right)^2}
.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{cauchy\_log}{reals \farg{y}, reals \farg{mu}, reals
 \farg{sigma}}{ The log of the Cauchy density of \farg{y} given location
 \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{cauchy\_cdf}{reals \farg{y}, reals \farg{mu}, reals
 \farg{sigma}}{ The Cauchy cumulative distribution function of \farg{y} given location
 \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{cauchy\_rng}{real \farg{mu}, real \farg{sigma}}{Generate a Cauchy
  variate with location \farg{mu} and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}


\section{Double Exponential (Laplace) Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$, 
\[
\distro{DoubleExponential}(y|\mu,\sigma)
= \frac{1}{2\sigma} 
  \exp \left( - \, \frac{|y - \mu|}{\sigma} \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{double\_exponential\_log}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The log of the double exponential density of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{double\_exponential\_rng}{real \farg{mu}, real
  \farg{sigma}}{Generate a double exponential variate with location
  \farg{mu} and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Logistic Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$,
\[
\distro{Logistic}(y|\mu,\sigma)
=
\frac{1}{\sigma}
\
\exp\!\left( - \, \frac{y - \mu}{\sigma} \right)
\
\left(1 + \exp \!\left( - \, \frac{y - \mu}{\sigma} \right) \right)^{\!-2}
\! .
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{logistic\_log}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The log of the logistic density of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{logistic\_cdf}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The logistic cumulative distribution function of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{logistic\_rng}{real \farg{mu}, real
  \farg{sigma}}{Generate a logistic variate with location \farg{mu}
  and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Gumbel Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\beta \in \posreals$, then for $y \in \reals$,
\[
\distro{Gumbel}(y|\mu,\beta)
=
\frac{1}{\beta}
\
\exp\left(-\frac{y-\mu}{\beta}-\exp\left(-\frac{y-\mu}{\beta}\right)\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{gumbel\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{beta}}{The log of the gumbel density of \farg{y} given location \farg{mu} and scale \farg{beta}}
%
\fitem{real}{gumbel\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{beta}}{The cumulative gumbel distribution of \farg{y}
  given location \farg{mu} and scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{gumbel\_rng}{real \farg{mu}, real
  \farg{beta}}{Generate a gumbel variate with location \farg{mu}
  and scale \farg{beta}; may only be used in generated quantities block}
\end{description}



\chapter{Positive Continuous Distributions}

\noindent
The positive continuous probability functions have support on the
positive real numbers.


\section{Lognormal Distribution}\label{lognormal.section}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in
\posreals$, 
\[
\distro{LogNormal}(y|\mu,\sigma)
=
\frac{1}{\sqrt{2 \pi} \ \sigma}
\,
\frac{1}{y}
\
\exp \! \left(
       - \, \frac{1}{2}
       \, \left( \frac{\log y - \mu}{\sigma} \right)^2
     \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{lognormal\_log}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}}{The log of the lognormal density of \farg{y} given location
  \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{lognormal\_cdf}{real \farg{y}, real \farg{mu}, real
  \farg{sigma}}{The cumulative lognormal distribution of \farg{y}
  given location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{lognormal\_rng}{real \farg{mu}, real
  \farg{beta}}{Generate a lognormal variate with location \farg{mu}
  and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, then for $y \in \posreals$,
\[
\distro{ChiSquare}(y|\nu)
=
\frac{2^{-\nu/2}}
    {\Gamma(\nu / 2)}
\,
y^{\nu/2 - 1}
\,
\exp \! \left( -\, \frac{1}{2} \, y \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{chi\_square\_log}{reals \farg{y}, reals \farg{nu}}{The
  log of the Chi-square density of \farg{y} given degrees of freedom
  \farg{nu}}
\end{description}
%
\begin{description}
\fitem{real}{chi\_square\_rng}{real \farg{nu}}{Generate a Chi-square
  variate with degrees of freedom \farg{nu}; may only be used in
  generated quantities block}
\end{description}



\section{Inverse Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, then for $y \in \posreals$,
\[
\distro{InvChiSquare}(y|\nu)
= 
\frac{2^{-\nu/2}}
   {\Gamma(\nu / 2)}
\,
y^{-(\nu/2 - 1)}
\,
\exp\! \left( \! - \, \frac{1}{2} \, \frac{1}{y} \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{inv\_chi\_square\_log}{reals \farg{y}, reals
  \farg{nu}}{The log of the inverse Chi-square density of \farg{y} given
  degrees of freedom \farg{nu}}
%
\fitem{real}{inv\_chi\_square\_cdf}{reals \farg{y}, reals
  \farg{nu}}{The inverse Chi-squared cumulative distribution function of \farg{y} given
  degrees of freedom \farg{nu}}
\end{description}
%
\begin{description}
\fitem{real}{inv\_chi\_square\_rng}{real \farg{nu}}{Generate an
  inverse Chi-squared variate with degrees of freedom \farg{nu}; 
may only be used in generated quantities block}
\end{description}


\section{Scaled Inverse Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$ and $\sigma \in \posreals$, then for $y \in
\posreals$,
\[
\distro{ScaledInvChiSquare}(y|\nu)
= 
\frac{(\nu / 2)^{\nu/2}}
     {\Gamma(\nu / 2)}
\,
\sigma^{\nu}
\,
y^{-(\nu/2 + 1)}
\,
\exp \! \left( \!
   - \, \frac{1}{2} \, \nu \, \sigma^2 \, \frac{1}{y}
\right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{scaled\_inv\_chi\_square\_log}{reals \farg{y}, reals
    \farg{nu}, reals \farg{s}}{The log of the scaled inverse Chi-square
    density of \farg{y} given degrees of freedom \farg{nu} and scale
    \farg{s}}
\end{description}
%
\begin{description}
  \fitem{real}{scaled\_inv\_chi\_square\_cdf}{reals \farg{y}, reals
    \farg{nu}, reals \farg{s}}{The scaled inverse Chi-square
    cumulative distribution function
    of \farg{y} given degrees of freedom \farg{nu} and scale
    \farg{s}}
\end{description}
%
\begin{description}
\fitem{real}{scaled\_inv\_chi\_square\_rng}{real \farg{nu}, real
  \farg{s}}{Generate a scaled inverse Chi-squared variate with degrees 
of freedom \farg{nu} and scale \farg{s}; may only be used in generated 
quantities block}
\end{description}


\section{Exponential Distribution}

\subsubsection{Probability Density Function}

If $\beta \in \posreals$, then for $y \in \posreals$,
\[
\distro{Exponential}(y|\beta)
= 
\beta \, 
\exp ( - \beta \, y )
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{exponential\_log}{reals \farg{y}, reals \farg{beta}}{The
    log of the exponential density of \farg{y} given inverse scale \farg{beta}}
%
\fitem{real}{exponential\_cdf}{real \farg{y}, real \farg{beta}}{The
  cumulative distribution function of \farg{y} given inverse scale
  \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{exponential\_rng}{real \farg{beta}}{Generate an
  exponential variate with inverse scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Gamma Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $y \in
\posreals$,
\[
\distro{Gamma}(y|\alpha,\beta)
=
\frac{\beta^{\alpha}}
     {\Gamma(\alpha)}
\,
y^{\alpha - 1}
\exp(-\beta \, y)
.
\]


\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{gamma\_log}{reals \farg{y}, reals \farg{alpha}, reals
  \farg{beta}}{The log of the gamma density of \farg{y} given shape
  \farg{alpha} and inverse scale \farg{beta}}
%
%  \fitem{real}{gamma\_cdf}{real \farg{y}, real \farg{alpha}, real
 %  \farg{beta}}{The cumulative distribution function of \farg{y} given shape
 %  \farg{alpha} and inverse scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{gamma\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a gamma variate with shape
  \farg{alpha} and inverse scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Inverse Gamma Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $y \in
\posreals$,
\[
\distro{InvGamma}(y|\alpha,\beta)
= 
\frac{\beta^{\alpha}}
     {\Gamma(\alpha)}
\
y^{-(\alpha + 1)}
\,
\exp \! \left( \! - \beta \, \frac{1}{y} \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{inv\_gamma\_log}{reals \farg{y}, reals \farg{alpha}, reals
\farg{beta}}{The log of the inverse gamma density of \farg{y} given shape
\farg{alpha} and scale \farg{beta}}
%
\fitem{real}{inv\_gamma\_cdf}{reals \farg{y}, reals \farg{alpha}, reals
\farg{beta}}{The inverse gamma cumulative distribution function of \farg{y} given shape
\farg{alpha} and scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{inv\_gamma\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate an inverse gamma variate with shape
  \farg{alpha} and scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Weibull Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\sigma \in [0,\infty)$, then for $y \in
\posreals$, 
\[
\distro{Weibull}(y|\alpha,\sigma)
= 
\frac{\alpha}{\sigma}
\,
\left( \frac{y}{\sigma} \right)^{\alpha - 1}
\,
\exp \! \left( \! - \left( \frac{y}{\sigma} \right)^{\alpha}  \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{weibull\_log}{reals \farg{y}, reals \farg{alpha}, reals
\farg{sigma}}{The log of the Weibull density of \farg{y} given shape
\farg{alpha} and scale \farg{sigma}}
%
\fitem{real}{weibull\_cdf}{real \farg{y}, real \farg{alpha}, real
\farg{sigma}}{The Weibull cumulative distribution of \farg{y} given shape
\farg{alpha} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{weibull\_rng}{real \farg{alpha}, real
  \farg{sigma}}{Generate a weibull variate with shape
  \farg{alpha} and scale \farg{sigma}; may only be used in generated 
quantities block}
\end{description}


\chapter{Positive Lower-Bounded Probabilities}

\noindent
The positive lower-bounded probabilities have support on real values
above some positive minimum value.


\section{Pareto Distribution}

\subsubsection{Probability Density Function}

If $y_0 \in \posreals$ and $\alpha \in \posreals$, then for
$y \in \posreals$,
\[
\distro{Pareto}(y|y_0,\alpha)
=
\alpha 
\ y_0
\, \left( \frac{1}{y} \right)^{\!\alpha+1}
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{pareto\_log}{reals \farg{y}, reals \farg{y\_min}, reals
    \farg{alpha}}{The log of the Pareto density of \farg{y} given
    positive minimum value \farg{y\_min} and shape \farg{alpha}}
%
  \fitem{real}{pareto\_cdf}{reals \farg{y}, reals \farg{y\_min}, reals
    \farg{alpha}}{The Pareto cumulative distribution function of \farg{y} given
    positive minimum value \farg{y\_min} and shape \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{real}{pareto\_rng}{real \farg{y\_min}, real
  \farg{alpha}}{Generate a Pareto variate with positive minimum value \farg{y\_min} and shape \farg{alpha}; may only be used in generated 
quantities block}
\end{description}


\chapter{Continuous Distributions on $[0,1]$}

\noindent
The continuous distributions with outcomes in the interval $[0,1]$ are
used to characterized bounded quantities, including probabilities.


\section{Beta Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $\theta
\in [0,1]$,
\[
\distro{Beta}(\theta|\alpha,\beta)
=
\frac{1}{\Betafun(\alpha,\beta)}
\,
\theta^{\alpha - 1}
\,
(1 - \theta)^{\beta - 1}
,
\] 
where the beta function $\Betafun()$ is as defined in \refsection{betafun}


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{beta\_log}{reals \farg{theta}, reals \farg{alpha}, reals
    \farg{beta}}{The log of the beta density of \code{theta} in $[0,1]$
    given positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}}
%
  \fitem{real}{beta\_cdf}{reals \farg{theta}, reals \farg{alpha}, reals
    \farg{beta}}{The beta cumulative distribution function of \code{theta} in $[0,1]$
    given positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{beta\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a beta variate with positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}; may only
    be used in generated quantities block}
\end{description}


\chapter{Bounded Continuous Probabilities}

\noindent
The bounded continuous probabilities have support on a finite interval
of real numbers.



\section{Uniform Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \reals$ and $\beta \in (\alpha,\infty)$, then for $y
\in [\alpha,\beta]$,
\[
\distro{Uniform}(y|\alpha,\beta)
= 
\frac{1}{\beta - \alpha}
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{uniform\_log}{reals \farg{y}, reals \farg{alpha}, reals
  \farg{beta}}{The log of the uniform density of \farg{y} given lower bound
  \farg{alpha} and upper bound \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{uniform\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a uniform variate with lower bound
  \farg{alpha} and upper bound \farg{beta}; may only
    be used in generated quantities block}
\end{description}



\chapter{Distributions over Unbounded Vectors}

\noindent
The unbounded vector probability distributions have support on all of
$\reals^K$ for some fixed $K$.


\section{Multivariate Normal Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $\Sigma \in \reals^{K \times
  K}$ is symmetric and positive definite, then for $y \in \reals^K$,
\[
\distro{MultiNormal}(y|\mu,\Sigma)
=
\frac{1}{\left( 2 \pi \right)^{K/2}}
\
\frac{1}{\sqrt{|\Sigma|}}
\
\exp \! \left( \!
- 
\frac{1}{2}
(y - \mu)^{\top} \, \Sigma^{-1} \, (y - \mu)
\right)
\! ,
\]
%
where $|\Sigma|$ is the absolute determinant of $\Sigma$.


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_log}{vector \farg{y}, vector \farg{mu},
  matrix \farg{S}}{The log of the multivariate normal density of vector \farg{y}
 given location \farg{mu} and covariance matrix \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{vector}{multi\_normal\_rng}{vector \farg{mu}, matrix
  \farg{S}}{Generate a multivariate normal variate with location
  \farg{mu} and covariance matrix \farg{S}; may only be used in 
generated quantities block}
\end{description}


\section{Multivariate Normal Distribution, Precision Parameterization}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $\Omega \in \reals^{K \times
  K}$ is symmetric and positive definite, then for $y \in \reals^K$,
%
\[
\distro{MultiNormalPrecision}(y|\mu,\Omega)
= \distro{MultiNormal}(y|\mu,\Sigma^{-1})
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_prec\_log}{vector \farg{y}, vector
  \farg{mu}, matrix \farg{P}}{The log of the multivariate normal density of vector
  \farg{y} given location \farg{mu} and positive definite precision
  matrix \farg{P}}
%
\end{description}



\section{Multivariate Normal Distribution, Cholesky Parameterization}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $L \in \reals^{K \times K}$ is lower
triangular and such that $LL^{\top}$ is positive definite, then for $y
\in \reals^K$,
\[
\distro{MultiNormalCholesky}(y|\mu,L)
=
\distro{MultiNormal}(y|\mu,LL^{\top}).
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_cholesky\_log}{vector \farg{y}, vector
  \farg{mu}, matrix \farg{L}}{The log of the multivariate normal density of vector
  \farg{y} given location \farg{mu} and lower-triangular Cholesky
  factor of the covariance matrix \farg{L}}
%
\end{description}



\section{Multivariate Student-$t$ Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in \posreals$, $\mu \in \reals^K$, and $\Sigma
\in \reals^{K \times K}$ is symmetric and positive definite, then for
$y \in \reals^K$,
\[
\begin{array}{l}
\distro{MultiStudentT}(y|\nu,\mu,\Sigma)
\\[8pt]
\displaystyle
\hspace*{8pt}
=
\frac{1}{\pi^{K/2}}
\
\frac{1}{\nu^{K/2}}
\
\frac{\Gamma\!x\left((\nu + K)/2\right)}
     {\Gamma(\nu/2)}
\
\frac{1}{\sqrt{\left| \Sigma \right|}}
\
\left(
1 + \frac{1}{\nu} \, \left(y - \mu\right)^{\top} \, \Sigma^{-1} \, \left(y - \mu\right)
\right)^{-(\nu + K)/2}
\! .
\end{array}
\]
\vspace*{4pt}


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_student\_t\_log}{vector \farg{y}, real \farg{nu},
  vector \farg{mu}, matrix \farg{S}}{The log of the multivariate Student-$t$
  density of vector \farg{y} given degrees of freedom \farg{nu},
  location \farg{mu}, and scale matrix \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{vector}{multi\_student\_t\_rng}{real \farg{nu}, vector \farg{mu}, matrix
  \farg{S}}{Generate a multivariate Student-$t$ variate with degrees
  of freedom \farg{nu}, location \farg{mu}, and scale matrix \farg{S}; 
may only be used in generated quantities block}
\end{description}

\chapter{Simplex Distributions}

\noindent
The simplex probabilities have support on the unit $K$-simplex for a
specified $K$.  A $K$-dimensional vector $\theta$ is a unit
$K$-simplex if $\theta_k \geq 0$ for $k \in \setlist{1,\ldots,K}$ and
$\sum_{k = 1}^K \theta_k = 1$.


\section{Dirichlet Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$ and $\alpha \in (\posreals)^{K}$, then for
$\theta \in \mbox{$K$-simplex}$, 
\[
\distro{Dirichlet}(\theta|\alpha)
= 
\frac{\Gamma \! \left( \sum_{k=1}^K \alpha_k \right)}
     {\prod_{k=1}^K \Gamma(\alpha_k)}
\
\prod_{k=1}^K \theta_k^{\alpha_k - 1}
.
\]


\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{dirichlet\_log}{vector \farg{theta}, vector
    \farg{alpha}}{ The log of the Dirichlet density for simplex
    \farg{theta} given prior counts (plus one) \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{vector}{dirichlet\_rng}{vector \farg{alpha}}{Generate a
  Dirichlet variate with prior counts (plus one) \farg{alpha}; 
may only be used in generated quantities block}
\end{description}


\chapter{Correlation Matrix Distributions}

\noindent
The correlation matrix distributions have support on the (Cholesky
factors of) correlation matrices.  A Cholesky factor $L$ for a $K
\times K$ covariance matrix of dimensions $K$ has rows of unit length
so that the diagonal of $L L^{\top}$ is the unit $K$-vector.


\section{LKJ Correlation Distribution}

\subsubsection{Probability Density Function}

For $\eta > 0$, if $\Sigma$ a positive-definite, symmetric matrix with
unit diagonal (i.e., a correlation matrix), then
%
\[
\distro{LkjCorr}(\Sigma|\eta)
\propto \det \left( \Sigma \right)^{(\eta - 1)}.
\]
%
The shape parameter $\eta$ can be interpreted like the shape parameter
of a symmetric beta distribution. If $\eta = 1$, then the density is
uniform over all correlation matrices of a given order. If $\eta > 1$,
the identity matrix is the modal correlation matrix, especially as
$\eta$ becomes large. For $0 < \eta < 1$, the density has a trough at
the identity matrix. See \citep{LewandowskiKurowickaJoe:2009} for
definitions.


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{lkj\_corr\_log}{matrix \farg{y}, real
    \farg{eta}}{The log of the LKJ density for the correlation matrix
    \farg{y} given nonnegative shape \farg{eta}.}
%
\end{description}
\begin{description}
\fitem{matrix}{lkj\_corr\_rng}{int \farg{K}, real \farg{eta}}{Generate a
  LKJ random correlation matrix of order \farg{K} with shape \farg{eta};
  may only be used in generated quantities block}
\end{description}


\section{Cholesky LKJ Correlation Distribution}

\subsubsection{Probability Density Function}

For $\eta > 0$, if $L$ is the Cholesky factor of a positive-definite
matrix with unit diagonal (i.e., a correlation matrix), then
\[
\distro{LkjCholesky}(L|\eta) 
\propto \det(L L^\top)^{(\eta - 1)} 
= \det(L)^{(2 \eta - 2)}.
\]
See the previous section for details on interpreting the shape
parameter $\eta$.

\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{lkj\_corr\_cholesky\_log}{matrix \farg{L}, real
    \farg{eta}}{The log of the LKJ density for the lower-triangular
    Cholesky factor \farg{L} of a correlation matrix given shape
    \farg{eta}.}
%
\end{description}
\begin{description}
\fitem{matrix}{lkj\_corr\_cholesky\_rng}{int \farg{K}, real \farg{eta}}{
  Generate a random Cholesky factor of a LKJ random correlation matrix
  of order \farg{K} with shape \farg{eta}; may only be used in 
  generated quantities block}
\end{description}




\chapter{Covariance Matrix Distributions}

\noindent
The covariance matrix distributions have support on symmetric,
positive-definite $K \times K$ matrices.


\section{Wishart Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in (K-1,\infty)$, and $S \in \reals^{K \times K}$ is symmetric
and positive definite, then for symmetric and positive-definite $W \in
\reals^{K \times K}$,
\[
\distro{Wishart}(W|\nu,S)
=
\frac{1}{2^{\nu K / 2}}
\
\frac{1}{\Gamma_K \! \left( \frac{\nu}{2} \right)}
\
\left| S \right|^{-\nu/2}
\
\left| W \right|^{(\nu - K - 1)/2}
\
\exp \! \left(\frac{1}{2} \ \mbox{tr}\left( S^{-1} W \right) \right)
\! ,
\]
%
where $\mbox{tr}()$ is the matrix trace function, and $\Gamma_K()$ is
the multivariate Gamma function,
\[
\Gamma_K(x) = 
\frac{1}{\pi^{K(K-1)/4}}
\
\prod_{k=1}^K \Gamma \left( x + \frac{1 - k}{2} \right)
\!.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{wishart\_log}{matrix \farg{W}, real \farg{nu}, matrix
 \farg{S}}{The log of the Wishart density for positive-definite matrix
 \farg{W} given degrees of freedom \farg{nu} and scale matrix
 \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{matrix}{wishart\_rng}{real \farg{nu}, matrix \farg{S}}{Generate a
  Wishart variate with degrees of freedom \farg{nu} and scale matrix
 \farg{S}; may only be used in generated quantities block}
\end{description}


\section{Inverse Wishart Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in (K-1,\infty)$, and $S \in \reals^{K \times
  K}$ is symmetric and positive definite, then for symmetric and
positive-definite $W \in \reals^{K \times K}$,
\[
\distro{InvWishart}(W|\nu,S)
= 
\frac{1}{2^{\nu K / 2}}
\
\frac{1}{\Gamma_K \! \left( \frac{\nu}{2} \right)}
\
\left| S \right|^{\nu/2}
\
\left| W \right|^{-(\nu - K - 1)/2}
\
\exp \! \left( 
- \frac{1}{2}
\
\mbox{tr}(SW^{-1})
\right)
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{inv\_wishart\_log}{matrix \farg{W}, real \farg{nu}, matrix
 \farg{S}}{The log of the inverse Wishart density for positive-definite matrix
 \farg{W} given degrees of freedom \farg{nu} and scale matrix
 \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{matrix}{inv\_wishart\_rng}{real \farg{nu}, matrix
  \farg{S}}{Generate an inverse Wishart variate with degrees of 
freedom \farg{nu} and scale matrix
 \farg{S}; may only be used in generated quantities block}
\end{description}

\section{LKJ Covariance Distribution}

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{lkj\_cov\_log}{matrix \farg{W}, vector \farg{mu},
    vector \farg{sigma}, real \farg{eta}}{The log of the LKJ density
    for covariance matrix \farg{W} is the sum of log of the lognormal
    density of the standard deviations given location vector \farg{mu}
    and scale vector \farg{sigma} and the log of the lkj\_corr density
    of the correlation matrix given shape \farg{eta}.  See the next
    section for details on the lkj\_corr density.}
\end{description}



<commit_msg>added von mises distr to manual<commit_after>\part{Discrete Distributions}\label{discrete-prob-functions.part}


\chapter{Binary Distributions}

\noindent
Binary probability distributions have support on $\setlist{0,1}$,
where 1 represents the value true and 0 the value false.

\section{Bernoulli Distribution}

\subsubsection{Probability Mass Function}

If $\theta \in [0,1]$, then for $y \in \setlist{0,1}$, 
\[
\distro{Bernoulli}(y|\theta)
=
\left\{
\begin{array}{ll}
\theta & \mbox{if } y = 1, \mbox{ and}
\\
1 - \theta & \mbox{if } y = 0.
\end{array}
\right.
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{bernoulli\_log}{ints \farg{y}, reals \farg{theta}}{The
  log Bernoulli probability mass of \farg{y} given chance of success
  \farg{theta}}
%
\end{description}

\begin{description}
%
\fitem{real}{bernoulli\_cdf}{ints \farg{y}, reals \farg{theta}}{The
  Bernoulli cumulative distribution function of \farg{y} given chance of success
  \farg{theta}}
%
\end{description}
%
\begin{description}
\fitem{int}{bernoulli\_rng}{real \farg{theta}}{Generate a Bernoulli
  variate with chance of success \farg{theta}; may only be used in
  generated quantities block}
\end{description}

\section{Bernoulli Distribution, Logit Parameterization}

\Stan also supplies a direct parameterization in terms of a
logit-transformed chance-of-success parameter.  This parameterization
is more numerically stable if the chance-of-success parameter is on
the logit scale, as with the linear predictor in a logistic
regression.  

\subsubsection{Probability Mass Function}

If $\alpha \in \reals$, then for $c \in \setlist{0,1}$,
\[
\distro{BernoulliLogit}(c|\alpha)
=
\distro{Bernoulli}(c|\mbox{logit}^{-1}(\alpha))
= 
\left\{
\begin{array}{ll}
\mbox{logit}^{-1}(\alpha) & \mbox{if } y = 1, \mbox{ and}
\\
1 - \mbox{logit}^{-1}(\alpha) & \mbox{if } y = 0.
\end{array}
\right.
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{bernoulli\_logit\_log}{ints \farg{y}, reals \farg{alpha}}{The
  log Bernoulli probability mass of \farg{y} given logit chance of success
  \code{exp(\farg{alpha})}}
%
\end{description}



\chapter{Bounded Discrete Distributions}\label{betafun.chapter}

\noindent
Bounded discrete probability functions have support on
$\setlist{0,\ldots,N}$ for some upper bound $N$.


\section{Binomial Distribution}

\subsubsection{Probability Mass Function}

Suppose $N \in \nats$ and $\theta \in [0,1]$, and $n \in
\{0,\ldots,N\}$.
\[
\distro{Binomial}(n|N,\theta)
= {N \choose n} \theta^n (1 - \theta)^{N - n}.
\]


\subsubsection{Log Probability Mass Function}

\begin{eqnarray*}
\log \distro{Binomial}(n|N,\theta)
& = &
\log \Gamma(N+1) - \log \Gamma(n + 1) - \log \Gamma(N- n + 1)
\\[4pt]
& & { } + n \log \theta + (N - n) \log (1 - \theta), 
\end{eqnarray*}


\subsubsection{Gradient of Log Probability Mass Function}

\[
\frac{\partial}{\partial \theta} \log \distro{Binomial}(n|N,\theta)
= \frac{n}{\theta}
- \frac{N - n}{1 - \theta}
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{binomial\_log}{ints \farg{n}, ints \farg{N}, reals
    \farg{theta}}{The log binomial probability mass of \farg{n}
    successes in \farg{N} trials given chance of success \farg{theta}}
%
  \fitem{real}{binomial\_cdf}{ints \farg{n}, ints \farg{N}, reals
    \farg{theta}}{The binomial cumulative distribution function of \farg{n}
    successes in \farg{N} trials given chance of success \farg{theta}}
%
\end{description}
%
\begin{description}
\fitem{int}{binomial\_rng}{int \farg{N}, real \farg{theta}}{Generate a binomial
  variate with \farg{N} trials and chance of success \farg{theta}; may only be used in
  generated quantities block}
\end{description}



\section{Binomial Distribution, Logit Parameterization}

Stan also provides a version of the binomial probability mass function
distribution with the chance of success parameterized on the
unconstrained logistic scale.  

\subsubsection{Probability Mass Function}

Suppose $N \in \nats$, $\alpha \in \reals$, and $n \in
\{0,\ldots,N\}$.

\begin{eqnarray*}
\distro{BinomialLogit}(n|N,\alpha)
& = & \distro{BinomialLogit}(n|N,\mbox{logit}^{-1}(\alpha))
\\[6pt]
& = & {N \choose n} \left( \mbox{logit}^{-1}(\alpha) \right)^{n}
                    \left( 1 - \mbox{logit}^{-1}(\alpha) \right)^{N - n}.
\end{eqnarray*}


\subsubsection{Log Probability Mass Function}

\begin{eqnarray*}
\log \distro{BinomialLogit}(n|N,\alpha)
& = &
\log \Gamma(N+1) - \log \Gamma(n + 1) - \log \Gamma(N- n + 1)
\\[4pt]
& & { } + n \log \mbox{logit}^{-1}(\alpha) + (N - n) \log \left( 1 -
  \mbox{logit}^{-1}(\alpha) \right), 
\end{eqnarray*}


\subsubsection{Gradient of Log Probability Mass Function}

\[
\frac{\partial}{\partial \alpha} \log \distro{BinomialLogit}(n|N,\alpha)
= \frac{n}{\mbox{logit}^{-1}(-\alpha)}
- \frac{N - n}{\mbox{logit}^{-1}(\alpha)}
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{binomial\_logit\_log}{ints \farg{n}, ints \farg{N}, reals
    \farg{alpha}}{The log binomial probability mass of \farg{n}
    successes in \farg{N} trials given logit-scaled chance of success \farg{alpha}}
%
\end{description}



\section{Beta-Binomial Distribution}

\subsubsection{Probability Mass Function}

If $N \in \nats$, $\alpha \in \posreals$, and $\beta \in \posreals$,
then for $n \in \setlist{0,\ldots,N}$,
\[
\distro{BetaBinomial}(n|N,\alpha,\beta)
= 
{N \choose n} \frac{\Betafun(n+\alpha, N -n +
  \beta)}{\Betafun(\alpha,\beta)},
\]
%
where the beta function $\Betafun(x,y)$ is defined for $x \in
\posreals$ and $y \in \posreals$ by
%
\[
\Betafun(x,y)
= \frac{\Gamma(x) \ \Gamma(y)}{\Gamma(x + y)}.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{beta\_binomial\_log}{ints \farg{n}, ints \farg{N}, reals
  \farg{alpha}, reals \farg{beta}}{The log beta-binomial probability mass
  of \farg{n} successes in \farg{N} trials given prior success count
  (plus one) of \farg{alpha} and prior failure count (plus one) of
  \farg{beta}}
%
\fitem{real}{beta\_binomial\_cdf}{ints \farg{n}, ints \farg{N}, reals
  \farg{alpha}, reals \farg{beta}}{The beta-binomial cumulative
  distribution function
  of \farg{n} successes in \farg{N} trials given prior success count
  (plus one) of \farg{alpha} and prior failure count (plus one) of
  \farg{beta}}
\end{description}
%
\begin{description}
\fitem{int}{beta\_binomial\_rng}{int \farg{N}, real \farg{alpha}, real \farg{beta}}{Generate a beta-binomial variate with \farg{N} trials, prior success count
  (plus one) of \farg{alpha}, and prior failure count (plus one) of
  \farg{beta}; may only be used in
  generated quantities block}
\end{description}




\section{Hypergeometric Distribution}

\subsubsection{Probability Mass Function}

If $a \in \nats$, $b \in \nats$, and $N \in \setlist{0,\ldots,a+b}$,
then for $n \in \setlist{\max(0,N-b),\ldots,\min(a,N)}$, 
\[
\distro{Hypergeometric}(n|N,a,b)
=
\frac{\normalsize{a \choose n} {b \choose {N - n}}}
     {\normalsize{{a + b} \choose N}}.
\]


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{hypergeometric\_log}{int \farg{n}, int \farg{N}, int
    \farg{a}, int \farg{b}}{The log hypergeometric probability mass of
    \farg{n} successes in \farg{N} trials given total success count of
    \farg{a} and total failure count of \farg{b}}

%
\end{description}
%
\begin{description}
\fitem{int}{hypergeometric\_rng}{int \farg{N}, real \farg{a}, real \farg{b}}{Generate a hypergeometric variate with \farg{N} trials, total success count of
    \farg{a}, and total failure count of \farg{b}; may only be used in
  generated quantities block}
\end{description}




\section{Categorical Distribution}

\subsubsection{Probability Mass Function}

If $N \in \nats$ and $\theta \in \mbox{$N$-simplex}$, then for $y \in
\setlist{1,\ldots,N}$, 
\[
\distro{Categorical}(y|\theta) = \theta_n.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{categorical\_log}{int \farg{y}, vector \farg{theta}}{The
  log categorical probability mass function with outcome \farg{y} in 
$1:N$ given $N$-simplex distribution parameter \farg{theta}}
\end{description}
%
\begin{description}
\fitem{int}{categorical\_rng}{vector \farg{theta}}{Generate a
  categorical variate with $N$-simplex distribution parameter 
\farg{theta}; may only be used in generated quantities block}
\end{description}



\section{Ordered Logistic Distribution}

\subsubsection{Probability Mass Function}

If $K \in \nats$ with $K > 2$, $c \in \reals^{K-1}$ such that $c_k <
c_{k+1}$ for $k \in \setlist{1,\ldots,K-2}$, and $\eta \in \reals$, then for $k \in
\setlist{1,\ldots,K}$,
\[
\distro{OrderedLogistic}(k|\eta,c)
=
\left\{
\begin{array}{ll}
1 - \mbox{logit}^{-1}(\eta - c_1) & \mbox{if } k = 1,
\\[4pt]
\mbox{logit}^{-1}(\eta - c_{k-1}) - \mbox{logit}^{-1}(\eta -
c_{k})
& \mbox{if } 1 < k < K, \mbox{and}
\\[4pt]
\mbox{logit}^{-1}(\eta - c_{K-1}) - 0
& \mbox{if } k = K.
\end{array}
\right.
\]
%
The $k=1$ and $k=K$ edge cases can be subsumed into the general definition
by setting $c_0 = -\infty$ and $c_K = +\infty$ with
$\mbox{logit}^{-1}(-\infty) = 0$ and $\mbox{logit}^{-1}(\infty) = 1$.

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{ordered\_logistic\_log}{int \farg{k}, real \farg{eta},
    vector \farg{c}}{The log ordered logistic probability mass of
    \farg{k} given linear predictor \farg{eta} and cutpoints
    \farg{c}.}
%
\fitem{int}{ordered\_logistic\_rng}{real \farg{eta}, vector \farg{c}}{Generate an
  ordered logistic variate with linear predictor \farg{eta} and cutpoints
    \farg{c}; may only be used in generated quantities block}
\end{description}



\chapter{Unbounded Discrete Distributions}

\noindent
The unbounded discrete distributions have support over the natural
numbers (i.e., the non-negative integers).


\section{Negative Binomial Distribution}

\subsubsection{Probability Mass Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $n \in
\nats$,
\[
\distro{NegativeBinomial}(n|\alpha,\beta)
 = 
{{n + \alpha - 1} \choose {\alpha - 1}}
\,
\left( \frac{\beta}{\beta+1} \right)^{\!\alpha}
\,
\left( \frac{1}{\beta + 1} \right)^{\!n} \!.
\]
\begin{eqnarray*}
\log \distro{NegativeBinomial}(n|\alpha,\beta)
& = & \log \Gamma(n + \alpha) 
  - \log \Gamma(n + 1)
  - \log \Gamma(\alpha)
\\[4pt]
& & 
  {} + \alpha \left(\log \beta - \log (\beta + 1) \right)
  - n \log (\beta + 1)
\end{eqnarray*}
\[
\frac{\partial}{\partial \alpha} 
\log \distro{NegativeBinomial}(n|\alpha,\beta)
= \Psi(n + \alpha)
- \Psi(\alpha)
+ \log \beta
- \log (\beta + 1)
\]
\[
\frac{\partial}{\partial \beta} 
\log \distro{NegativeBinomial}(n|\alpha,\beta)
= \frac{\alpha}{\beta} - \frac{\alpha + n}{\beta + 1}
\]
where $\Psi$ is the digamma function, defined as
\[
\Psi(x) = \frac{\partial}{\partial x} \log \Gamma(x).
\]

\subsubsection{Stan Functions}

\begin{description}
%
 \fitem{real}{neg\_binomial\_log}{ints \farg{n}, reals
   \farg{alpha}, reals \farg{beta}}{The log negative binomial probability
   mass of \farg{n} given shape \farg{alpha} and inverse scale \farg{beta}}
%
 \fitem{real}{neg\_binomial\_cdf}{ints \farg{n}, reals
   \farg{alpha}, reals \farg{beta}}{The negative binomial cumulative
   distribution function
   of \farg{n} given shape \farg{alpha} and inverse scale \farg{beta}}
%
\fitem{int}{neg\_binomial\_rng}{real \farg{alpha}, real \farg{beta}}{Generate a
  negative binomial variate with shape \farg{alpha} and inverse scale
  \farg{beta}; may only be used in generated quantities block}
\end{description}


\section{Poisson Distribution}

\subsubsection{Probability Mass Function}

If $\lambda \in \posreals$, then for $n \in \nats$,
\[
\distro{Poisson}(n|\lambda)
= 
\frac{1}{n!}
\,
\lambda^n 
\,
\exp(-\lambda).
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{poisson\_log}{ints \farg{n}, reals \farg{lambda}}{The
  log Poisson probability mass of \farg{n} given rate \farg{lambda}}
%
\fitem{real}{poisson\_cdf}{ints \farg{n}, reals \farg{lambda}}{The
  Poisson cumulative distribution function of \farg{n} given rate \farg{lambda}}
%
\fitem{int}{poisson\_rng}{real \farg{lambda}}{Generate a
  poisson variate with rate \farg{lambda}; may only be used in generated quantities block}
\end{description}


\section{Poisson Distribution, Log Parameterization}


Stan also provides a parameterization of the Poisson using the log
rate $\alpha = \log \lambda$ as a parameter.  This is useful for
log-linear Poisson regressions so that the predictor does not need to
be exponentiated and passed into the standard Poisson probability
function.

\subsubsection{Probability Mass Function}

If $\alpha \in \reals$, then for $n \in \nats$,
\[
\distro{PoissonLog}(n|\alpha)
= 
\frac{1}{n!}
\,
\exp \left(n\alpha - \exp(\alpha) \right).
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{poisson\_log\_log}{ints \farg{n}, reals \farg{alpha}}{The
  log Poisson probability mass of \farg{n} given log rate \farg{alpha}}
\end{description}




\chapter{Multivariate Discrete Distributions}

\noindent
The multivariate discrete distributions are over multiple integer
values, which are expressed in Stan as arrays.

\section{Multinomial Distribution}

\subsubsection{Probability Mass Function}

If $K \in \nats$, $N \in \nats$, and $\theta \in \mbox{$K$-simplex}$,
then for $y \in \nats^K$ such that $\sum_{k=1}^K y_k = N$,
%
\[
\distro{Multinomial}(y|\theta,N)
= {N \choose {y_1,\ldots,y_K}} 
\prod_{k=1}^K \theta_k^{y_k},
\]
where the multinomial coefficient is defined by
\[
{N \choose {y_1,\ldots,y_k}}
= \frac{N!}{\prod_{k=1}^K y_k!}.
\]

\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{multinomial\_log}{int[] \farg{y}, vector
    \farg{theta}, int \farg{N}}{The log multinomial probability mass function with
    outcome array \code{y} of size $K$ given the $K$-simplex
    distribution parameter \farg{theta} and (implicit) total count
    \code{N = sum(\farg{y})}}
%
\fitem{vector}{multinomial\_rng}{vector \farg{theta}, int \farg{N}}{Generate a
  multinomial variate with simplex distribution parameter \farg{theta} and (implicit) total count $N$; may only be used in generated quantities block}
\end{description}



\part{Continuous Distributions}\label{continuous-prob-functions.part}



\chapter{Unbounded Continuous Distributions}

\noindent
The unbounded univariate continuous probability distributions have
support on all real numbers.


\section{Normal Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in
\reals$,
\[
\distro{Normal}(y|\mu,\sigma)
=
\frac{1}{\sqrt{2 \pi} \ \sigma}
\exp\left( - \, \frac{1}{2}
           \left(  \frac{y - \mu}{\sigma} \right)^2
    \right)
\!.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{normal\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{sigma}}{The log of the normal density of \farg{y} given
    location \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{normal\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}}{The cumulative normal distribution of \farg{y}
  given location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{normal\_rng}{real \farg{mu}, real \farg{sigma}}{Generate a normal
  variate with location \farg{mu} and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}


\section{Exponentially Modified Normal Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$, $\sigma \in \posreals$, and $\lambda \in
\posreals$, then for $y \in \reals$,
\[
\distro{ExpModNormal}(y|\mu,\sigma,\lambda)
=
\frac{\lambda}{\sqrt{\pi}}
\
\exp \left(\frac{\lambda}{2} \left(2\mu + \lambda \sigma^2 - 2y\right)\right) \erfc\left(\frac{\mu + \lambda\sigma^2 - y}{\sqrt{2}\sigma}\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{exp\_mod\_normal\_log}{reals \farg{y}, \\ reals
    \farg{mu}, reals \farg{sigma}, \newline reals \farg{lambda}}{The
    log of the exponentially modified normal density of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}}
%
  \fitem{real}{exp\_mod\_normal\_cdf}{reals \farg{y}, reals \farg{mu},
    reals \farg{sigma}, reals \farg{lambda}}{The cumulative
    exponentially modified normal distribution of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}}
\end{description}
%
\begin{description}
\fitem{real}{exp\_mod\_normal\_rng}{real \farg{mu}, real \farg{sigma},
real \farg{lambda}}{Generate a exponentially modified normal variate 
with location \farg{mu}, scale \farg{sigma}, and shape \farg{lambda}; 
may only be used in generated quantities block}
\end{description}

\section{Skew Normal Distribution}

\subsubsection{Probabilty Density Function}

If $\mu \in \reals$, $\sigma \in \posreals$, and $\alpha \in \reals$,
then for $y \in \reals$,
\[
\distro{SkewNormal}(y|\mu,\sigma,\alpha)
=
\frac{1}{\sigma\sqrt{2\pi}}
\
\exp\left( - \, \frac{1}{2}
           \left(  \frac{y - \mu}{\sigma} \right)^2
    \right)
\
\left(1 + \erf\left( \alpha\left(\frac{y - \mu}{\sigma\sqrt{2}}\right)\right)\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{skew\_normal\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{sigma}, reals \farg{alpha}}{The log of the skew normal density of \farg{y} given
    location \farg{mu}, scale \farg{sigma}, and shape \farg{alpha}}
%
\fitem{real}{skew\_normal\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}, reals \farg{alpha}}{The cumulative skew normal
  distribution of \farg{y} given location \farg{mu}, scale
  \farg{sigma}, and shape \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{real}{skew\_normal\_rng}{real \farg{mu}, real \farg{sigma},
  real \farg{alpha}}{Generate a skew normal variate with location
  \farg{mu}, scale \farg{sigma}, and shape \farg{alpha}; may only be used in
  generated quantities block}
\end{description}


\section{Student-$t$ Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, $\mu \in \reals$, and $\sigma \in \posreals$,
then for $y \in \reals$,
\[
\distro{StudentT}(y|\nu,\mu,\sigma)
=
\frac{\Gamma\left((\nu + 1)/2\right)}
     {\Gamma(\nu/2)}
\
\frac{1}{\sqrt{\nu \pi} \ \sigma}
\
\left(
1 + \frac{1}{\nu} \left(\frac{y - \mu}{\sigma}\right)^2
\right)^{-(\nu + 1)/2}
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{student\_t\_log}{reals \farg{y}, reals \farg{nu}, reals
    \farg{mu}, reals \farg{sigma}}{The log of the Student-$t$ density of \farg{y}
    given degrees of freedom \farg{nu}, location \farg{mu}, and scale
    \farg{sigma}}
%
  \fitem{real}{student\_t\_cdf}{reals \farg{y}, reals \farg{nu}, reals
    \farg{mu}, reals \farg{sigma}}{The Student-$t$ cumulative
    distribution function of \farg{y}
    given degrees of freedom \farg{nu}, location \farg{mu}, and scale
    \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{student\_t\_rng}{real \farg{nu}, real \farg{mu}, real
  \farg{sigma}}{Generate a Student-$t$ variate with degrees of freedom 
\farg{nu}, location \farg{mu}, and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}



\section{Cauchy Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$,
\[
\distro{Cauchy}(y|\mu,\sigma)
= 
\frac{1}{\pi \sigma}
\
\frac{1}{1 + \left((y - \mu)/\sigma\right)^2}
.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{cauchy\_log}{reals \farg{y}, reals \farg{mu}, reals
 \farg{sigma}}{ The log of the Cauchy density of \farg{y} given location
 \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{cauchy\_cdf}{reals \farg{y}, reals \farg{mu}, reals
 \farg{sigma}}{ The Cauchy cumulative distribution function of \farg{y} given location
 \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{cauchy\_rng}{real \farg{mu}, real \farg{sigma}}{Generate a Cauchy
  variate with location \farg{mu} and scale \farg{sigma}; may only be used in
  generated quantities block}
\end{description}


\section{Double Exponential (Laplace) Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$, 
\[
\distro{DoubleExponential}(y|\mu,\sigma)
= \frac{1}{2\sigma} 
  \exp \left( - \, \frac{|y - \mu|}{\sigma} \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{double\_exponential\_log}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The log of the double exponential density of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{double\_exponential\_rng}{real \farg{mu}, real
  \farg{sigma}}{Generate a double exponential variate with location
  \farg{mu} and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Logistic Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in \reals$,
\[
\distro{Logistic}(y|\mu,\sigma)
=
\frac{1}{\sigma}
\
\exp\!\left( - \, \frac{y - \mu}{\sigma} \right)
\
\left(1 + \exp \!\left( - \, \frac{y - \mu}{\sigma} \right) \right)^{\!-2}
\! .
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{logistic\_log}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The log of the logistic density of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{logistic\_cdf}{reals \farg{y}, reals \farg{mu},
reals \farg{sigma}}{ The logistic cumulative distribution function of \farg{y} given
location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{logistic\_rng}{real \farg{mu}, real
  \farg{sigma}}{Generate a logistic variate with location \farg{mu}
  and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Gumbel Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\beta \in \posreals$, then for $y \in \reals$,
\[
\distro{Gumbel}(y|\mu,\beta)
=
\frac{1}{\beta}
\
\exp\left(-\frac{y-\mu}{\beta}-\exp\left(-\frac{y-\mu}{\beta}\right)\right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{gumbel\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{beta}}{The log of the gumbel density of \farg{y} given location \farg{mu} and scale \farg{beta}}
%
\fitem{real}{gumbel\_cdf}{reals \farg{y}, reals \farg{mu}, reals
  \farg{beta}}{The cumulative gumbel distribution of \farg{y}
  given location \farg{mu} and scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{gumbel\_rng}{real \farg{mu}, real
  \farg{beta}}{Generate a gumbel variate with location \farg{mu}
  and scale \farg{beta}; may only be used in generated quantities block}
\end{description}


\chapter{Positive Continuous Distributions}

\noindent
The positive continuous probability functions have support on the
positive real numbers.


\section{Lognormal Distribution}\label{lognormal.section}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\sigma \in \posreals$, then for $y \in
\posreals$, 
\[
\distro{LogNormal}(y|\mu,\sigma)
=
\frac{1}{\sqrt{2 \pi} \ \sigma}
\,
\frac{1}{y}
\
\exp \! \left(
       - \, \frac{1}{2}
       \, \left( \frac{\log y - \mu}{\sigma} \right)^2
     \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{lognormal\_log}{reals \farg{y}, reals \farg{mu}, reals
  \farg{sigma}}{The log of the lognormal density of \farg{y} given location
  \farg{mu} and scale \farg{sigma}}
%
\fitem{real}{lognormal\_cdf}{real \farg{y}, real \farg{mu}, real
  \farg{sigma}}{The cumulative lognormal distribution of \farg{y}
  given location \farg{mu} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{lognormal\_rng}{real \farg{mu}, real
  \farg{beta}}{Generate a lognormal variate with location \farg{mu}
  and scale \farg{sigma}; may only be used in generated quantities block}
\end{description}


\section{Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, then for $y \in \posreals$,
\[
\distro{ChiSquare}(y|\nu)
=
\frac{2^{-\nu/2}}
    {\Gamma(\nu / 2)}
\,
y^{\nu/2 - 1}
\,
\exp \! \left( -\, \frac{1}{2} \, y \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{chi\_square\_log}{reals \farg{y}, reals \farg{nu}}{The
  log of the Chi-square density of \farg{y} given degrees of freedom
  \farg{nu}}
\end{description}
%
\begin{description}
\fitem{real}{chi\_square\_rng}{real \farg{nu}}{Generate a Chi-square
  variate with degrees of freedom \farg{nu}; may only be used in
  generated quantities block}
\end{description}



\section{Inverse Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$, then for $y \in \posreals$,
\[
\distro{InvChiSquare}(y|\nu)
= 
\frac{2^{-\nu/2}}
   {\Gamma(\nu / 2)}
\,
y^{-(\nu/2 - 1)}
\,
\exp\! \left( \! - \, \frac{1}{2} \, \frac{1}{y} \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{inv\_chi\_square\_log}{reals \farg{y}, reals
  \farg{nu}}{The log of the inverse Chi-square density of \farg{y} given
  degrees of freedom \farg{nu}}
%
\fitem{real}{inv\_chi\_square\_cdf}{reals \farg{y}, reals
  \farg{nu}}{The inverse Chi-squared cumulative distribution function of \farg{y} given
  degrees of freedom \farg{nu}}
\end{description}
%
\begin{description}
\fitem{real}{inv\_chi\_square\_rng}{real \farg{nu}}{Generate an
  inverse Chi-squared variate with degrees of freedom \farg{nu}; 
may only be used in generated quantities block}
\end{description}


\section{Scaled Inverse Chi-Square Distribution}

\subsubsection{Probability Density Function}

If $\nu \in \posreals$ and $\sigma \in \posreals$, then for $y \in
\posreals$,
\[
\distro{ScaledInvChiSquare}(y|\nu)
= 
\frac{(\nu / 2)^{\nu/2}}
     {\Gamma(\nu / 2)}
\,
\sigma^{\nu}
\,
y^{-(\nu/2 + 1)}
\,
\exp \! \left( \!
   - \, \frac{1}{2} \, \nu \, \sigma^2 \, \frac{1}{y}
\right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{scaled\_inv\_chi\_square\_log}{reals \farg{y}, reals
    \farg{nu}, reals \farg{s}}{The log of the scaled inverse Chi-square
    density of \farg{y} given degrees of freedom \farg{nu} and scale
    \farg{s}}
\end{description}
%
\begin{description}
  \fitem{real}{scaled\_inv\_chi\_square\_cdf}{reals \farg{y}, reals
    \farg{nu}, reals \farg{s}}{The scaled inverse Chi-square
    cumulative distribution function
    of \farg{y} given degrees of freedom \farg{nu} and scale
    \farg{s}}
\end{description}
%
\begin{description}
\fitem{real}{scaled\_inv\_chi\_square\_rng}{real \farg{nu}, real
  \farg{s}}{Generate a scaled inverse Chi-squared variate with degrees 
of freedom \farg{nu} and scale \farg{s}; may only be used in generated 
quantities block}
\end{description}


\section{Exponential Distribution}

\subsubsection{Probability Density Function}

If $\beta \in \posreals$, then for $y \in \posreals$,
\[
\distro{Exponential}(y|\beta)
= 
\beta \, 
\exp ( - \beta \, y )
.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{exponential\_log}{reals \farg{y}, reals \farg{beta}}{The
    log of the exponential density of \farg{y} given inverse scale \farg{beta}}
%
\fitem{real}{exponential\_cdf}{real \farg{y}, real \farg{beta}}{The
  cumulative distribution function of \farg{y} given inverse scale
  \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{exponential\_rng}{real \farg{beta}}{Generate an
  exponential variate with inverse scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Gamma Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $y \in
\posreals$,
\[
\distro{Gamma}(y|\alpha,\beta)
=
\frac{\beta^{\alpha}}
     {\Gamma(\alpha)}
\,
y^{\alpha - 1}
\exp(-\beta \, y)
.
\]


\subsubsection{Stan Functions}

\begin{description}
 \fitem{real}{gamma\_log}{reals \farg{y}, reals \farg{alpha}, reals
  \farg{beta}}{The log of the gamma density of \farg{y} given shape
  \farg{alpha} and inverse scale \farg{beta}}
%
%  \fitem{real}{gamma\_cdf}{real \farg{y}, real \farg{alpha}, real
 %  \farg{beta}}{The cumulative distribution function of \farg{y} given shape
 %  \farg{alpha} and inverse scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{gamma\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a gamma variate with shape
  \farg{alpha} and inverse scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Inverse Gamma Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $y \in
\posreals$,
\[
\distro{InvGamma}(y|\alpha,\beta)
= 
\frac{\beta^{\alpha}}
     {\Gamma(\alpha)}
\
y^{-(\alpha + 1)}
\,
\exp \! \left( \! - \beta \, \frac{1}{y} \right)
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{inv\_gamma\_log}{reals \farg{y}, reals \farg{alpha}, reals
\farg{beta}}{The log of the inverse gamma density of \farg{y} given shape
\farg{alpha} and scale \farg{beta}}
%
\fitem{real}{inv\_gamma\_cdf}{reals \farg{y}, reals \farg{alpha}, reals
\farg{beta}}{The inverse gamma cumulative distribution function of \farg{y} given shape
\farg{alpha} and scale \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{inv\_gamma\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate an inverse gamma variate with shape
  \farg{alpha} and scale \farg{beta}; may only be used in generated 
quantities block}
\end{description}


\section{Weibull Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\sigma \in [0,\infty)$, then for $y \in
\posreals$, 
\[
\distro{Weibull}(y|\alpha,\sigma)
= 
\frac{\alpha}{\sigma}
\,
\left( \frac{y}{\sigma} \right)^{\alpha - 1}
\,
\exp \! \left( \! - \left( \frac{y}{\sigma} \right)^{\alpha}  \right)
.
\]


\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{weibull\_log}{reals \farg{y}, reals \farg{alpha}, reals
\farg{sigma}}{The log of the Weibull density of \farg{y} given shape
\farg{alpha} and scale \farg{sigma}}
%
\fitem{real}{weibull\_cdf}{real \farg{y}, real \farg{alpha}, real
\farg{sigma}}{The Weibull cumulative distribution of \farg{y} given shape
\farg{alpha} and scale \farg{sigma}}
\end{description}
%
\begin{description}
\fitem{real}{weibull\_rng}{real \farg{alpha}, real
  \farg{sigma}}{Generate a weibull variate with shape
  \farg{alpha} and scale \farg{sigma}; may only be used in generated 
quantities block}
\end{description}


\chapter{Positive Lower-Bounded Probabilities}

\noindent
The positive lower-bounded probabilities have support on real values
above some positive minimum value.


\section{Pareto Distribution}

\subsubsection{Probability Density Function}

If $y_0 \in \posreals$ and $\alpha \in \posreals$, then for
$y \in \posreals$,
\[
\distro{Pareto}(y|y_0,\alpha)
=
\alpha 
\ y_0
\, \left( \frac{1}{y} \right)^{\!\alpha+1}
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{pareto\_log}{reals \farg{y}, reals \farg{y\_min}, reals
    \farg{alpha}}{The log of the Pareto density of \farg{y} given
    positive minimum value \farg{y\_min} and shape \farg{alpha}}
%
  \fitem{real}{pareto\_cdf}{reals \farg{y}, reals \farg{y\_min}, reals
    \farg{alpha}}{The Pareto cumulative distribution function of \farg{y} given
    positive minimum value \farg{y\_min} and shape \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{real}{pareto\_rng}{real \farg{y\_min}, real
  \farg{alpha}}{Generate a Pareto variate with positive minimum value \farg{y\_min} and shape \farg{alpha}; may only be used in generated 
quantities block}
\end{description}


\chapter{Continuous Distributions on $[0,1]$}

\noindent
The continuous distributions with outcomes in the interval $[0,1]$ are
used to characterized bounded quantities, including probabilities.


\section{Beta Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \posreals$ and $\beta \in \posreals$, then for $\theta
\in [0,1]$,
\[
\distro{Beta}(\theta|\alpha,\beta)
=
\frac{1}{\Betafun(\alpha,\beta)}
\,
\theta^{\alpha - 1}
\,
(1 - \theta)^{\beta - 1}
,
\] 
where the beta function $\Betafun()$ is as defined in \refsection{betafun}


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{beta\_log}{reals \farg{theta}, reals \farg{alpha}, reals
    \farg{beta}}{The log of the beta density of \code{theta} in $[0,1]$
    given positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}}
%
  \fitem{real}{beta\_cdf}{reals \farg{theta}, reals \farg{alpha}, reals
    \farg{beta}}{The beta cumulative distribution function of \code{theta} in $[0,1]$
    given positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{beta\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a beta variate with positive prior successes (plus one)
    \farg{alpha} and prior failures (plus one) \farg{beta}; may only
    be used in generated quantities block}
\end{description}


\chapter{Bounded Continuous Probabilities}

\noindent
The bounded continuous probabilities have support on a finite interval
of real numbers.



\section{Uniform Distribution}

\subsubsection{Probability Density Function}

If $\alpha \in \reals$ and $\beta \in (\alpha,\infty)$, then for $y
\in [\alpha,\beta]$,
\[
\distro{Uniform}(y|\alpha,\beta)
= 
\frac{1}{\beta - \alpha}
.
\]

\subsubsection{Stan Functions}

\begin{description}
\fitem{real}{uniform\_log}{reals \farg{y}, reals \farg{alpha}, reals
  \farg{beta}}{The log of the uniform density of \farg{y} given lower bound
  \farg{alpha} and upper bound \farg{beta}}
\end{description}
%
\begin{description}
\fitem{real}{uniform\_rng}{real \farg{alpha}, real
  \farg{beta}}{Generate a uniform variate with lower bound
  \farg{alpha} and upper bound \farg{beta}; may only
    be used in generated quantities block}
\end{description}



\chapter{Distributions over Unbounded Vectors}

\noindent
The unbounded vector probability distributions have support on all of
$\reals^K$ for some fixed $K$.


\section{Multivariate Normal Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $\Sigma \in \reals^{K \times
  K}$ is symmetric and positive definite, then for $y \in \reals^K$,
\[
\distro{MultiNormal}(y|\mu,\Sigma)
=
\frac{1}{\left( 2 \pi \right)^{K/2}}
\
\frac{1}{\sqrt{|\Sigma|}}
\
\exp \! \left( \!
- 
\frac{1}{2}
(y - \mu)^{\top} \, \Sigma^{-1} \, (y - \mu)
\right)
\! ,
\]
%
where $|\Sigma|$ is the absolute determinant of $\Sigma$.


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_log}{vector \farg{y}, vector \farg{mu},
  matrix \farg{S}}{The log of the multivariate normal density of vector \farg{y}
 given location \farg{mu} and covariance matrix \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{vector}{multi\_normal\_rng}{vector \farg{mu}, matrix
  \farg{S}}{Generate a multivariate normal variate with location
  \farg{mu} and covariance matrix \farg{S}; may only be used in 
generated quantities block}
\end{description}


\section{Multivariate Normal Distribution, Precision Parameterization}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $\Omega \in \reals^{K \times
  K}$ is symmetric and positive definite, then for $y \in \reals^K$,
%
\[
\distro{MultiNormalPrecision}(y|\mu,\Omega)
= \distro{MultiNormal}(y|\mu,\Sigma^{-1})
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_prec\_log}{vector \farg{y}, vector
  \farg{mu}, matrix \farg{P}}{The log of the multivariate normal density of vector
  \farg{y} given location \farg{mu} and positive definite precision
  matrix \farg{P}}
%
\end{description}



\section{Multivariate Normal Distribution, Cholesky Parameterization}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\mu \in \reals^K$, and $L \in \reals^{K \times K}$ is lower
triangular and such that $LL^{\top}$ is positive definite, then for $y
\in \reals^K$,
\[
\distro{MultiNormalCholesky}(y|\mu,L)
=
\distro{MultiNormal}(y|\mu,LL^{\top}).
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_normal\_cholesky\_log}{vector \farg{y}, vector
  \farg{mu}, matrix \farg{L}}{The log of the multivariate normal density of vector
  \farg{y} given location \farg{mu} and lower-triangular Cholesky
  factor of the covariance matrix \farg{L}}
%
\end{description}



\section{Multivariate Student-$t$ Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in \posreals$, $\mu \in \reals^K$, and $\Sigma
\in \reals^{K \times K}$ is symmetric and positive definite, then for
$y \in \reals^K$,
\[
\begin{array}{l}
\distro{MultiStudentT}(y|\nu,\mu,\Sigma)
\\[8pt]
\displaystyle
\hspace*{8pt}
=
\frac{1}{\pi^{K/2}}
\
\frac{1}{\nu^{K/2}}
\
\frac{\Gamma\!x\left((\nu + K)/2\right)}
     {\Gamma(\nu/2)}
\
\frac{1}{\sqrt{\left| \Sigma \right|}}
\
\left(
1 + \frac{1}{\nu} \, \left(y - \mu\right)^{\top} \, \Sigma^{-1} \, \left(y - \mu\right)
\right)^{-(\nu + K)/2}
\! .
\end{array}
\]
\vspace*{4pt}


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{multi\_student\_t\_log}{vector \farg{y}, real \farg{nu},
  vector \farg{mu}, matrix \farg{S}}{The log of the multivariate Student-$t$
  density of vector \farg{y} given degrees of freedom \farg{nu},
  location \farg{mu}, and scale matrix \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{vector}{multi\_student\_t\_rng}{real \farg{nu}, vector \farg{mu}, matrix
  \farg{S}}{Generate a multivariate Student-$t$ variate with degrees
  of freedom \farg{nu}, location \farg{mu}, and scale matrix \farg{S}; 
may only be used in generated quantities block}
\end{description}

\chapter{Simplex Distributions}

\noindent
The simplex probabilities have support on the unit $K$-simplex for a
specified $K$.  A $K$-dimensional vector $\theta$ is a unit
$K$-simplex if $\theta_k \geq 0$ for $k \in \setlist{1,\ldots,K}$ and
$\sum_{k = 1}^K \theta_k = 1$.


\section{Dirichlet Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$ and $\alpha \in (\posreals)^{K}$, then for
$\theta \in \mbox{$K$-simplex}$, 
\[
\distro{Dirichlet}(\theta|\alpha)
= 
\frac{\Gamma \! \left( \sum_{k=1}^K \alpha_k \right)}
     {\prod_{k=1}^K \Gamma(\alpha_k)}
\
\prod_{k=1}^K \theta_k^{\alpha_k - 1}
.
\]


\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{dirichlet\_log}{vector \farg{theta}, vector
    \farg{alpha}}{ The log of the Dirichlet density for simplex
    \farg{theta} given prior counts (plus one) \farg{alpha}}
\end{description}
%
\begin{description}
\fitem{vector}{dirichlet\_rng}{vector \farg{alpha}}{Generate a
  Dirichlet variate with prior counts (plus one) \farg{alpha}; 
may only be used in generated quantities block}
\end{description}


\chapter{Correlation Matrix Distributions}

\noindent
The correlation matrix distributions have support on the (Cholesky
factors of) correlation matrices.  A Cholesky factor $L$ for a $K
\times K$ covariance matrix of dimensions $K$ has rows of unit length
so that the diagonal of $L L^{\top}$ is the unit $K$-vector.


\section{LKJ Correlation Distribution}

\subsubsection{Probability Density Function}

For $\eta > 0$, if $\Sigma$ a positive-definite, symmetric matrix with
unit diagonal (i.e., a correlation matrix), then
%
\[
\distro{LkjCorr}(\Sigma|\eta)
\propto \det \left( \Sigma \right)^{(\eta - 1)}.
\]
%
The shape parameter $\eta$ can be interpreted like the shape parameter
of a symmetric beta distribution. If $\eta = 1$, then the density is
uniform over all correlation matrices of a given order. If $\eta > 1$,
the identity matrix is the modal correlation matrix, especially as
$\eta$ becomes large. For $0 < \eta < 1$, the density has a trough at
the identity matrix. See \citep{LewandowskiKurowickaJoe:2009} for
definitions.


\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{lkj\_corr\_log}{matrix \farg{y}, real
    \farg{eta}}{The log of the LKJ density for the correlation matrix
    \farg{y} given nonnegative shape \farg{eta}.}
%
\end{description}
\begin{description}
\fitem{matrix}{lkj\_corr\_rng}{int \farg{K}, real \farg{eta}}{Generate a
  LKJ random correlation matrix of order \farg{K} with shape \farg{eta};
  may only be used in generated quantities block}
\end{description}


\section{Cholesky LKJ Correlation Distribution}

\subsubsection{Probability Density Function}

For $\eta > 0$, if $L$ is the Cholesky factor of a positive-definite
matrix with unit diagonal (i.e., a correlation matrix), then
\[
\distro{LkjCholesky}(L|\eta) 
\propto \det(L L^\top)^{(\eta - 1)} 
= \det(L)^{(2 \eta - 2)}.
\]
See the previous section for details on interpreting the shape
parameter $\eta$.

\subsubsection{Stan Functions}

\begin{description}
%
  \fitem{real}{lkj\_corr\_cholesky\_log}{matrix \farg{L}, real
    \farg{eta}}{The log of the LKJ density for the lower-triangular
    Cholesky factor \farg{L} of a correlation matrix given shape
    \farg{eta}.}
%
\end{description}
\begin{description}
\fitem{matrix}{lkj\_corr\_cholesky\_rng}{int \farg{K}, real \farg{eta}}{
  Generate a random Cholesky factor of a LKJ random correlation matrix
  of order \farg{K} with shape \farg{eta}; may only be used in 
  generated quantities block}
\end{description}




\chapter{Covariance Matrix Distributions}

\noindent
The covariance matrix distributions have support on symmetric,
positive-definite $K \times K$ matrices.


\section{Wishart Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in (K-1,\infty)$, and $S \in \reals^{K \times K}$ is symmetric
and positive definite, then for symmetric and positive-definite $W \in
\reals^{K \times K}$,
\[
\distro{Wishart}(W|\nu,S)
=
\frac{1}{2^{\nu K / 2}}
\
\frac{1}{\Gamma_K \! \left( \frac{\nu}{2} \right)}
\
\left| S \right|^{-\nu/2}
\
\left| W \right|^{(\nu - K - 1)/2}
\
\exp \! \left(\frac{1}{2} \ \mbox{tr}\left( S^{-1} W \right) \right)
\! ,
\]
%
where $\mbox{tr}()$ is the matrix trace function, and $\Gamma_K()$ is
the multivariate Gamma function,
\[
\Gamma_K(x) = 
\frac{1}{\pi^{K(K-1)/4}}
\
\prod_{k=1}^K \Gamma \left( x + \frac{1 - k}{2} \right)
\!.
\]


\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{wishart\_log}{matrix \farg{W}, real \farg{nu}, matrix
 \farg{S}}{The log of the Wishart density for positive-definite matrix
 \farg{W} given degrees of freedom \farg{nu} and scale matrix
 \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{matrix}{wishart\_rng}{real \farg{nu}, matrix \farg{S}}{Generate a
  Wishart variate with degrees of freedom \farg{nu} and scale matrix
 \farg{S}; may only be used in generated quantities block}
\end{description}


\section{Inverse Wishart Distribution}

\subsubsection{Probability Density Function}

If $K \in \nats$, $\nu \in (K-1,\infty)$, and $S \in \reals^{K \times
  K}$ is symmetric and positive definite, then for symmetric and
positive-definite $W \in \reals^{K \times K}$,
\[
\distro{InvWishart}(W|\nu,S)
= 
\frac{1}{2^{\nu K / 2}}
\
\frac{1}{\Gamma_K \! \left( \frac{\nu}{2} \right)}
\
\left| S \right|^{\nu/2}
\
\left| W \right|^{-(\nu - K - 1)/2}
\
\exp \! \left( 
- \frac{1}{2}
\
\mbox{tr}(SW^{-1})
\right)
\! .
\]

\subsubsection{Stan Functions}

\begin{description}
%
\fitem{real}{inv\_wishart\_log}{matrix \farg{W}, real \farg{nu}, matrix
 \farg{S}}{The log of the inverse Wishart density for positive-definite matrix
 \farg{W} given degrees of freedom \farg{nu} and scale matrix
 \farg{S}}
%
\end{description}
%
\begin{description}
\fitem{matrix}{inv\_wishart\_rng}{real \farg{nu}, matrix
  \farg{S}}{Generate an inverse Wishart variate with degrees of 
freedom \farg{nu} and scale matrix
 \farg{S}; may only be used in generated quantities block}
\end{description}

\section{LKJ Covariance Distribution}

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{lkj\_cov\_log}{matrix \farg{W}, vector \farg{mu},
    vector \farg{sigma}, real \farg{eta}}{The log of the LKJ density
    for covariance matrix \farg{W} is the sum of log of the lognormal
    density of the standard deviations given location vector \farg{mu}
    and scale vector \farg{sigma} and the log of the lkj\_corr density
    of the correlation matrix given shape \farg{eta}.  See the next
    section for details on the lkj\_corr density.}
\end{description}


\chapter{Circular Distributions}

\noindent
Circular distributions are defined for finite values \farg{y} in any interval of length $2\pi$.


\section{Von Mises Distribution}

\subsubsection{Probability Density Function}

If $\mu \in \reals$ and $\kappa \in \posreals$, then for $y \in
\reals$,
\[
\distro{VonMises}(y|\mu,\kappa)
=
\frac{\exp(\kappa\cos(y-\mu))}{2\pi I_0(\kappa)}
\!.
\]

\subsubsection{Stan Functions}

\begin{description}
  \fitem{real}{von\_mises\_log}{reals \farg{y}, reals \farg{mu}, reals
    \farg{kappa}}{The log of the von mises density of \farg{y} given
    location \farg{mu} and scale \farg{kappa}}
\end{description}



{'fraction_non_alphanumeric': 0.17266744953803204, 'fraction_numerical': 0.005771829924888662, 'mean_word_length': 4.138733917795742, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2966902', 'n_tokens_mistral': 33394, 'n_tokens_neox': 32470, 'n_words': 8778}