vlmc | R Documentation |
This function fits a Variable Length Markov Chain (VLMC) to a discrete time series.
vlmc(
x,
alpha = 0.05,
cutoff = NULL,
min_size = 2L,
max_depth = 100L,
prune = TRUE,
keep_match = FALSE,
backend = getOption("mixvlmc.backend", "R")
)
x |
a discrete time series; can be numeric, character, factor or logical. |
alpha |
number in (0,1] (default: 0.05) cut off value in quantile scale in the pruning phase. |
cutoff |
non negative number: cut off value in native (likelihood ratio)
scale in the pruning phase. Defaults to the value obtained from |
min_size |
integer >= 1 (default: 2). Minimum number of observations for a context in the growing phase of the context tree. |
max_depth |
integer >= 1 (default: 100). Longest context considered in growing phase of the context tree. |
prune |
logical: specify whether the context tree should be pruned (default behaviour). |
keep_match |
logical: specify whether to keep the context matches (default to FALSE) |
backend |
"R" or "C++" (default: as specified by the "mixvlmc.backend" option). Specifies the implementation used to represent the context tree and to built it. See details. |
The VLMC is built using Bühlmann and Wyner's algorithm which consists in
fitting a context tree (see ctx_tree()
) to a time series and then pruning
it in such as way that the conditional distribution of the next state of the
time series given the context is significantly different from the
distribution given a truncated version of the context.
The construction of the context tree is controlled by min_size
and
max_depth
, exactly as in ctx_tree()
. Significativity is measured using a
likelihood ratio test (threshold can be specified in terms of the ratio
itself with cutoff
) or in quantile scale with alpha
.
Pruning can be postponed by setting prune=FALSE
. Using a combination of
cutoff()
and prune()
, the complexity of the VLMC can then be adjusted.
Any VLMC model can be pruned after construction, prune=FALSE
is a
convenience parameter to avoid setting alpha=1
(which essentially prevents
any pruning). Automated model selection is provided by tune_vlmc()
.
a fitted vlmc model.
Two back ends are available to compute context trees:
the "R" back end represents the tree in pure R data structures (nested lists) that be easily processed further in pure R (C++ helper functions are used to speed up the construction).
the "C++" back end represents the tree with C++ classes. This back end is
considered experimental. The tree is built with an optimised suffix tree
algorithm which speeds up the construction by at least a factor 10 in
standard settings. As the tree is kept outside of R direct reach, context
trees built with the C++ back end must be restored after a
saveRDS()
/readRDS()
sequence. This is done automatically by recomputing
completely the context tree.
Bühlmann, P. and Wyner, A. J. (1999), "Variable length Markov chains. Ann. Statist." 27 (2) 480-513 \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/aos/1018031204")}
cutoff()
, prune()
and tune_vlmc()
pc <- powerconsumption[powerconsumption$week == 5, ]
dts <- cut(pc$active_power,
breaks = c(0, quantile(pc$active_power, probs = c(0.25, 0.5, 0.75, 1)))
)
model <- vlmc(dts)
draw(model)
depth(model)
## reduce the detph of the model
shallow_model <- vlmc(dts, max_depth = 3)
draw(shallow_model, prob = FALSE)
## improve probability estimates
robust_model <- vlmc(dts, min_size = 25)
draw(robust_model, prob = FALSE) ## show the frequencies
draw(robust_model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.