Fast simulation from and evaluation of multivariate Gaussian probability densities.

dmvnormal(x, mu, sigma)

rmvnormal(n, mu, sigma)

## Arguments

x A p times k matrix of quantiles. Each rows correspond to a realization from the density and each column corresponds to a dimension. The mean vector of dimension k. The variance-covariance matrix of dimension k times k. The number of observations to be simulated.

## Value

dmvnormal returns a $$1$$ by $$p$$ matrix of the probability densities corresponding to each row of x. sigma. Each row corresponds to an observation.

rmvnormal returns a p by k matrix of observations from a multivariate normal distribution with the given mean mu and covariance

## Details

dmvnormal functions similarly to dmvnorm from the mvtnorm-package and likewise for rmvnormal and rmvnorm.

dmvnorm and rmvnorm in the mvtnorm-package.

## Author

Anders Ellern Bilgrau

## Examples

dmvnormal(x = matrix(rnorm(300), 100, 3),
mu = 1:3,
sigma = diag(3))
#>                [,1]
#>   [1,] 4.395865e-06
#>   [2,] 8.985129e-05
#>   [3,] 6.277211e-03
#>   [4,] 2.850900e-03
#>   [5,] 5.370311e-05
#>   [6,] 8.402662e-06
#>   [7,] 6.659393e-04
#>   [8,] 2.425272e-08
#>   [9,] 4.425838e-06
#>  [10,] 3.779227e-04
#>  [11,] 8.564625e-05
#>  [12,] 1.510399e-06
#>  [13,] 9.925569e-03
#>  [14,] 4.143860e-04
#>  [15,] 1.843982e-02
#>  [16,] 8.492447e-10
#>  [17,] 4.441409e-05
#>  [18,] 4.527677e-08
#>  [19,] 1.278954e-06
#>  [20,] 1.046467e-03
#>  [21,] 2.848106e-04
#>  [22,] 3.123517e-06
#>  [23,] 1.651889e-07
#>  [24,] 3.288003e-06
#>  [25,] 1.397543e-03
#>  [26,] 1.670901e-06
#>  [27,] 7.252277e-04
#>  [28,] 1.609289e-06
#>  [29,] 2.113883e-10
#>  [30,] 1.817144e-04
#>  [31,] 6.790490e-07
#>  [32,] 1.256493e-04
#>  [33,] 8.162061e-04
#>  [34,] 2.463785e-04
#>  [35,] 1.155994e-03
#>  [36,] 6.801616e-05
#>  [37,] 6.034439e-08
#>  [38,] 7.306711e-05
#>  [39,] 2.149473e-04
#>  [40,] 4.848281e-04
#>  [41,] 7.983370e-04
#>  [42,] 3.703589e-07
#>  [43,] 1.600543e-06
#>  [44,] 4.667707e-04
#>  [45,] 2.095048e-03
#>  [46,] 2.749692e-07
#>  [47,] 2.664740e-04
#>  [48,] 8.798395e-05
#>  [49,] 3.055017e-05
#>  [50,] 4.552412e-06
#>  [51,] 6.099375e-05
#>  [52,] 8.807570e-04
#>  [53,] 8.699533e-03
#>  [54,] 1.482883e-05
#>  [55,] 6.443309e-06
#>  [56,] 9.001661e-07
#>  [57,] 3.838610e-04
#>  [58,] 1.301324e-05
#>  [59,] 6.552978e-06
#>  [60,] 3.711888e-07
#>  [61,] 9.775338e-07
#>  [62,] 8.154388e-08
#>  [63,] 8.630163e-05
#>  [64,] 4.535630e-05
#>  [65,] 1.549505e-02
#>  [66,] 6.664620e-08
#>  [67,] 1.011343e-03
#>  [68,] 6.766246e-05
#>  [69,] 2.304499e-09
#>  [70,] 1.061191e-03
#>  [71,] 3.717300e-06
#>  [72,] 1.089295e-06
#>  [73,] 9.703943e-07
#>  [74,] 1.002121e-03
#>  [75,] 4.614332e-05
#>  [76,] 7.726395e-04
#>  [77,] 2.913523e-06
#>  [78,] 1.366338e-07
#>  [79,] 7.896864e-04
#>  [80,] 1.953834e-05
#>  [81,] 2.461896e-04
#>  [82,] 1.685075e-04
#>  [83,] 1.719575e-04
#>  [84,] 4.395644e-07
#>  [85,] 1.154500e-04
#>  [86,] 6.591402e-05
#>  [87,] 9.876170e-06
#>  [88,] 1.687666e-06
#>  [89,] 1.743750e-07
#>  [90,] 3.144707e-05
#>  [91,] 3.619485e-05
#>  [92,] 3.062359e-04
#>  [93,] 1.143923e-05
#>  [94,] 3.101002e-10
#>  [95,] 2.966187e-05
#>  [96,] 7.116680e-05
#>  [97,] 6.024713e-06
#>  [98,] 1.043274e-04
#>  [99,] 3.369595e-07
#> [100,] 8.011754e-07rmvnormal(n = 10, mu = 1:4, sigma = diag(4))
#>              [,1]      [,2]     [,3]     [,4]
#>  [1,]  2.28692204 2.2626652 3.106321 2.998199
#>  [2,]  1.45812526 2.5436579 2.391332 3.180132
#>  [3,] -0.45202829 3.0410603 2.698803 3.025448
#>  [4,]  1.07734228 2.1975062 3.976203 4.604309
#>  [5,]  1.55989527 0.3704217 3.456009 4.548788
#>  [6,]  0.92505343 2.1210402 4.294408 4.916433
#>  [7,]  1.78269770 0.3625780 1.866798 6.661566
#>  [8,]  0.82733144 1.4689569 2.130540 3.819743
#>  [9,] -0.05129378 2.9536798 2.245030 4.685015
#> [10,]  1.72945128 0.2793493 2.870365 7.266415