Title: | Cholesky Decomposition of the Wishart Distribution |
---|---|
Description: | Sampling from the Cholesky factorization of a Wishart random variable, sampling from the inverse Wishart distribution, sampling from the Cholesky factorization of an inverse Wishart random variable, sampling from the pseudo Wishart distribution, sampling from the generalized inverse Wishart distribution, computing densities for the Wishart and inverse Wishart distributions, and computing the multivariate gamma and digamma functions. Provides a header file so the C functions can be called directly from other programs. |
Authors: | Geoffrey Thompson [aut, cre] , R Core Team [ctb] |
Maintainer: | Geoffrey Thompson <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.4 |
Built: | 2024-11-18 06:27:28 UTC |
Source: | CRAN |
Compute the density of an observation of a random Wishart distributed matrix
(dWishart
) or an observation
from the inverse Wishart distribution (dInvWishart
).
dWishart(x, df, Sigma, log = TRUE) dInvWishart(x, df, Sigma, log = TRUE)
dWishart(x, df, Sigma, log = TRUE) dInvWishart(x, df, Sigma, log = TRUE)
x |
positive definite |
df |
numeric parameter, "degrees of freedom". |
Sigma |
positive definite |
log |
logical, whether to return value on the log scale. |
Note there are different ways of parameterizing the Inverse
Wishart distribution, so check which one you need.
Here, If then
.
Dawid (1981) has a different definition: if
and
, then
,
where
.
Density or log of density
dInvWishart()
: density for the inverse Wishart distribution.
Dawid, A. (1981). Some Matrix-Variate Distribution Theory: Notational Considerations and a Bayesian Application. Biometrika, 68(1), 265-274. doi:10.2307/2335827
Gupta, A. K. and D. K. Nagar (1999). Matrix variate distributions. Chapman and Hall.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
set.seed(20180222) A <- rWishart(1, 10, diag(4))[, , 1] A dWishart(x = A, df = 10, Sigma = diag(4L), log = TRUE) dInvWishart(x = solve(A), df = 10, Sigma = diag(4L), log = TRUE)
set.seed(20180222) A <- rWishart(1, 10, diag(4))[, , 1] A dWishart(x = A, df = 10, Sigma = diag(4L), log = TRUE) dInvWishart(x = solve(A), df = 10, Sigma = diag(4L), log = TRUE)
A special mathematical function related to the gamma function,
generalized for multivariate gammas. lmvgamma
is the log of the
multivariate gamma, mvgamma
.
The multivariate gamma function for a dimension p is defined as:
For , this is the same as the usual gamma function.
lmvgamma(x, p) mvgamma(x, p)
lmvgamma(x, p) mvgamma(x, p)
x |
non-negative numeric vector, matrix, or array |
p |
positive integer, dimension of a square matrix |
For lmvgamma
log of multivariate gamma of dimension p
for each entry of x
. For non-log variant,
use mvgamma
.
mvgamma()
: Multivariate gamma function.
A. K. Gupta and D. K. Nagar 1999. Matrix variate distributions. Chapman and Hall.
Multivariate gamma function. In Wikipedia, The Free Encyclopedia,from https://en.wikipedia.org/w/index.php?title=Multivariate_gamma_function
lgamma(1:12) lmvgamma(1:12, 1L) mvgamma(1:12, 1L) gamma(1:12)
lgamma(1:12) lmvgamma(1:12, 1L) mvgamma(1:12, 1L) gamma(1:12)
A special mathematical function related to the gamma function,
generalized for multivariate distributions.
The multivariate digamma function is the derivative of the log of the
multivariate gamma function; for it is the same as the
univariate digamma function.
where is the univariate digamma function (the
derivative of the log-gamma function).
mvdigamma(x, p)
mvdigamma(x, p)
x |
non-negative numeric vector, matrix, or array |
p |
positive integer, dimension of a square matrix |
vector of values of multivariate digamma function.
A. K. Gupta and D. K. Nagar 1999. Matrix variate distributions. Chapman and Hall.
Multivariate gamma function. In Wikipedia, The Free Encyclopedia,from https://en.wikipedia.org/w/index.php?title=Multivariate_gamma_function
gamma
, lgamma
,
digamma
, and mvgamma
digamma(1:10) mvdigamma(1:10, 1L)
digamma(1:10) mvdigamma(1:10, 1L)
Generate n random matrices, distributed according
to the Cholesky factorization of a Wishart distribution with
parameters Sigma
and df
,
(known as the Bartlett decomposition
in the context of Wishart random matrices).
rCholWishart(n, df, Sigma)
rCholWishart(n, df, Sigma)
n |
integer sample size. |
df |
numeric parameter, "degrees of freedom". |
Sigma |
positive definite |
a numeric array, say R
, of dimension
,
where each
R[,,i]
is a Cholesky decomposition of a sample
from the Wishart distribution . Based on a
modification of the existing code for the
rWishart
function.
Anderson, T. W. (2003). An Introduction to Multivariate Statistical Analysis (3rd ed.). Hoboken, N. J.: Wiley Interscience.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
A. K. Gupta and D. K. Nagar 1999. Matrix variate distributions. Chapman and Hall.
# How it is parameterized: set.seed(20180211) A <- rCholWishart(1L, 10, 3 * diag(5L))[, , 1] A set.seed(20180211) B <- rInvCholWishart(1L, 10, 1 / 3 * diag(5L))[, , 1] B crossprod(A) %*% crossprod(B) set.seed(20180211) C <- chol(stats::rWishart(1L, 10, 3 * diag(5L))[, , 1]) C
# How it is parameterized: set.seed(20180211) A <- rCholWishart(1L, 10, 3 * diag(5L))[, , 1] A set.seed(20180211) B <- rInvCholWishart(1L, 10, 1 / 3 * diag(5L))[, , 1] B crossprod(A) %*% crossprod(B) set.seed(20180211) C <- chol(stats::rWishart(1L, 10, 3 * diag(5L))[, , 1]) C
Generate n random matrices, distributed according
to the generalized inverse Wishart distribution with parameters
Sigma
and df
, ,
with sample size
df
less than the dimension p
.
Let ,
be
df
observations of a multivariate normal distribution with mean 0 and
covariance Sigma
. Then is distributed as a pseudo
Wishart
. Sometimes this is called a
singular Wishart distribution, however, that can be confused with the case
where
itself is singular. Then the generalized inverse
Wishart distribution is the natural extension of the inverse Wishart using
the Moore-Penrose pseudo-inverse. This can generate samples for positive
semi-definite
however, a function dedicated to generating
singular normal random distributions or singular pseudo Wishart distributions
should be used if that is desired.
Note there are different ways of parameterizing the Inverse
Wishart distribution, so check which one you need.
Here, if then
.
Dawid (1981) has a different definition: if
and
, then
,
where
.
rGenInvWishart(n, df, Sigma)
rGenInvWishart(n, df, Sigma)
n |
integer sample size. |
df |
integer parameter, "degrees of freedom", should be less than the
dimension of |
Sigma |
positive semi-definite |
a numeric array, say R
, of dimension
,
where each
R[,,i]
is a realization of the pseudo Wishart
distribution .
Diaz-Garcia, Jose A, Ramon Gutierrez Jaimez, and Kanti V Mardia. 1997. “Wishart and Pseudo-Wishart Distributions and Some Applications to Shape Theory.” Journal of Multivariate Analysis 63 (1): 73–87. doi:10.1006/jmva.1997.1689.
Bodnar, T., Mazur, S., Podgórski, K. "Singular inverse Wishart distribution and its application to portfolio theory", Journal of Multivariate Analysis, Volume 143, 2016, Pages 314-326, ISSN 0047-259X, doi:10.1016/j.jmva.2015.09.021.
Bodnar, T., Okhrin, Y., "Properties of the singular, inverse and generalized inverse partitioned Wishart distributions", Journal of Multivariate Analysis, Volume 99, Issue 10, 2008, Pages 2389-2405, ISSN 0047-259X, doi:10.1016/j.jmva.2008.02.024.
Uhlig, Harald. "On Singular Wishart and Singular Multivariate Beta Distributions." Ann. Statist. 22 (1994), no. 1, 395–405. doi:10.1214/aos/1176325375.
rWishart
, rInvWishart
,
and rPseudoWishart
set.seed(20181228) A <- rGenInvWishart(1L, 4L, 5.0 * diag(5L))[, , 1] A # A should be singular eigen(A)$values set.seed(20181228) B <- rPseudoWishart(1L, 4L, 5.0 * diag(5L))[, , 1] # A should be a Moore-Penrose pseudo-inverse of B B # this should be equal to B B %*% A %*% B # this should be equal to A A %*% B %*% A
set.seed(20181228) A <- rGenInvWishart(1L, 4L, 5.0 * diag(5L))[, , 1] A # A should be singular eigen(A)$values set.seed(20181228) B <- rPseudoWishart(1L, 4L, 5.0 * diag(5L))[, , 1] # A should be a Moore-Penrose pseudo-inverse of B B # this should be equal to B B %*% A %*% B # this should be equal to A A %*% B %*% A
Generate n random matrices, distributed according
to the Cholesky factor of an inverse Wishart distribution with
parameters Sigma
and df
, .
Note there are different ways of parameterizing the Inverse
Wishart distribution, so check which one you need.
Here, if then
.
Dawid (1981) has a different definition: if
and
, then
,
where
.
rInvCholWishart(n, df, Sigma)
rInvCholWishart(n, df, Sigma)
n |
integer sample size. |
df |
numeric parameter, "degrees of freedom". |
Sigma |
positive definite |
a numeric array, say R
, of dimension
,
where each
R[,,i]
is a Cholesky decomposition of a realization
of the Wishart distribution .
Based on a modification of the existing code for the
rWishart
function
Anderson, T. W. (2003). An Introduction to Multivariate Statistical Analysis (3rd ed.). Hoboken, N. J.: Wiley Interscience.
Dawid, A. (1981). Some Matrix-Variate Distribution Theory: Notational Considerations and a Bayesian Application. Biometrika, 68(1), 265-274. doi:10.2307/2335827
Gupta, A. K. and D. K. Nagar (1999). Matrix variate distributions. Chapman and Hall.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
rWishart
and rCholWishart
# How it is parameterized: set.seed(20180211) A <- rCholWishart(1L, 10, 3 * diag(5L))[, , 1] A set.seed(20180211) B <- rInvCholWishart(1L, 10, 1 / 3 * diag(5L))[, , 1] B crossprod(A) %*% crossprod(B) set.seed(20180211) C <- chol(stats::rWishart(1L, 10, 3 * diag(5L))[, , 1]) C
# How it is parameterized: set.seed(20180211) A <- rCholWishart(1L, 10, 3 * diag(5L))[, , 1] A set.seed(20180211) B <- rInvCholWishart(1L, 10, 1 / 3 * diag(5L))[, , 1] B crossprod(A) %*% crossprod(B) set.seed(20180211) C <- chol(stats::rWishart(1L, 10, 3 * diag(5L))[, , 1]) C
Generate n random matrices, distributed according
to the inverse Wishart distribution with parameters Sigma
and
df
, .
Note there are different ways of parameterizing the Inverse
Wishart distribution, so check which one you need.
Here, if then
.
Dawid (1981) has a different definition: if
and
, then
,
where
.
rInvWishart(n, df, Sigma)
rInvWishart(n, df, Sigma)
n |
integer sample size. |
df |
numeric parameter, "degrees of freedom". |
Sigma |
positive definite |
a numeric array, say R
, of dimension
,
where each
R[,,i]
is a realization of the inverse Wishart distribution
.
Based on a modification of the existing code for the
rWishart
function.
Dawid, A. (1981). Some Matrix-Variate Distribution Theory: Notational Considerations and a Bayesian Application. Biometrika, 68(1), 265-274. doi:10.2307/2335827
Gupta, A. K. and D. K. Nagar (1999). Matrix variate distributions. Chapman and Hall.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
rWishart
, rCholWishart
,
and rInvCholWishart
set.seed(20180221) A <- rInvWishart(1L, 10, 5 * diag(5L))[, , 1] set.seed(20180221) B <- stats::rWishart(1L, 10, .2 * diag(5L))[, , 1] A %*% B
set.seed(20180221) A <- rInvWishart(1L, 10, 5 * diag(5L))[, , 1] set.seed(20180221) B <- stats::rWishart(1L, 10, .2 * diag(5L))[, , 1] A %*% B
Generate n random matrices, distributed according
to the pseudo Wishart distribution with parameters Sigma
and
df
, , with sample size
df
less than the dimension p
.
Let ,
be
df
observations of a multivariate normal distribution with mean 0 and
covariance Sigma
. Then is distributed as a pseudo
Wishart
. Sometimes this is called a
singular Wishart distribution, however, that can be confused with the case
where
itself is singular. If cases with a singular
are desired, this function cannot provide them.
rPseudoWishart(n, df, Sigma)
rPseudoWishart(n, df, Sigma)
n |
integer sample size. |
df |
integer parameter, "degrees of freedom", should be less than the
dimension of |
Sigma |
positive definite |
a numeric array, say R
, of dimension
,
where each
R[,,i]
is a realization of the pseudo Wishart
distribution .
Diaz-Garcia, Jose A, Ramon Gutierrez Jaimez, and Kanti V Mardia. 1997. “Wishart and Pseudo-Wishart Distributions and Some Applications to Shape Theory.” Journal of Multivariate Analysis 63 (1): 73–87. doi:10.1006/jmva.1997.1689.
Uhlig, Harald. "On Singular Wishart and Singular Multivariate Beta Distributions." Ann. Statist. 22 (1994), no. 1, 395–405. doi:10.1214/aos/1176325375.
rWishart
, rInvWishart
,
and rGenInvWishart
set.seed(20181227) A <- rPseudoWishart(1L, 4L, 5.0 * diag(5L))[, , 1] # A should be singular eigen(A)$values
set.seed(20181227) A <- rPseudoWishart(1L, 4L, 5.0 * diag(5L))[, , 1] # A should be singular eigen(A)$values