[R] a few scatter plots for a specific correlation value

Chuck Cleland ccleland at optonline.net
Thu Mar 5 13:02:46 CET 2009


On 3/5/2009 6:46 AM, June Kim wrote:
> Hello,
> 
> Is there a simple way to draw a few random sample scatter plots from a
> given specific correlation coefficient(say, 0.18)?

scatter <- function(n=100, r=.18){
require(MASS)
mymat <- mvrnorm(n, mu=c(0,0), Sigma=matrix(c(1,r,r,1), ncol=2),
empirical=TRUE)
plot(mymat[,1], mymat[,2])
}

par(mfrow=c(2,2))

replicate(4, scatter())

> ______________________________________________
> 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list