Calculating the probability of one bin preceding the other

Hi,
I'm having a difficult time with this problem.
A matrix, M (2500x2), was binned into B:
bins = 1:1:8
B =
2 4
1 1
1 1
1 3
1 1
8 8
7 8
I'd like to know the probability of [1,1] proceeding [8,8].
The only thought I have is the obvious: counting each instance of [1,1] where [8,8] comes right before it, and then divide by 2500. However simple that is, I'm unable to implement it.
Any help would be greatly appreciated. Thank you, Scott

댓글 수: 2

For the 7-row example you show, what is the correct value of the probability p? Should it be p = 1/7, because there is one instance of [1 1] of preceding [8 8]? Should it be p = 1, because the only instance of [8 8] is preceded by [1 1]? Or should it be p = 1/3, because out of the 3 instances of [1 1], there is one case where [8 8] comes next? Or something else?
It would be p = 1/3. The total of number of probabilities of each transition would equal 1. (E.g., [1 1] --> [1 1], [1 1] --> [1 2], [1 1] --> [1 3],....)
(I think so. You're making me question my thinking, which is good... But, it's also nearly 5AM, so that may be easy to do.)
In the case of my actual data, we know the immediately prior state can effect the current state. So it's certainly conditional.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 21일
Counting can be done using ismember
tf11 = ismember(A,[1 1],'rows') ; % true for rows that are [1 1]
N11 = sum(tf11) % count
q = [false ; tf11(1:end-1)] ; % true for rows following a row with [1 1]
tf = ismember(A(q,:),[8 8],'rows') ; % true when these rows are [8 8]
N11followedby88 = sum(tf) % count

댓글 수: 1

Thank you, Jos. :) That would have taken me days to find ismember.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2014년 3월 21일

댓글:

2014년 3월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by