# Distributions over Unbounded Vectors

The unbounded vector probability distributions have support on all of $$\mathbb{R}^K$$ for some fixed $$K$$.

## Multivariate normal distribution

### Probability density function

If $$K \in \mathbb{N}$$, $$\mu \in \mathbb{R}^K$$, and $$\Sigma \in \mathbb{R}^{K \times K}$$ is symmetric and positive definite, then for $$y \in \mathbb{R}^K$$, $\begin{equation*} \text{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) \! , \end{equation*}$ where $$|\Sigma|$$ is the absolute determinant of $$\Sigma$$.

### Distribution statement

y ~ multi_normal(mu, Sigma)

Increment target log probability density with multi_normal_lupdf(y | mu, Sigma).

Available since 2.0

### Stan functions

The multivariate normal probability function is overloaded to allow the variate vector $$y$$ and location vector $$\mu$$ to be vectors or row vectors (or to mix the two types). The density function is also vectorized, so it allows arrays of row vectors or vectors as arguments; see section vectorized function signatures for a description of vectorization.

real multi_normal_lpdf(vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and covariance matrix Sigma

Available since 2.12

real multi_normal_lupdf(vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and covariance matrix Sigma dropping constant additive terms

Available since 2.25

real multi_normal_lpdf(vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and covariance matrix Sigma

Available since 2.12

real multi_normal_lupdf(vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and covariance matrix Sigma dropping constant additive terms

Available since 2.25

real multi_normal_lpdf(row_vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and covariance matrix Sigma

Available since 2.12

real multi_normal_lupdf(row_vectors y | vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and covariance matrix Sigma dropping constant additive terms

Available since 2.25

real multi_normal_lpdf(row_vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and covariance matrix Sigma

Available since 2.12

real multi_normal_lupdf(row_vectors y | row_vectors mu, matrix Sigma)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and covariance matrix Sigma dropping constant additive terms

Available since 2.25

Although there is a direct multi-normal RNG function, if more than one result is required, it’s much more efficient to Cholesky factor the covariance matrix and call multi_normal_cholesky_rng; see section multi-variate normal, cholesky parameterization.

vector multi_normal_rng(vector mu, matrix Sigma)
Generate a multivariate normal variate with location mu and covariance matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.0

vector multi_normal_rng(row_vector mu, matrix Sigma)
Generate a multivariate normal variate with location mu and covariance matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_normal_rng(vectors mu, matrix Sigma)
Generate an array of multivariate normal variates with locations mu and covariance matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_normal_rng(row_vectors mu, matrix Sigma)
Generate an array of multivariate normal variates with locations mu and covariance matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.18

## Multivariate normal distribution, precision parameterization

### Probability density function

If $$K \in \mathbb{N}$$, $$\mu \in \mathbb{R}^K$$, and $$\Omega \in \mathbb{R}^{K \times K}$$ is symmetric and positive definite, then for $$y \in \mathbb{R}^K$$, $\begin{equation*} \text{MultiNormalPrecision}(y|\mu,\Omega) = \text{MultiNormal}(y|\mu,\Omega^{-1}) \end{equation*}$

### Distribution statement

y ~ multi_normal_prec(mu, Omega)

Increment target log probability density with multi_normal_prec_lupdf(y | mu, Omega).

Available since 2.3

### Stan functions

real multi_normal_prec_lpdf(vectors y | vectors mu, matrix Omega)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and positive definite precision matrix Omega

Available since 2.18

real multi_normal_prec_lupdf(vectors y | vectors mu, matrix Omega)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and positive definite precision matrix Omega dropping constant additive terms

Available since 2.25

real multi_normal_prec_lpdf(vectors y | row_vectors mu, matrix Omega)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and positive definite precision matrix Omega

Available since 2.18

real multi_normal_prec_lupdf(vectors y | row_vectors mu, matrix Omega)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and positive definite precision matrix Omega dropping constant additive terms

Available since 2.25

real multi_normal_prec_lpdf(row_vectors y | vectors mu, matrix Omega)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and positive definite precision matrix Omega

Available since 2.18

real multi_normal_prec_lupdf(row_vectors y | vectors mu, matrix Omega)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and positive definite precision matrix Omega dropping constant additive terms

Available since 2.25

real multi_normal_prec_lpdf(row_vectors y | row_vectors mu, matrix Omega)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and positive definite precision matrix Omega

Available since 2.18

real multi_normal_prec_lupdf(row_vectors y | row_vectors mu, matrix Omega)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and positive definite precision matrix Omega dropping constant additive terms

Available since 2.25

## Multivariate normal distribution, Cholesky parameterization

### Probability density function

If $$K \in \mathbb{N}$$, $$\mu \in \mathbb{R}^K$$, and $$L \in \mathbb{R}^{K \times K}$$ is lower triangular and such that $$LL^{\top}$$ is positive definite, then for $$y \in \mathbb{R}^K$$, $\begin{equation*} \text{MultiNormalCholesky}(y|\mu,L) = \text{MultiNormal}(y|\mu,LL^{\top}). \end{equation*}$ If $$L$$ is lower triangular and $$LL^{top}$$ is a $$K \times K$$ positive definite matrix, then $$L_{k,k}$$ must be strictly positive for $$k \in 1{:}K$$. If an $$L$$ is provided that is not the Cholesky factor of a positive-definite matrix, the probability functions will raise errors.

### Distribution statement

y ~ multi_normal_cholesky(mu, L)

Increment target log probability density with multi_normal_cholesky_lupdf(y | mu, L).

Available since 2.0

### Stan functions

real multi_normal_cholesky_lpdf(vectors y | vectors mu, matrix L)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L

Available since 2.18

real multi_normal_cholesky_lupdf(vectors y | vectors mu, matrix L)
The log of the multivariate normal density of vector(s) y given location vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L dropping constant additive terms

Available since 2.25

real multi_normal_cholesky_lpdf(vectors y | row_vectors mu, matrix L)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L

Available since 2.18

real multi_normal_cholesky_lupdf(vectors y | row_vectors mu, matrix L)
The log of the multivariate normal density of vector(s) y given location row vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L dropping constant additive terms

Available since 2.25

real multi_normal_cholesky_lpdf(row_vectors y | vectors mu, matrix L)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L

Available since 2.18

real multi_normal_cholesky_lupdf(row_vectors y | vectors mu, matrix L)
The log of the multivariate normal density of row vector(s) y given location vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L dropping constant additive terms

Available since 2.25

real multi_normal_cholesky_lpdf(row_vectors y | row_vectors mu, matrix L)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L

Available since 2.18

real multi_normal_cholesky_lupdf(row_vectors y | row_vectors mu, matrix L)
The log of the multivariate normal density of row vector(s) y given location row vector(s) mu and lower-triangular Cholesky factor of the covariance matrix L dropping constant additive terms

Available since 2.25

vector multi_normal_cholesky_rng(vector mu, matrix L)
Generate a multivariate normal variate with location mu and lower-triangular Cholesky factor of the covariance matrix L; may only be used in transformed data and generated quantities blocks

Available since 2.3

vector multi_normal_cholesky_rng(row_vector mu, matrix L)
Generate a multivariate normal variate with location mu and lower-triangular Cholesky factor of the covariance matrix L; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_normal_cholesky_rng(vectors mu, matrix L)
Generate an array of multivariate normal variates with locations mu and lower-triangular Cholesky factor of the covariance matrix L; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_normal_cholesky_rng(row_vectors mu, matrix L)
Generate an array of multivariate normal variates with locations mu and lower-triangular Cholesky factor of the covariance matrix L; may only be used in transformed data and generated quantities blocks

Available since 2.18

## Multivariate Gaussian process distribution

### Probability density function

If $$K,N \in \mathbb{N}$$, $$\Sigma \in \mathbb{R}^{N \times N}$$ is symmetric, positive definite kernel matrix and $$w \in \mathbb{R}^{K}$$ is a vector of positive inverse scales, then for $$y \in \mathbb{R}^{K \times N}$$, $\begin{equation*} \text{MultiGP}(y|\Sigma,w) = \prod_{i=1}^{K} \text{MultiNormal}(y_i|0,w_i^{-1} \Sigma), \end{equation*}$ where $$y_i$$ is the $$i$$th row of $$y$$. This is used to efficiently handle Gaussian Processes with multi-variate outputs where only the output dimensions share a kernel function but vary based on their scale. Note that this function does not take into account the mean prediction.

### Distribution statement

y ~ multi_gp(Sigma, w)

Increment target log probability density with multi_gp_lupdf(y | Sigma, w).

Available since 2.3

### Stan functions

real multi_gp_lpdf(matrix y | matrix Sigma, vector w)
The log of the multivariate GP density of matrix y given kernel matrix Sigma and inverses scales w

Available since 2.12

real multi_gp_lupdf(matrix y | matrix Sigma, vector w)
The log of the multivariate GP density of matrix y given kernel matrix Sigma and inverses scales w dropping constant additive terms

Available since 2.25

## Multivariate Gaussian process distribution, Cholesky parameterization

### Probability density function

If $$K,N \in \mathbb{N}$$, $$L \in \mathbb{R}^{N \times N}$$ is lower triangular and such that $$LL^{\top}$$ is positive definite kernel matrix (implying $$L_{n,n} > 0$$ for $$n \in 1{:}N$$), and $$w \in \mathbb{R}^{K}$$ is a vector of positive inverse scales, then for $$y \in \mathbb{R}^{K \times N}$$, $\begin{equation*} \text{MultiGPCholesky}(y \, | \ L,w) = \prod_{i=1}^{K} \text{MultiNormal}(y_i|0,w_i^{-1} LL^{\top}), \end{equation*}$ where $$y_i$$ is the $$i$$th row of $$y$$. This is used to efficiently handle Gaussian Processes with multi-variate outputs where only the output dimensions share a kernel function but vary based on their scale. If the model allows parameterization in terms of Cholesky factor of the kernel matrix, this distribution is also more efficient than $$\text{MultiGP}()$$. Note that this function does not take into account the mean prediction.

### Distribution statement

y ~ multi_gp_cholesky(L, w)

Increment target log probability density with multi_gp_cholesky_lupdf(y | L, w).

Available since 2.5

### Stan functions

real multi_gp_cholesky_lpdf(matrix y | matrix L, vector w)
The log of the multivariate GP density of matrix y given lower-triangular Cholesky factor of the kernel matrix L and inverses scales w

Available since 2.12

real multi_gp_cholesky_lupdf(matrix y | matrix L, vector w)
The log of the multivariate GP density of matrix y given lower-triangular Cholesky factor of the kernel matrix L and inverses scales w dropping constant additive terms

Available since 2.25

## Multivariate Student-t distribution

### Probability density function

If $$K \in \mathbb{N}$$, $$\nu \in \mathbb{R}^+$$, $$\mu \in \mathbb{R}^K$$, and $$\Sigma \in \mathbb{R}^{K \times K}$$ is symmetric and positive definite, then for $$y \in \mathbb{R}^K$$, $\begin{equation*} \begin{array}{l} \text{MultiStudentT}(y\,|\,\nu,\,\mu,\,\Sigma) \\ = \frac{1}{\pi^{K/2}} \ \frac{1}{\nu^{K/2}} \ \frac{\Gamma\!\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} \end{equation*}$

### Distribution statement

y ~ multi_student_t(nu, mu, Sigma)

Increment target log probability density with multi_student_t_lupdf(y | nu, mu, Sigma).

Available since 2.0

### Stan functions

real multi_student_t_lpdf(vectors y | real nu, vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of vector(s) y given degrees of freedom nu, location vector(s) mu, and scale matrix Sigma

Available since 2.18

real multi_student_t_lupdf(vectors y | real nu, vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of vector(s) y given degrees of freedom nu, location vector(s) mu, and scale matrix Sigma dropping constant additive terms

Available since 2.25

real multi_student_t_lpdf(vectors y | real nu, row_vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of vector(s) y given degrees of freedom nu, location row vector(s) mu, and scale matrix Sigma

Available since 2.18

real multi_student_t_lupdf(vectors y | real nu, row_vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of vector(s) y given degrees of freedom nu, location row vector(s) mu, and scale matrix Sigma dropping constant additive terms

Available since 2.25

real multi_student_t_lpdf(row_vectors y | real nu, vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of row vector(s) y given degrees of freedom nu, location vector(s) mu, and scale matrix Sigma

Available since 2.18

real multi_student_t_lupdf(row_vectors y | real nu, vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of row vector(s) y given degrees of freedom nu, location vector(s) mu, and scale matrix Sigma dropping constant additive terms

Available since 2.25

real multi_student_t_lpdf(row_vectors y | real nu, row_vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of row vector(s) y given degrees of freedom nu, location row vector(s) mu, and scale matrix Sigma

Available since 2.18

real multi_student_t_lupdf(row_vectors y | real nu, row_vectors mu, matrix Sigma)
The log of the multivariate Student-$$t$$ density of row vector(s) y given degrees of freedom nu, location row vector(s) mu, and scale matrix Sigma dropping constant additive terms

Available since 2.25

vector multi_student_t_rng(real nu, vector mu, matrix Sigma)
Generate a multivariate Student-$$t$$ variate with degrees of freedom nu, location mu, and scale matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.0

vector multi_student_t_rng(real nu, row_vector mu, matrix Sigma)
Generate a multivariate Student-$$t$$ variate with degrees of freedom nu, location mu, and scale matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_student_t_rng(real nu, vectors mu, matrix Sigma)
Generate an array of multivariate Student-$$t$$ variates with degrees of freedom nu, locations mu, and scale matrix Sigma; may only be used in transformed data and generated quantities blocks

Available since 2.18

vectors multi_student_t_rng(real nu, row_vectors mu, matrix Sigma)
Generate an array of multivariate Student-$$t$$ variates with degrees of freedom nu, locations mu, and scale matrix Sigma; may only be used in transformed data andgenerated quantities blocks

Available since 2.18

## Multivariate Student-t distribution, Cholesky parameterization

### Probability density function

Let $$K \in \mathbb{N}$$, $$\nu \in \mathbb{R}^+$$, $$\mu \in \mathbb{R}^K$$, and $$L$$ a $$K \times K$$ lower-triangular matrix with strictly positive, finite diagonal then $\begin{equation*} \begin{array}{l} \text{MultiStudentTCholesky}(y\,\mid \nu,\,\mu,\,L) \\ = \frac{1}{\pi^{K/2}} \ \frac{1}{\nu^{K/2}} \ \frac{\Gamma\!\left((\nu + K)/2\right)} {\Gamma(\nu/2)} \ \frac{1}{\left| L \right|} \ \left( 1 + \frac{1}{\nu} \, \left(y - \mu\right)^{\top} \, L^{-T}L^{-1} \, \left(y - \mu\right) \right)^{-(\nu + K)/2} \! . \end{array} \end{equation*}$

### Distribution statement

y ~ multi_student_t_cholesky(nu, mu, L)

Increment target log probability density with multi_student_t_cholesky_lupdf(y | nu, mu, L).

Available since 2.30

### Stan functions

real multi_student_t_cholesky_lpdf(vectors y | real nu, vectors mu, matrix L)
The log of the multivariate Student-$$t$$ density of vector or array of vectors y given degrees of freedom nu, location vector or array of vectors mu, and Cholesky factor of the scale matrix L. For a definition of the arguments compatible with the vectors type, see the probability vectorization section.

Available since 2.30

real multi_student_t_cholesky_lupdf(vectors y | real nu, vectors mu, matrix L)
The log of the multivariate Student-$$t$$ density of vector or vector array y given degrees of freedom nu, location vector or vector array mu, and Cholesky factor of the scale matrix L, dropping constant additive terms. For a definition of arguments compatible with the vectors type, see the probability vectorization section.

Available since 2.30

vector multi_student_t_cholesky_rng(real nu, vector mu, matrix L)
Generate a multivariate Student-$$t$$ variate with degrees of freedom nu, location mu, and Cholesky factor of the scale matrix L; may only be used in transformed data and generated quantities blocks.

Available since 2.30

array[] vector multi_student_t_cholesky_rng(real nu, array[] vector mu, matrix L)
Generate a multivariate Student-$$t$$ variate with degrees of freedom nu, location array mu, and Cholesky factor of the scale matrix L; may only be used in transformed data and generated quantities blocks.

Available since 2.30

array[] vector multi_student_t_cholesky_rng(real nu, array[] row_vector mu, matrix L)
Generate an array of multivariate Student-$$t$$ variate with degrees of freedom nu, location array mu, and Cholesky factor of the scale matrix L; may only be used in transformed data and generated quantities blocks.

Available since 2.30

## Gaussian dynamic linear models

A Gaussian Dynamic Linear model is defined as follows, For $$t \in 1, \dots, T$$, \begin{equation*} \begin{aligned}[t] y_{t} &\sim N(F' \theta_{t}, V) \\ \theta_{t} &\sim N(G \theta_{t - 1}, W) \\ \theta_{0} &\sim N(m_{0}, C_{0}) \end{aligned} \end{equation*} where $$y$$ is $$n \times T$$ matrix where rows are variables and columns are observations. These functions calculate the log-density of the observations marginalizing over the latent states ($$p(y | F, G, V, W, m_{0}, C_{0})$$). This log-density is a system that is calculated using the Kalman Filter. If $$V$$ is diagonal, then a more efficient algorithm which sequentially processes observations and avoids a matrix inversions can be used .

### Distribution statement

y ~ gaussian_dlm_obs(F, G, V, W, m0, C0)

Increment target log probability density with gaussian_dlm_obs_lupdf(y | F, G, V, W, m0, C0).

Available since 2.0

### Stan functions

The following two functions differ in the type of their V, the first taking a full observation covariance matrix V and the second a vector V representing the diagonal of the observation covariance matrix. The sampling statement defined in the previous section works with either type of observation V.

real gaussian_dlm_obs_lpdf(matrix y | matrix F, matrix G, matrix V, matrix W, vector m0, matrix C0)
The log of the density of the Gaussian Dynamic Linear model with observation matrix y in which rows are variables and columns are observations, design matrix F, transition matrix G, observation covariance matrix V, system covariance matrix W, and the initial state is distributed normal with mean m0 and covariance C0.

Available since 2.12

real gaussian_dlm_obs_lupdf(matrix y | matrix F, matrix G, matrix V, matrix W, vector m0, matrix C0)
The log of the density of the Gaussian Dynamic Linear model with observation matrix y in which rows are variables and columns are observations, design matrix F, transition matrix G, observation covariance matrix V, system covariance matrix W, and the initial state is distributed normal with mean m0 and covariance C0. This function drops constant additive terms.

Available since 2.25

real gaussian_dlm_obs_lpdf(matrix y | matrix F, matrix G, vector V, matrix W, vector m0, matrix C0)
The log of the density of the Gaussian Dynamic Linear model with observation matrix y in which rows are variables and columns are observations, design matrix F, transition matrix G, observation covariance matrix with diagonal V, system covariance matrix W, and the initial state is distributed normal with mean m0 and covariance C0.

Available since 2.12

real gaussian_dlm_obs_lupdf(matrix y | matrix F, matrix G, vector V, matrix W, vector m0, matrix C0)
The log of the density of the Gaussian Dynamic Linear model with observation matrix y in which rows are variables and columns are observations, design matrix F, transition matrix G, observation covariance matrix with diagonal V, system covariance matrix W, and the initial state is distributed normal with mean m0 and covariance C0. This function drops constant additive terms.

Available since 2.25

## References

Durbin, J., and S. J. Koopman. 2001. Time Series Analysis by State Space Methods. New York: Oxford University Press.