Computes the Maximum Likelihood estimators (MLE) for an MTD Markov chain with
relevant lag set S
.
probs(X, S, matrixform = FALSE, A = NULL, warning = FALSE)
A data frame or a matrix containing estimated transition probabilities:
If matrixform = FALSE
, the function returns a data frame with three columns:
The past sequence \(x_S\) (a concatenation of past states).
The current state \(a\).
The estimated probability \(\hat{p}(a | x_S)\).
If matrixform = TRUE
, the function returns a stochastic transition matrix,
where rows correspond to past sequences \(x_S\) and columns correspond to states in A
.
A vector or single-column data frame containing a sample of a Markov chain (X[1]
is the most recent).
A numeric vector of unique positive integers. Typically, S
represents
a set of relevant lags.
Logical. If TRUE
, the output is formatted as a stochastic
transition matrix.
A numeric vector of distinct integers representing the state space.
If not provided, this function will set A <- sort(unique(X))
.
Logical. If TRUE
, the function warns the user when the state
space is automatically set as A <- sort(unique(X))
.
The probabilities are estimated as:
$$\hat{p}(a | x_S) = \frac{N(x_S a)}{N(x_S)}$$
where \(N(x_S a)\) is the number of times the sequence \(x_S\) appeared in the sample
followed by \(a\), and \(N(x_S)\) is the number of times \(x_S\) appeared
(followed by any state). If \(N(x_S) = 0\), the probability is set to \(1 / |A|\)
(assuming a uniform distribution over A
).
X <- testChains[, 3]
probs(X, S = c(1, 30))
probs(X, S = c(1, 15, 30))
Run the code above in your browser using DataLab