Trying to build what I believe to be a contingency table, please consider the following :
dist = Parallelize[Table[RandomVariate[NormalDistribution[]], {100000}]];
dist2 = Rest@FoldList[0.95 # + #2 &, 0, dist];
dist3 = Rest@FoldList[0.95 # + Abs[#2] &, 0, dist];
dist4 = {dist2, dist3}\[Transpose]
q1 = Flatten[{Quantile[dist2, {1/3, 2/3}], Quantile[dist3, {1/3, 2/3}]}]
{-1.39001, 1.33851, 15.0327, 16.6757}
What I need to do : For each element of dist4 I need to see with of the 9 box below it belongs to :
for example : {1.55191, 15.7189} belongs to 2
1.55 belongs to 1 and
15.71 belongs to 8
So the intersection is 2.
I have tried If, or Switch but it is to long to write. Is there an automatic way to do this ?
If I understand the question, I think this does it:
{a, b, c, d} = q1;
tbl = Range@9 ~Partition~ 3;
f[{x_, y_}] := tbl[[
Which[x > b, 1, x > a, 2, x <= a, 3],
Which[y < c, 1, y < d, 2, y >= d, 3]
]]
f /@ dist4 // Short