English 中文(简体)
应急数学表a
原标题:Contingency Table in Mathematica

为了建设我认为是一个应急表,请考虑如下:

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}

“entergraph

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.  

我曾尝试过,如果是,还是转手,但要写得很长。 是否有这样做的自动途径?

最佳回答

如果我理解这个问题,我认为:

{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
问题回答
y[t_] := Piecewise[{{7, t <  q1[[1]]}, {4, t <= q1[[2]]}}, 1];
x[t_] := Piecewise[{{0, t <  q1[[3]]}, {1, t <= q1[[4]]}}, 2];
{{##}, x[#1] + y[#2]} & @@@ dist4

或或许使用<条码>BinLists!

k = BinLists[dist4,
   {Join[{Min[dist4[[All, 1]]]}, q1[[1 ;; 2]], {Max[dist4[[All, 1]]]}]},
   {Join[{Min[dist4[[All, 2]]]}, q1[[3 ;; 4]], {Max[dist4[[All, 2]]]}]}
   ];

Flatten[Replace[
        Flatten[MapIndexed[{#1, #2} &, k, {2}], 1], {{x__}, t_} :>
           (Join[{#}, {9 - 3 First@t + Last@t}] & /@ {x}), {1}], 1]

Have you considered using a step function? Depending on whether you want the output to be {3,2} in the case of slot 8, or actually the number 8, the implementation might differ.

g1[x_] := 
 Piecewise[{{1, x > 1.33851}, {2, 1.33851 >= x > -1.39001}, 3}]

g2[x_] := Piecewise[{{1, x < 15.0327}, {2, 15.0327 <= x < 16.6757}}, 3]

slotfn[{a_, b_}] := {g2[b], g1[a]}

slotnumber[{a_, b_}] := 3 g2[b] + g1[a]

如果实际执行情况相同,请删除。 我遗憾地指出,我的不功能的“终端”版本确保你只将两个论点转至<代码>slotf或slot

(a) 单独限制:

limits =
  {
   {.1, .15, .5, [Infinity]},
   {1, 2, 3, [Infinity]}
   };

cell[l_List] :=
 Table[
  Position[
    limits[[i]], _?(# > l[[i]] &), 1, 1
    ][[1, 1]], {i, 1, Length@l}]

。 您可以:

(cell[{.4, 1.5}] - {0, 1})*{1, Length[limits[[1]]]} // Plus @@ # &

页: 1





相关问题
SELECT command to calculate percentage

I m trying to get the percentage of each video I have in my database based on its view count against all other videos. I m then trying to display all the videos from highest view count to lowest, ...

Consolidating a COUNT query

I have a page where I am running an initial SQL query to get a list of subjects, then I loop over this query and run two additional queries for each record returned from the original subjects query (I ...

R: Count number of objects in list [closed]

Can someone recommend a function that can allow me to count and return the number of items in a list? library(stringr) l <- strsplit(words, "a") if(# number of items in list l < 1) ...

Mysql get count of rows for each day

My Current query is: SELECT DISTINCT DATE(vote_timestamp) AS Date, COUNT(*) AS TotalVotes FROM `votes` WHERE vote_target_id= 83031 GROUP BY DATE(vote_timestamp) ORDER BY DATE(vote_timestamp) DESC ...

Group by named column

I always forget how to do things like this. I have a database table with birthdates and I want to find out how many people have the same age. I m trying: SELECT TIMESTAMPDIFF( YEAR, birthdate, ...

TableView oval button for Index/counts

Can someone help me create an index/count button for a UITableView, like this one? iTunes http://img.skitch.com/20091107-nwyci84114dxg76wshqwgtauwn.preview.jpg Is there an Apple example, or other ...

热门标签