Article View: alive.statistics
Article #60Re: [urgent]: random sample with predefined correlation
From: Ray Koopman
Date: Mon, 03 Oct 2005 07:41
Date: Mon, 03 Oct 2005 07:41
23 lines
1883 bytes
1883 bytes
Pedro Cardoso wrote:
> Hello all, I have this problem:
>
> I have a vector x of values and I would like "randomly" produce other
> vector y,
> such that correlation(x,y) is equal to some predefined value.
>
> example:
> x=(1, 2, 1, 2, 3, 4, 5, 1, 8)
> y=(?, ?; ?, ?, ?, ?, ?, ?, ?)
> correlation(x,y)=0.7
>
>
> Can anyone help?
>
> best regards,
> Pedro.
I assume you would like Mathematica code again. This should do it:
y = {0,r,Sqrt[1-r^2]}.First@QRDecomposition[{1.,#,Random[]}&/@x]
where r is the desired correlation[x,y]. Tr@y == 0. && y.y == 1.
Technical Details
Message-ID:
<1128325289.798962.226930@g44g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mailReferences:
<434058d2$0$17828$a729d347@news.telepac.pt>Show Full Headers
Complete Article Headers
X-Google-Thread: 10468c,d6603d800ee0afd9 X-Google-Thread: fbb77,d6603d800ee0afd9 X-Google-Thread: 107665,d6603d800ee0afd9 X-Google-Attributes: gid10468c,gidfbb77,gid107665,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mail From: "Ray Koopman" <koopman@sfu.ca> Newsgroups: alive.statistics,alt.sci.math.statistics.prediction,pt.ciencia.geral Subject: Re: [urgent]: random sample with predefined correlation Date: 3 Oct 2005 00:41:29 -0700 Organization: http://groups.google.com Lines: 24 Message-ID: <1128325289.798962.226930@g44g2000cwa.googlegroups.com> References: <434058d2$0$17828$a729d347@news.telepac.pt> NNTP-Posting-Host: 70.69.0.143 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1128325299 2429 127.0.0.1 (3 Oct 2005 07:41:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Oct 2005 07:41:39 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 5.17; Mac_PowerPC),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=70.69.0.143; posting-account=nnH_0gwAAAARIDd_i5XyTPj4LuckzgGi