Hello, Is there a simple way to draw a few random sample scatter plots from a given specific correlation coefficient(say, 0.18)?
Chuck Cleland
2009-Mar-05 12:02 UTC
[R] a few scatter plots for a specific correlation value
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
See the run.cor.examp function in the TeachingDemos package (in addition to the mvrnorm function in MASS). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of June Kim > Sent: Thursday, March 05, 2009 4:47 AM > To: r-help at r-project.org > Subject: [R] a few scatter plots for a specific correlation value > > Hello, > > Is there a simple way to draw a few random sample scatter plots from a > given specific correlation coefficient(say, 0.18)? > > ______________________________________________ > 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.