Finding conditional and joint probabilities from a table of data

In summary, the conversation discusses a function for a Markov Chain simulation and uses a 5-step simulation repeated 10 times as an example. The values of various probabilities are then discussed, including P(X1=1|X0=1), P(X2=1|X0=1), P(X5=2|X2=1), P(X1=1,X3=1), P(X5=2|X0=1,X2=1), and E(X2). The use of 'mean' in determining these probabilities is questioned and it is suggested to use the 'length' function instead.
  • #1
user366312
Gold Member
89
3
TL;DR Summary
Finding conditional and joint probabilities from a table of data generated by Markov Chain simulation.
Let,

Code:
    alpha <- c(1, 1) / 2
    mat <- matrix(c(1 / 2, 0, 1 / 2, 1), nrow = 2, ncol = 2)

    chainSim <- function(alpha, mat, n)
    {
      out <- numeric(n)
      out[1] <- sample(1:2, 1, prob = alpha)
      for(i in 2:n)
        out[i] <- sample(1:2, 1, prob = mat[out[i - 1], ])
      out
    }
Suppose the following is the result of a 5-step Markov Chain simulation repeated 10 times:

Code:
> sim
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    2    1    1    2    2    2    1    1    1     2
[2,]    2    1    2    2    2    2    2    1    1     2
[3,]    2    1    2    2    2    2    2    1    2     2
[4,]    2    2    2    2    2    2    2    1    2     2
[5,]    2    2    2    2    2    2    2    2    2     2
[6,]    2    2    2    2    2    2    2    2    2     2

What would be the values of the following?

  1. P(X1=1|X0=1)P(X1=1|X0=1)
  2. P(X2=1|X0=1)P(X2=1|X0=1)
  3. P(X5=2|X2=1)P(X5=2|X2=1)
  4. P(X1=1,X3=1)P(X1=1,X3=1)
  5. P(X5=2|X0=1,X2=1)P(X5=2|X0=1,X2=1)
  6. E(X2)E(X2)
I tried them as follows:

  1. mean(sim[2, sim[1, ] == 1] == 1)
  2. mean(sim[3, sim[1, ] == 1] == 1)
  3. mean(sim[6, sim[3, ] == 1] == 2)
  4. mean(sim[4, ] == 1 && sim[2, ]== 1)
  5. ?
  6. c(1,2) * mean(sim[2, ])
What would be the solution of (5)?

Am I correct withe the rest?
 
Last edited:
Technology news on Phys.org
  • #2
Are you getting meaningful probabilities between 0 and 1 from your code?
I guess that I wasn't clear in a similar thread of yours Post #8 of similar thread
I think that your use of 'mean' is wrong here. It will give you the average of a lot of values of 1 and 2, which will be over 1. That can not be a probability. You must count the number of entries, not their values. You can do that by using the 'length' function as I showed in Post #8 of the other thread.

PS. I just noticed that this thread is several days old, so my answer here might already be known and understood by the OP.
 

1. What is the difference between conditional and joint probabilities?

Conditional probabilities refer to the likelihood of an event occurring given that another event has already occurred. On the other hand, joint probabilities refer to the likelihood of two or more events occurring together.

2. How can I find conditional probabilities from a table of data?

To find conditional probabilities from a table of data, you will need to identify the relevant row and column for the events you are interested in. Then, divide the cell that represents the intersection of those events by the total number of outcomes in the row or column.

3. How do I calculate joint probabilities from a table of data?

To calculate joint probabilities from a table of data, you will need to identify the cell that represents the intersection of the events you are interested in. Then, divide that cell by the total number of outcomes in the entire table.

4. What does the sum of all conditional probabilities equal to?

The sum of all conditional probabilities equals 1. This is because the conditional probabilities for all possible outcomes must add up to 100%.

5. Can conditional and joint probabilities be calculated for more than two events?

Yes, conditional and joint probabilities can be calculated for any number of events. However, as the number of events increases, the calculations become more complex and may require the use of more advanced statistical methods.

Similar threads

  • Programming and Computer Science
Replies
7
Views
3K
  • Precalculus Mathematics Homework Help
Replies
3
Views
3K
  • Programming and Computer Science
Replies
32
Views
2K
  • Set Theory, Logic, Probability, Statistics
2
Replies
36
Views
3K
Replies
6
Views
2K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
889
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
  • General Math
Replies
4
Views
1K
  • Precalculus Mathematics Homework Help
Replies
24
Views
2K
Back
Top