Reputation: 271
I was trying to genrate multi-normal data in R
using mvrnorm
, however, I got errors as:
> epsiloni <- mvrnorm(n = 1, rep(0,8), diag(1), tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
Error in mvrnorm(n = 1, rep(0, 8), diag(1), tol = 1e-06, empirical = FALSE,
: incompatible arguments
But it works fine for other expectation and variance, like
betai <- mvrnorm(n = 1, mu, D, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
where mu
and D
are specified otherwise.
The only difference between these two are just the expectations and the variance, but I did not see anything wrong with the mean and variance in epsiloni
, they are just multi-standard normal.
Thanks!
Upvotes: 2
Views: 1449
Reputation: 48241
Setting Sigma
to diag(1)
, which is a 1x1 matrix, is the problem. If you want an identity covariance matrix for an 8-dimensional vector, you need diag(8)
.
mvrnorm(n = 1, rep(0, 8), diag(8))
# [1] -0.3554192 0.6051595 0.3926595 0.2752819 0.8610572 0.2679094 -1.3581420 -0.2814057
Upvotes: 3