MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: correlated random vector

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63990] Re: correlated random vector
  • From: "Ray Koopman" <koopman at sfu.ca>
  • Date: Thu, 26 Jan 2006 03:43:33 -0500 (EST)
  • References: <dqsp65$cbj$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Jan Schmedes wrote:
> Dear group,
>
> given a vector of observed data x i would like to create a vector with
> uniform distributed random numbers y that is correlated with the observed
> vector, that is, corr(x,y)=r for a given r, say 0.6. Is that possible and
> how could i do that in Mathematica?
>
> Regards
>
> Jan

Here's a general version of my previous solution. This uses Valeri
Astanoff's method of handling a variable number of parameters,
which is much better than what I had in mind.

In[1]:= <<Statistics`

In[2]:= unicor2[x_List, r_ /; Abs@r < 1] := Block[
{n = Length@x, u = 1.-r^2, v,w,z}, v = Array[w,n-2];
z = Rest @ First @ QRDecomposition @ Transpose @ Join[
    {Table[1.,{n}], x}, Table[Random[],{n-2},{n}]];
If[Negative[x.z[[1]]], z[[1]] *= -1]; Prepend[Last /@ Last @
NMinimize[{#.#&@ListConvolve[{1,-2,1},Sort[Prepend[v,r].z]],
           v.v == u}, v], r].z]

In[3]:= x = Table[Random[],{20}]
Out[3]=
{0.388446, 0.587678, 0.275674, 0.631232, 0.352318,
 0.356175, 0.30096, 0.42984, 0.516199, 0.446825,
 0.0433444, 0.288117, 0.22664, 0.41129, 0.130119,
 0.114932, 0.0718704, 0.461425, 0.199434, 0.679792}

In[4]:= y2 = unicor2[x, .6]
Out[4]=
{0.240175, 0.0773088, 0.194736, 0.261759, 0.0907826,
 0.314476, 0.152402, 0.0783928, 0.00382136, 0.138326,
 -0.414515, -0.25001, -0.442791, -0.0569127, -0.192389,
 -0.16771, 0.0428463, 0.177506, -0.360031, 0.111829}

In[5]:= Correlation[x,y2]
Out[5]= 0.6


  • Prev by Date: Re: Factorising polynomials
  • Next by Date: Re: Factorising polynomials
  • Previous by thread: Re: correlated random vector
  • Next by thread: Simplifying the root of a quadratic