Learn R Programming

hdMTD (version 0.1.1)

probs: 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)

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 sequences \(x_S\) and columns correspond to states in A.

Arguments

X

A vector or single-column data frame containing a sample of a Markov chain (X[1] is the most recent).

S

A numeric vector of unique positive integers. Typically, S represents a set of relevant lags.

matrixform

Logical. If TRUE, the output is formatted as a stochastic transition matrix.

A

A numeric vector of distinct integers representing the state space. If not provided, this function will set A <- sort(unique(X)).

warning

Logical. If TRUE, the function warns the user when the state space is automatically set as A <- sort(unique(X)).

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).

Examples

Run this code
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