# Wishart: Wishart distribution In mixAK: Multivariate Normal Mixture Models and Mixtures of Generalized Linear Mixed Models Including Model Based Clustering

## Description

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.

Prior to version 3.4-1 of this package, functions `dWISHART` and `rWISHART` were called as `dWishart` and `rWishart`, respectively. The names were changed in order to avoid conflicts with `rWishart` from a standard package `stats`.

## Usage

 ```1 2 3``` ```dWISHART(W, df, S, log=FALSE) rWISHART(n, df, S) ```

## Arguments

 `W` Either a matrix with the same number of rows and columns as `S` (1 point sampled from the Wishart distribution) or a matrix with `ncol` equal to `ncol`*`(ncol+1)`/2 and `n` rows (`n` points sampled from the Wishart distribution for which only lower triangles are given in rows of the matrix `W`). `n` number of observations to be sampled. `df` degrees of freedom of the Wishart distribution. `S` scale matrix of the Wishart distribution. `log` logical; if `TRUE`, log-density is computed

## Details

The density of the Wishart distribution is the following

f(W) = (2^{nu*p/2} * pi^{p*(p-1)/4} * prod[i=1]^p Gamma((nu + 1 - i)/2))^{-1} * |S|^{-nu/2} * |W|^{(nu - p - 1)/2} * exp(-0.5*tr(S^{-1}*W)),

where p is number of rows and columns of the matrix W.

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).

Some objects.

## Value for dWISHART

A numeric vector with evaluated (log-)density.

## Value for rWISHART

If `n` equals 1 then a sampled symmetric matrix W is returned.

If `n` > 1 then a matrix with sampled points (lower triangles of W) in rows is returned.

## Author(s)

Arnošt Komárek arnost.komarek[AT]mff.cuni.cz

## References

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.

`rWishart`.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53``` ```set.seed(1977) ### The same as gamma(shape=df/2, rate=1/(2*S)) df <- 1 S <- 3 w <- rWISHART(n=1000, df=df, S=S) mean(w) ## should be close to df*S var(w) ## should be close to 2*df*S^2 dWISHART(w[1], df=df, S=S) dWISHART(w[1], df=df, S=S, log=TRUE) dens.w <- dWISHART(w, df=df, S=S) dens.wG <- dgamma(w, shape=df/2, rate=1/(2*S)) rbind(dens.w[1:10], dens.wG[1:10]) ldens.w <- dWISHART(w, df=df, S=S, log=TRUE) ldens.wG <- dgamma(w, shape=df/2, rate=1/(2*S), log=TRUE) rbind(ldens.w[1:10], ldens.wG[1:10]) ### Bivariate Wishart df <- 2 S <- matrix(c(1,3,3,13), nrow=2) print(w2a <- rWISHART(n=1, df=df, S=S)) dWISHART(w2a, df=df, S=S) w2 <- rWISHART(n=1000, df=df, S=S) print(w2[1:10,]) apply(w2, 2, mean) ## should be close to df*S (df*S)[lower.tri(S, diag=TRUE)] dens.w2 <- dWISHART(w2, df=df, S=S) ldens.w2 <- dWISHART(w2, df=df, S=S, log=TRUE) cbind(w2[1:10,], data.frame(Density=dens.w2[1:10], Log.Density=ldens.w2[1:10])) ### Trivariate Wishart df <- 3.5 S <- matrix(c(1,2,3,2,20,26,3,26,70), nrow=3) print(w3a <- rWISHART(n=1, df=df, S=S)) dWISHART(w3a, df=df, S=S) w3 <- rWISHART(n=1000, df=df, S=S) print(w3[1:10,]) apply(w3, 2, mean) ## should be close to df*S (df*S)[lower.tri(S, diag=TRUE)] dens.w3 <- dWISHART(w3, df=df, S=S) ldens.w3 <- dWISHART(w3, df=df, S=S, log=TRUE) cbind(w3[1:10,], data.frame(Density=dens.w3[1:10], Log.Density=ldens.w3[1:10])) ```

### Example output

```Loading required package: colorspace

### Mixture of methods including mixtures
### Arnost Komarek

### See citation("mixAK") or toBibtex(citation("mixAK")) for the best way to cite
### the package if you find it useful.

[1] 2.967794
[1] 19.43923
[1] 0.0588085
[1] -2.833469
1         2         3        4         5         6         7
[1,] 0.0588085 0.1449037 0.3470858 3.054181 0.2388643 0.1074662 0.1479219
[2,] 0.0588085 0.1449037 0.3470858 3.054181 0.2388643 0.1074662 0.1479219
8         9       10
[1,] 0.8135921 0.7172008 2.210538
[2,] 0.8135921 0.7172008 2.210538
1         2         3        4        5         6         7
[1,] -2.833469 -1.931686 -1.058183 1.116511 -1.43186 -2.230579 -1.911071
[2,] -2.833469 -1.931686 -1.058183 1.116511 -1.43186 -2.230579 -1.911071
8          9        10
[1,] -0.2062962 -0.3323995 0.7932361
[2,] -0.2062962 -0.3323995 0.7932361
[,1]      [,2]
[1,] 0.341001  2.091936
[2,] 2.091936 17.844946
[1] 0.00451184
(1.1)      (2.1)      (2.2)
1   3.46855249  7.9162578  35.985898
2   1.77611610  0.5697106   2.019978
3   7.71710352 26.4729448  91.249136
4   0.95528853  1.5859176   4.814772
5   0.92952209 -0.4209225  14.579903
6   0.47219029  0.4200592   4.743177
7   2.98564445 15.7761746  91.794062
8   2.36146714  5.6494757  13.518222
9   0.01211207  0.2777356  13.394315
10 12.24134582 34.2778524 104.200794
(1.1)     (2.1)     (2.2)
2.057971  6.160985 26.490188
[1]  2  6 26
(1.1)      (2.1)      (2.2)      Density Log.Density
1   3.46855249  7.9162578  35.985898 3.793826e-05  -10.179551
2   1.77611610  0.5697106   2.019978 7.317531e-04   -7.220067
3   7.71710352 26.4729448  91.249136 1.813020e-04   -8.615347
4   0.95528853  1.5859176   4.814772 5.251182e-03   -5.249302
5   0.92952209 -0.4209225  14.579903 1.415763e-04   -8.862672
6   0.47219029  0.4200592   4.743177 4.870213e-03   -5.324618
7   2.98564445 15.7761746  91.794062 4.431984e-05  -10.024078
8   2.36146714  5.6494757  13.518222 6.920151e-02   -2.670733
9   0.01211207  0.2777356  13.394315 1.543682e-02   -4.171000
10 12.24134582 34.2778524 104.200794 1.467829e-06  -13.431726
[,1]      [,2]      [,3]
[1,]  4.420618  14.92187  10.96118
[2,] 14.921869 101.44288 100.68469
[3,] 10.961177 100.68469 126.92317
[1] 7.86458e-11
(1.1)      (2.1)     (3.1)       (2.2)      (3.2)     (3.3)
1   1.575966  0.1652046 12.906412  24.1248781  41.104651 261.35484
2   3.083901  6.9410265  1.669144  85.6338825  38.009242  19.75609
3   6.948168 12.9984221 14.240827  57.8778758  67.564201 274.41267
4   6.089056 10.1538141 18.463781  82.0256934 156.165259 430.56446
5   4.977367 13.2492356 25.247122 132.0954065 161.218745 339.45961
6   5.169670  9.9097134 12.311678  55.2284374  98.241472 202.10080
7  10.762091 22.7189887 49.352652  59.8707432  90.608935 296.57284
8   3.037555 17.9022981 11.649918 145.4420432  37.573954 185.20094
9   0.630428 -0.4079311 -1.953571   0.4067281   1.778779 167.44650
10  2.133667  5.1083065 11.612041  51.2147903 179.996712 669.65562
(1.1)      (2.1)      (3.1)      (2.2)      (3.2)      (3.3)
3.452541   7.036285  10.523561  72.353371  96.256739 254.865072
[1]   3.5   7.0  10.5  70.0  91.0 245.0
(1.1)      (2.1)     (3.1)       (2.2)      (3.2)     (3.3)      Density
1   1.575966  0.1652046 12.906412  24.1248781  41.104651 261.35484 1.243326e-10
2   3.083901  6.9410265  1.669144  85.6338825  38.009242  19.75609 1.405562e-10
3   6.948168 12.9984221 14.240827  57.8778758  67.564201 274.41267 3.157100e-12
4   6.089056 10.1538141 18.463781  82.0256934 156.165259 430.56446 2.813189e-12
5   4.977367 13.2492356 25.247122 132.0954065 161.218745 339.45961 2.526182e-12
6   5.169670  9.9097134 12.311678  55.2284374  98.241472 202.10080 1.161716e-10
7  10.762091 22.7189887 49.352652  59.8707432  90.608935 296.57284 3.129837e-12
8   3.037555 17.9022981 11.649918 145.4420432  37.573954 185.20094 9.543639e-13
9   0.630428 -0.4079311 -1.953571   0.4067281   1.778779 167.44650 2.235773e-09
10  2.133667  5.1083065 11.612041  51.2147903 179.996712 669.65562 2.020762e-11
Log.Density
1    -22.80806
2    -22.68541
3    -26.48137
4    -26.59670
5    -26.70431
6    -22.87595
7    -26.49004
8    -27.67773
9    -19.91868
10   -24.62496
```

mixAK documentation built on May 21, 2018, 5:04 p.m.