probs {hdMTD} | R Documentation |
Estimated transition probabilities
Description
Computes the Maximum Likelihood estimators (MLE) for an MTD Markov chain with
relevant lag set S
.
Usage
probs(X, S, matrixform = FALSE, A = NULL, warning = FALSE)
Arguments
X |
A vector or single-column data frame containing a sample of a Markov chain ( |
S |
A numeric vector of unique positive integers. Typically, |
matrixform |
Logical. If |
A |
A numeric vector of distinct integers representing the state space.
If not provided, this function will set |
warning |
Logical. If |
Details
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
).
Value
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 sequencesx_S
and columns correspond to states inA
.
Examples
X <- testChains[, 3]
probs(X, S = c(1, 30))
probs(X, S = c(1, 15, 30))