# Simulate 1000 samples from a bivariate normal distribution

I know the code to generate two correlated variables (r=0.5), for example with 100 numbers each:

xy<-mvrnorm(100, mu=c(50,60), matrix(c(1,0.5,0.5,1),2))

But how can I simulate 1000 samples from a population with let's say rho=0.5. I guess it should work somehow with the replicate-function. After that I want to applicate the cor.test for the Spearman correlation coefficient.

Is it better two generate two variables (say 10.000 numbers each) and sample from this "population" or is it better two repeat the mvrnorm-function 1000 times? Is there a difference between these two methods?

No matter if you

• generate $n$ values $k$ times,
• generate $N$ values at once and then $k$ times sample without replacement $n$ values out of it,
• generate $N$ values at once and then deterministically take subsequent groups of size $n$,
• $k$ times repeat sampling single value $n$ times in a row etc.

the result will be the same since if the pseudo random generator works properly (and you have no reason to suspect it does not), than it sould return values that are independent and identically distributted. You could be interested in reading more about exchangeability.

It does not matter if you toss a coin $n$ times, or you give it to $n$ people and ask each of them to toss it once, you sould give similar results. (Assumming that people do not differ in how they toss.)

I think you might be looking for the sample method to draw samples from your population. Type ?sample for details.

You could first create your population and then draw from it 1000 times. Note the effect of the replicate parameter in the man page (related to the second part of your question). I think you would want it to be TRUE.