Yasir Kaheil
2008-Aug-11 19:57 UTC
[R] generating a random signal with a known correlation
Hi, How can I generate a random signal that's correlated with a given signal at a given correlation (say 0.7)? I've been looking at rmvnorm etc but don't seem to figure it out. Thanks ----- Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/generating-a-random-signal-with-a-known-correlation-tp18932541p18932541.html Sent from the R help mailing list archive at Nabble.com.
Yasir Kaheil
2008-Aug-12 04:14 UTC
[R] generating a random signal with a known correlation
OK, here is the code for those who are interested: x<-rnorm(1000, mean=20, sd=100); x.s<-scale(x) xp<-pnorm(x.s); xix<- sort(xp,index.return=TRUE)$ix norm.cop <- normalCopula(0.6) #correlation of 0.6, other libraries can be used instead of copula y <- rcopula(norm.cop, length(x)) yp<-pnorm(y) ypix<- sort(yp[,1],index.return=TRUE)$ix yp<-yp[ypix,]; yps<-yp[,1];# dummy initialization yps[xix]<-yp[,2]; #adjust mean and sd here. yqs<-qnorm(yps,mean=mean(x),sd=sd(x)); cor(x,yqs) Yasir Kaheil wrote:> > Hi, > How can I generate a random signal that's correlated with a given signal > at a given correlation (say 0.7)? > I've been looking at rmvnorm etc but don't seem to figure it out. Thanks > >----- Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/generating-a-random-signal-with-a-known-correlation-tp18932541p18937754.html Sent from the R help mailing list archive at Nabble.com.
Pedro.Rodriguez at sungard.com
2008-Aug-21 12:46 UTC
[R] generating a random signal with a known correlation
Hi Yasir, Try the following reference: A heuristic approach for the generation of multivariate random samples with specific marginal distributions and correlation matrix, Dimos C. Charmpis and Panayiota L. Panteli, Computational Statistics 19, 283-300, 2004. I have the R code, please let me know if you need it, I will more than happy to post it online. Nonetheless, soon I will create an add-on package. Rmvnorm assume a multivariate normal distribution, the method from above is flexible enough to mix marginals. Kind Regards, Pedro -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Yasir Kaheil Sent: Monday, August 11, 2008 3:58 PM To: r-help at r-project.org Subject: [R] generating a random signal with a known correlation Hi, How can I generate a random signal that's correlated with a given signal at a given correlation (say 0.7)? I've been looking at rmvnorm etc but don't seem to figure it out. Thanks ----- Yasir H. Kaheil Columbia University -- View this message in context: http://www.nabble.com/generating-a-random-signal-with-a-known-correlatio n-tp18932541p18932541.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.