Markov Chain process - Missing values I have a vector of sequences with presence (1) and absence (0), from were I have calculated the first order Markov Process. 
This is how the data looks like:
dataset=c(NA,NA,0,0,0,0,1,0,1,1,0,1,1,NA,NA,NA,NA,NA,0,
          1,1,1,1,1,1,0,NA,1,1,1,1,1,1,0,0,NA,NA,0,1,1,
          NA,NA,0,NA,0,0,0,1,1,1,0,1,1,1,1,0,1,NA,0,1)

For thsi vector I have calculated:


*

*Probability of Presence (P1) and Absence (P0)

*Probability of having Presence followed by Presence (P11), Presence followed by Absence (P10), Absence followed by Presence (P01) and Absence followed by Absence (P00)


The transition probabilities were obtained by using a loop the checks for sequence of 2 values: to calculate P_00 I am using 
   P_00 : dataset[j]==0 & dataset[j+1]==0 , etc.

These are the results:
P_0=0.3913043
P_1=0.6086957
P_0+P_1=1

P_00=0.1538462
P_01=0.2307692
P_11=0.4615385
P_10=0.1538462
P_00+P_01+P_11+P_10=1

The idea is to populate the NA with presence/absence sequences according to the Probability values obtained for the sequence. The problem is that for now I am not being able to find the best and more adequate process for this problem and I am a newbie with this type of problems. Even if there is already a package that can do this for me, I would prefer to understand how can I do it.
 A: This is best and most transparently done in bayesian modelling. Bayesian inference works using MCMC (Markov Chain Monte Carlo) simulations, and that's exactly what you need. Example model code in bugs (not tested!):
dataset[1] ~ dbern(P1) # you must somehow solve the first element
for (i in 2:n) { # markov chain - define how each value depends on the previous one
    dataset[i] ~ dbern(p.presence[dataset[i - 1]])
}

dbern(p) stands for Bernoulli distribution with probability p. The array p.presence can be defined as (using P* variables as you defined them):
p.presence[0] = P01 / P0   # probability of presence, given absence in previous step
p.presence[1] = P11 / P1   # probability of presence, given presence in previous step

This way you can pass p.presence as input data (as in your example), but you could also let bugs to estimate it from the data!! (this is much more common and reasonable). You can of course get posterior distributions and MCMC simulation samples for the missing values (NA) in the dataset, and compute various other statistics on it.
