我想生成从多元高斯分布中提取的数据点集群。
我希望所有聚类具有相同的协方差矩阵。我正在使用clusterGeneration包中的genRandomClust命令。
但遗憾的是,上述命令会生成具有不同协方差矩阵的聚类。有人能指出一个可以达到这个目标的命令或方案吗?
答案 0 :(得分:0)
这个怎么样?这里我们从双变量正态随机分布中抽取样本。
library(MASS)
Sigma <- matrix(c(10,3,3,2),2,2) # start with a fixed 2x2 covariance matrix, or generate it randomly
Sigma
datapoints <- mvrnorm(n = 1000, rep(0, 2), Sigma) # draw 1000 MVN samples with cov matrix Sigma, with mean c(0, 0) or use some random mean vector
var(datapoints) # notice that the covariance matrix for the datapoint generated is slightly different from Sigma
datapoints <- mvrnorm(n = 1000, rep(0, 2), Sigma, empirical = TRUE)
var(datapoints) # here the covariance matrix for the datapoint generated is exactly equal to Sigma