Learn R Programming

hdMTD (version 0.1.4)

probs: Predictive probabilities for MTD / MTDest

Description

Compute one-step-ahead predictive probabilities under an MTD model or an MTDest fit. For objects of class "MTDest", the method is inherited from the "MTD" class via S3 inheritance.

Conventions:

  • Samples are read most recent first: x[1] = X_{t-1}, x[2] = X_{t-2}, etc.

  • The global transition matrix P (or transitP) is indexed by row labels that list the past context from oldest to newest. A cell at row "s_k...s_1" and column "a" is read as p(a | s_1...s_k).

  • If both newdata and context are missing, probs() returns the full global transition matrix (transitP(object)).

Usage

probs(object, context = NULL, newdata = NULL, oldLeft = FALSE)

Value

A numeric matrix of predictive probabilities with one row per input context and columns indexed by states(object). Row names are the context labels (oldest to newest) formed by concatenating state symbols without a separator. If both newdata and context are missing, the full global transition matrix is returned, which can be large for big state spaces or many lags.

Arguments

object

An MTD or MTDest object.

context

Optional vector or matrix/data.frame of contexts (rows). By default, each row follows the "most recent first" convention; set oldLeft = TRUE if rows are supplied oldest to newest. Must have exactly length(Lambda(object)) columns (one symbol per lag).

newdata

Optional vector or matrix/data.frame of samples (rows). Columns follow the "most recent first" convention. Must have at least max(Lambda(object)) columns. Only one of newdata or context can be provided at a time. When there are extra columns, only the columns at the model lags are used.

oldLeft

Logical. If TRUE, interpret rows in newdata/context as oldest to newest (e.g. leftmost = newdata[ ,1] = oldest). If FALSE (default), rows are most recent first.

Details

All entries of newdata/context must belong to the model's state space states(object).

See Also

transitP, states, Lambda, empirical_probs, MTDmodel, MTDest

Examples

Run this code
set.seed(1)
m <- MTDmodel(Lambda = c(1,3), A = c(0,1), lam0 = 0.1)

# Full matrix
P <- probs(m)

# Using a sample row (most recent first): newdata has >= max(Lambda) columns
new_ctx <- c(1, 0, 1, 0)      # X_{t-1}=1, X_{t-2}=0, X_{t-3}=1, ...
probs(m, newdata = new_ctx)   # one row of probabilities

# Explicit contexts (exactly |Lambda| symbols per row)
probs(m, context = c(0, 1), oldLeft = FALSE)  # most recent first
probs(m, context = c(0, 1), oldLeft = TRUE)   # oldest to newest

# Multiple contexts (rows)
ctxs <- rbind(c(1,0,1), c(0,1,1), c(1,1,0))
probs(m, newdata = ctxs)

Run the code above in your browser using DataLab