View source: R/higherOrderPredict.R
| higherOrderPredict | R Documentation |
higherOrderPredict returns the distribution of the next
state given the most recent states, and higherOrderSimulate draws a
sequence of states, under a higher order model fitted by
fitHigherOrder or fitMTD.
higherOrderPredict(fit, history)
higherOrderSimulate(n, fit, t0, include.t0 = FALSE)
fit |
The list returned by |
history |
The most recent states, oldest first: a vector of at least
|
n |
Number of states to simulate. |
t0 |
The states preceding the simulated ones, oldest first; at least
|
include.t0 |
Should |
Both functions use the transition probabilities of the fitted model
of order k,
P(x_t = j \mid x_{t-1}, \dots, x_{t-k}) = \sum_{i=1}^{k} \lambda_i\, Q_i[j, x_{t-i}],
the same that enter higherOrderLogLik. For a fit returned
by fitMTD all the Q_i are the single MTD transition
matrix. Only the last k states of a history are used, the last
element being the most recent.
A model of order k needs k previous states, so t0
(and every history) must contain at least order states. The
probabilities are normalized to sum to one, which only matters when the
weights of a least squares fit sum to one up to the optimizer's tolerance.
higherOrderPredict: a named vector of next-state
probabilities for a single history, or a matrix with one row per history.
higherOrderSimulate: a character vector of n states,
preceded by t0 if include.t0 = TRUE.
fitHigherOrder, fitMTD,
higherOrderLogLik, rmarkovchain
wind <- read.csv(system.file("extdata", "koeberg_wind.csv",
package = "markovchain"))$state
fit <- fitMTD(wind, order = 2)
# next wind direction after directions 1 and then 2
higherOrderPredict(fit, c(1, 2))
# several histories at once
higherOrderPredict(fit, rbind(c(1, 1), c(2, 2), c(4, 1)))
# simulate one day of hourly directions starting from the last two observed
set.seed(1)
higherOrderSimulate(24, fit, t0 = tail(wind, 2))
# the same works for fitHigherOrder()
data(rain)
fit2 <- fitHigherOrder(rain$rain, order = 2, method = "mle")
higherOrderPredict(fit2, c("0", "6+"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.