rWishart | R Documentation |
Sample from the Wishart distribution
Wishart(nu, S),
where nu are degrees of freedom of the Wishart distribution and S is its scale matrix. The same parametrization as in Gelman (2004) is assumed, that is, if W~Wishart(nu,S) then
E(W) = nu*S
.
In the univariate case, Wishart(nu,S) is the same as Gamma(nu/2, 1/(2*S)).
Generation of random numbers is performed by the algorithm described in Ripley (1987, pp. 99).
rWishart(n, df, S)
n |
number of observations to be sampled. |
df |
degrees of freedom of the Wishart distribution. |
S |
scale matrix of the Wishart distribution. |
Matrix with sampled points (lower triangles of W) in rows.
Arnošt Komárek arnost.komarek@mff.cuni.cz
Gelman, A., Carlin, J. B., Stern, H. S., and Rubin, D. B. (2004). Bayesian Data Analysis, Second edition. Boca Raton: Chapman and Hall/CRC.
Ripley, B. D. (1987). Stochastic Simulation. New York: John Wiley and Sons.
### The same as rgamma(n, shape=df/2, rate=1/(2*S)) n <- 1000 df <- 1 S <- 3 w <- rWishart(n=n, df=df, S=S) mean(w) ## should be close to df*S var(w) ## should be close to 2*df*S^2 ### Multivariate Wishart n <- 1000 df <- 2 S <- matrix(c(1,3,3,13), nrow=2) w <- rWishart(n=n, df=df, S=S) apply(w, 2, mean) ## should be close to df*S df*S df <- 2.5 S <- matrix(c(1,2,3,2,20,26,3,26,70), nrow=3) w <- rWishart(n=n, df=df, S=S) apply(w, 2, mean) ## should be close to df*S df*S
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.