[R] Simulating correlations with varying sample sizes

Holger Steinmetz Holger.steinmetz at web.de
Mon May 16 15:42:48 CEST 2011


Hi there,

I would like to draw 10 correlations from a bivariate population - but every
draw should be done with a different sample size. I thought I could to this
with a loop:

r=numeric(10) #Goal vector 
N = c(1000,100,80,250,125,375,90,211,160,540) #Sample size vector
for(i in 1:10) {
    data <- mvrnorm(n=N,mu=c(0,0),Sigma=matrix(c(1,.3,.3,1),2)) 
    r[i] <- cor(data[,1],data[,2])
    }

Goal: The 10 correlations shall be contained in the r-vector.
However, this does not work. I get an error that "arguments do not match"

Has anybody an idea?

Best,
Holger



--
View this message in context: http://r.789695.n4.nabble.com/Simulating-correlations-with-varying-sample-sizes-tp3526231p3526231.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list