看看mvrnormMASS包中的功能
library(MASS)
Sigma <- matrix(c(10,3,3,2),2,2) # Covariance Matrix
set.seed(1) # For the example to be reproducible
Random_XY <- mvrnorm(n=100, c(0, 0), Sigma) # Random (x,y) from a Gaussian distr.
head(Random_XY)
[,1] [,2]
[1,] 2.3299984 -0.4196921
[2,] -0.2261965 -1.2474779
[3,] 2.3538800 1.7025069
[4,] -4.9527947 -1.8730622
[5,] -1.0148272 -0.4114252
[6,] 2.0557678 2.4378417
Run Code Online (Sandbox Code Playgroud)
编辑
由于高斯过程具有均值0和方差1以及零相关,因此正确的答案应该是:
mvrnorm(n=100, c(0, 0), diag(c(1,1)))
Run Code Online (Sandbox Code Playgroud)
其中平均值的向量是c(0,0)一个单一的协方差矩阵diag(c(1,1))
正如@Ben Bolker所指出的,最快的方法(使用R Base功能)是:
data.frame(x=rnorm(100),y=rnorm(100))
Run Code Online (Sandbox Code Playgroud)