Covariance Matrix Distributions

The covariance matrix distributions have support on symmetric, positive-definite K×K matrices or their Cholesky factors (square, lower triangular matrices with positive diagonal elements).

Wishart distribution

Probability density function

If KN, ν(K1,), and SRK×K is symmetric and positive definite, then for symmetric and positive-definite WRK×K, Wishart(Wν,S)=12νK/2 1ΓK(ν2) |S|ν/2 |W|(νK1)/2 exp(12 tr(S1W)), where tr() is the matrix trace function, and ΓK() is the multivariate Gamma function, ΓK(x)=1πK(K1)/4 k=1KΓ(x+1k2).

Distribution statement

W ~ wishart(nu, Sigma)

Increment target log probability density with wishart_lupdf(W | nu, Sigma).

Available since 2.0

Stan functions

real wishart_lpdf(matrix W | real nu, matrix Sigma)
Return the log of the Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma.

Available since 2.12

real wishart_lupdf(matrix W | real nu, matrix Sigma)
Return the log of the Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma dropping constant additive terms.

Available since 2.25

matrix wishart_rng(real nu, matrix Sigma)
Generate a Wishart variate with degrees of freedom nu and symmetric and positive-definite scale matrix Sigma; may only be used in transformed data and generated quantities blocks.

Available since 2.0

Wishart distribution, Cholesky Parameterization

The Cholesky parameterization of the Wishart distribution uses a Cholesky factor for both the variate and the parameter. If S and W are positive definite matrices with Cholesky factors LS and LW (i.e., S=LSLS and W=LWLW), then the Cholesky parameterization is defined so that LWWishartCholesky(ν,LS) if and only if WWishart(ν,S).

Probability density function

If KN, ν(K1,), and LS,LWRK×K are lower triangular matrixes with positive diagonal elements, then the Cholesky parameterized Wishart density is WishartCholesky(LWν,LS)=Wishart(LWLWν,LSLS)|Jf1|, where Jf1 is the Jacobian of the (inverse) transform of the variate, f1(LW)=LWLW. The log absolute determinant is log|Jf1|=Klog(2)+k=1K(Kk+1)log(LW)k,k.

The probability functions will raise errors if νK1 or if LS and LW are not Cholesky factors (square, lower-triangular matrices with positive diagonal elements) of the same size.

Stan functions

real wishart_cholesky_lpdf(matrix L_W | real nu, matrix L_S)
Return the log of the Wishart density for lower-triangular Cholesky factor L_W given degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S.

Available since 2.30

real wishart_cholesky_lupdf(matrix L_W | real nu, matrix L_S)
Return the log of the Wishart density for lower-triangular Cholesky factor of L_W given degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S dropping constant additive terms.

Available since 2.30

matrix wishart_cholesky_rng(real nu, matrix L_S)
Generate the Cholesky factor of a Wishart variate with degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S; may only be used in transformed data and generated quantities blocks

Available since 2.30

Inverse Wishart distribution

Probability density function

If KN, ν(K1,), and SRK×K is symmetric and positive definite, then for symmetric and positive-definite WRK×K, InvWishart(Wν,S)=12νK/2 1ΓK(ν2) |S|ν/2 |W|(ν+K+1)/2 exp(12 tr(SW1)).

Distribution statement

W ~ inv_wishart(nu, Sigma)

Increment target log probability density with inv_wishart_lupdf(W | nu, Sigma).

Available since 2.0

Stan functions

real inv_wishart_lpdf(matrix W | real nu, matrix Sigma)
Return the log of the inverse Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma.

Available since 2.12

real inv_wishart_lupdf(matrix W | real nu, matrix Sigma)
Return the log of the inverse Wishart density for symmetric and positive-definite matrix W given degrees of freedom nu and symmetric and positive-definite scale matrix Sigma dropping constant additive terms.

Available since 2.25

matrix inv_wishart_rng(real nu, matrix Sigma)
Generate an inverse Wishart variate with degrees of freedom nu and symmetric and positive-definite scale matrix Sigma; may only be used in transformed data and generated quantities blocks.

Available since 2.0

Inverse Wishart distribution, Cholesky Parameterization

The Cholesky parameterization of the inverse Wishart distribution uses a Cholesky factor for both the variate and the parameter. If S and W are positive definite matrices with Cholesky factors LS and LW (i.e., S=LSLS and W=LWLW), then the Cholesky parameterization is defined so that LWInvWishartCholesky(ν,LS) if and only if WInvWishart(ν,S).

Probability density function

If KN, ν(K1,), and LS,LWRK×K are lower triangular matrixes with positive diagonal elements, then the Cholesky parameterized inverse Wishart density is InvWishartCholesky(LWν,LS)=InvWishart(LWLWν,LSLS)|Jf1|, where Jf1 is the Jacobian of the (inverse) transform of the variate, f1(LW)=LWLW. The log absolute determinant is log|Jf1|=Klog(2)+k=1K(Kk+1)log(LW)k,k.

The probability functions will raise errors if νK1 or if LS and LW are not Cholesky factors (square, lower-triangular matrices with positive diagonal elements) of the same size.

Stan functions

real inv_wishart_cholesky_lpdf(matrix L_W | real nu, matrix L_S)
Return the log of the inverse Wishart density for lower-triangular Cholesky factor L_W given degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S.

Available since 2.30

real inv_wishart_cholesky_lupdf(matrix L_W | real nu, matrix L_S)
Return the log of the inverse Wishart density for lower-triangular Cholesky factor of L_W given degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S dropping constant additive terms.

Available since 2.30

matrix inv_wishart_cholesky_rng(real nu, matrix L_S)
Generate the Cholesky factor of an inverse Wishart variate with degrees of freedom nu and lower-triangular Cholesky factor of the scale matrix L_S; may only be used in transformed data and generated quantities blocks.

Available since 2.30
Back to top