Description Usage Arguments Value References Examples
View source: R/Gamma_Inference.r
Generate random samples from Wishart distribution. For a random matrix x, the density function of Wishart distribution is defined as:
(2^{(df p)/2} Gamma_p(df/2) |rate|^{-df/2})^{-1} |x|^{(df-p-1)/2} exp(-1/2 tr(x rate))
Where x is a pxp symmetric positive definite matrix, Gamma_p() is the multivariate Gamma function of dimension p.
1 |
df |
numeric, the degree of freedom. |
rate |
matrix, a symmetric positive-definite matrix, the 'rate', or 'inverse-scale' parameter. The 'rate' parameter in Wishart is the 'scale' parameter in InvWishart |
scale, |
matrix, the inverse of rate. Only one of 'rate' and 'scale' should be non-NULL. |
A symmetric positive-definite matrix.
Smith, W. B., and R. R. Hocking. "Algorithm as 53: Wishart variate generator." Journal of the Royal Statistical Society. Series C (Applied Statistics) 21.3 (1972): 341-345.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | rate <- crossprod(matrix(rnorm(15),5,3)) #the prior inverse-scale
m <- matrix(0,3,3)
## get 1000 samples and calculate the sample mean
for(i in 1:100){
m <- m+rWishart(df=5,rate=rate)/100
}
## m should roughly equal to df*inverse(rate):
m
pdsInverse(rate)*5
## try generating samples with 'rate' parameter:
scale <- pdsInverse(rate)
m2 <- matrix(0,3,3)
for(i in 1:100){
m2 <- m2+rWishart(df=5,scale=scale)/100
}
## m2 should roughly equal df*scale:
m2
5*scale
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.