View source: R/occupation_time_pmf.R
occupation_time_pmf | R Documentation |
Computes the pmf for the occupation time (sum of '1's), S, in a two-state Markov chain conditioning on X_0 = 0 or X_0 = 1. This is the expression given Equation (1) of Bhattacharya & Gupta (1980), with a minor typo correction.
occupation_time_pmf(x, n, alpha, beta, X0 = c("0", "1"), log = FALSE)
x |
the number of '1's in n iterations; non-negative integer smaller than or equal to n. |
n |
the number of iterations in Markov chain. |
alpha |
a transition probability (between 0 and 1). |
beta |
a transition probability (between 0 and 1). |
X0 |
initial state, either |
log |
logical if TRUE, probabilities p are given as log(p). |
(log) p, where p = Pr(S = x).
Bhattacharya, S. K., & Gupta, A. K. (1980). Occupation times for two-state Markov chains. Discrete Applied Mathematics, 2(3), 249-250.
recurrence_time_pmf
, max_transitions_pmf
M <- 100 # number of Markov chain iterations
probs.X0 <- occupation_time_pmf(x = 0:M, n = M, alpha = .02, beta = .2, X0 = "0")
probs.X1 <- occupation_time_pmf(x = 0:M, n = M, alpha = .02, beta = .2, X0 = "1")
sum(probs.X0) # should both be 1
sum(probs.X1)
plot(0:M, probs.X0, type = "h", lwd = 3, xlab = "Occupation time")
points(0:M, probs.X1, type = "h", lwd = 3, col = 2)
legend(x = "topright", col = 1:2,
legend = c(expression(X[0]==0), expression(X[0]==1)), bty = 'n', pch = 15)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.