[R] Problems creating a random sample

Chong Gu chong at stat.purdue.edu
Wed Jan 12 15:44:38 CET 2000


   Date: Wed, 12 Jan 2000 13:05:21 +0100 (CET)
   From: Adriane Leal <loparic at student.fsa.ucl.ac.be>
   X-Sender: loparic at 18-76.campusnet.ucl.ac.be
   MIME-Version: 1.0
   Content-Type: TEXT/PLAIN; charset=US-ASCII
   Sender: owner-r-help at stat.math.ethz.ch
   Precedence: bulk

   Hi!

   I'm supposed to create a random sample bivariate normal variates of size
   equal to 250 with  mean vector (-1,1) and cov matrix (1,0.95,0.95,1)

   In S language I would write:

   > mean<-c(-1,1)
   > cov<-c(1,0.95,0.95,1)
   > covmat<-matrix(cov,nrow=2,ncol=2)
   > mvnorm<-rmvnorm(250,mean,covmat)
   ... and it should work

   I've tried this in R, but it does not recognize "rmvnorm".

   (Error: couldn't find function "rmvnorm")

   Does anybody knows what function should I use in this case?

   My best regards,

   Adriane


Here is one way to do it:

covsqrt<-chol(matrix(c(1,.95,.95,1),2,2))
mvnorm<-matrix(rnorm(500),250,2)%*%covsqrt+c(-1,1)

Chong
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list