[R] generating a random signal with a known correlation

stephen sefick ssefick at gmail.com
Tue Aug 12 13:31:02 CEST 2008


sowas package by douglas mauran.  Type sowas into google.

On Tue, Aug 12, 2008 at 12:14 AM, Yasir Kaheil <kaheil at gmail.com> wrote:
>
> 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.
>
> ______________________________________________
> 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.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

	-K. Mullis



More information about the R-help mailing list