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.