rmvn.RdGenerates multivariate normal or t random deviates, and evaluates the corresponding log densities.
rmvn(n,mu,V)
r.mvt(n,mu,V,df)
dmvn(x,mu,V,R=NULL)
d.mvt(x,mu,V,df,R=NULL)number of simulated vectors required.
the mean of the vectors: either a single vector of length p=ncol(V) or an n by p matrix.
A positive semi definite covariance matrix.
The degrees of freedom for a t distribution.
A vector or matrix to evaluate the log density of.
An optional Cholesky factor of V (not pivoted).
An n row matrix, with each row being a draw from a multivariate normal or t density with covariance matrix V and mean vector mu. Alternatively each row may have a different mean vector if mu is a vector.
For density functions, a vector of log densities.
Uses a `square root' of V to transform standard normal deviates to multivariate normal with the correct covariance matrix.
library(mgcv)
V <- matrix(c(2,1,1,2),2,2)
mu <- c(1,3)
n <- 1000
z <- rmvn(n,mu,V)
crossprod(sweep(z,2,colMeans(z)))/n ## observed covariance matrix
#> [,1] [,2]
#> [1,] 1.959609 1.012001
#> [2,] 1.012001 2.108240
colMeans(z) ## observed mu
#> [1] 0.9734437 3.0243813
dmvn(z,mu,V)
#> [1] -2.506170 -5.631153