R/rmvnormcanon.R
rmvnormcanon.Rd
Draw random vectors from multivariate Gaussian in canonical form
rmvnormcanon(n, b, P)
Number of draws
b parameter
Precision matrix
matrix with n columns, vector if n=1
P<-matrix(c(1,.5,.5,1),ncol=2)
b=c(2,0)
# expected value and covariance matrix
Sigma = solve(P)
mu = b%*%Sigma
# sample
x<-rmvnormcanon(1000,b,P)
mu.hat=apply(x,1,mean)
print(mu.hat-mu)
#> [,1] [,2]
#> [1,] 0.050632 -0.0365172
Sigma.hat=var(t(x))
print(Sigma.hat-Sigma)
#> [,1] [,2]
#> [1,] -0.030764562 -0.002954267
#> [2,] -0.002954267 0.037434675