rmvnormcanon | R Documentation |
Draw random vectors from multivariate Gaussian in canonical form
rmvnormcanon(n, b, P)
n |
Number of draws |
b |
b parameter |
P |
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)
Sigma.hat=var(t(x))
print(Sigma.hat-Sigma)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.