[R] Simulating correlations with varying sample sizes

From: Holger Steinmetz <Holger.steinmetz_at_web.de>
Date: Mon, 16 May 2011 06:42:48 -0700 (PDT)


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.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 16 May 2011 - 13:45:28 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 16 May 2011 - 17:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive