Bookaa
Bookaa

Reputation: 13

How to generate normal distributed multidimensional points

I need to generate a random multidimensional clustered data. For this I want to generate few uniform distributed multidimensional points (centers) and then many normal distributed points around each of them. How can I set the vector (multidimensional point) as mean for the normal distribution? I see the function rnorm can get vectors as mean and sd parameters, but I really don't understand how it works.

Upvotes: 1

Views: 2146

Answers (2)

David Bazalar
David Bazalar

Reputation: 36

Function rmvnorm.mixt() in package ks is another good alternative. If you install this package and open the vignette file (ks: Kernel density estimation for bivariate data) you can access an example for building a 'dumbbell' density with this function (see page 1). But you can also use the rmnorm() function (proposed here already) to build this same density. This can be done as following:

xy <- rbind(4/11*rmnorm(200,c(-2,2), diag(2)),  
  4/11*rmnorm(200,c(2,-2), diag(2)),  
  3/11*rmnorm(200, c(0,0),matrix(c(0.8,-0.72,-0.72,0.8),2,2))
)
plot(xy)

Upvotes: 0

Rcoster
Rcoster

Reputation: 3210

Package mnormt, function rmnorm()

set.seed(2)
require(mnormt)
varcov <- matrix(rchisq(4, 2), 2)
varcov <- varcov + t(varcov)

rmnorm(1000, mean=c(0,1), varcov=varcov)

Upvotes: 1

Related Questions