Finding conditional and joint probabilities from a table of data

AI Thread Summary
The discussion revolves around a Markov Chain simulation in R, where a function generates sequences based on specified probabilities. The simulation results show multiple sequences of states over five steps. Participants are analyzing specific probabilities and expectations related to the states of the Markov Chain.Key points include calculations for conditional probabilities, such as P(X1=1|X0=1) and P(X5=2|X2=1), using the simulation data. One participant suggests that the use of the 'mean' function is inappropriate for calculating probabilities, as it averages values rather than counting occurrences. They recommend using the 'length' function to accurately determine the number of occurrences that meet specific conditions. The discussion emphasizes the importance of correctly interpreting simulation results to derive meaningful probabilities, ensuring values remain within the valid range of 0 to 1.
user366312
Gold Member
Messages
88
Reaction score
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
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top