install.packages("mixvlmc")Third release of mixvlmc
I am happy to announce the third release of mixvlmc, version 0.3.1. This R package provides a collection of tools to estimate and study Variable Length Markov Chains (VLMC) with or without external covariates. It can be installed from the CRAN as usual
and then loaded with
library(mixvlmc)I have already presented the most visible change of this version, the new draw() functions and their LaTeX export, in a previous post, written for version 0.3.0. That version did not make it to the CRAN (its checks were slightly too long on Windows), and version 0.3.1 is identical apart from the slowest tests being skipped on the CRAN. This post covers the other changes. As usual, the NEWS lists all of them. Several changes break compatibility with previous versions, so please read at least the breaking changes section of the NEWS before updating your code.
Discrete time series
mixvlmc 0.3.1 introduces a class for discrete time series, built by the dts() function. A dts stores a time series together with its state space, the set of values the series can take. For instance, we can turn the classical yearly sunspot numbers into a binary time series as follows:
sun <- dts(ifelse(sunspot.year >= median(sunspot.year), "high", "low"))
sunDiscrete time series of length 289 with state space high, low
low low low low low ...
The state space can also be specified explicitly, which sets the order of the states used by all the functions of the package (for instance in the results of contexts() or predict()), and allows states that do not appear in the series:
dts(c("b", "a", "b"), vals = c("c", "b", "a"))Discrete time series of length 3 with state space c, b, a
b a b
All the functions of the package that use time series accept dts objects as well as simple vectors, from estimation functions such as vlmc() to functions that use new data such as loglikelihood():
sun_vlmc <- vlmc(sun)
sun_vlmcVLMC context tree on high, low [C++]
cutoff: 1.921 (quantile: 0.05)
Number of contexts: 19
Maximum context length: 14
The main motivation for this new class is to prepare the support of multiple time series, planned for a future version. The new vignette Discrete time series and contexts of models describes the class and also shows how to explore in detail the contexts of a fitted model.
The C++ backend by default
Version 0.2.0 introduced a C++ implementation of context trees, based on suffix trees, as an experimental feature. It is now the default backend of ctx_tree(), vlmc() and tune_vlmc() (note the [C++] in the output above) and is not considered experimental any more. It gives the same models as the R implementation, which remains available with backend = "R" (or with the mixvlmc.backend option), but it is faster and uses less memory. VLMC with covariates still use the R implementation.
VLMC with covariates
This version fixes several bugs in VLMC with covariates, some of which change the models obtained by covlmc():
- the likelihood ratio tests used to prune the context tree take into account the number of levels of factor covariates (a factor with \(L\) levels has \(L-1\) parameters per time step, not 1). This changes the models obtained with factors with at least 3 levels;
- the number of parameters of a model, used by the AIC and the BIC (and thus by
tune_covlmc()), does not depend any more on the computing engine used to fit the logistic models; - unused levels of factor covariates are ignored.
The new article Computing engines and control of VLMC with covariates describes the computing engines (based on stats::glm(), VGAM and nnet), their differences and the parameters that control the estimation. In addition, covlmc() and tune_covlmc() are faster and their models use much less memory, in particular once saved to a file.
Stricter checks
Previous versions were sometimes too forgiving. Methods that do not use their ... argument now report an error when they are given additional arguments, which catches misspelled arguments that were silently ignored:
simulate(sun_vlmc, 100, burn_in = 10)Error in `simulate()`:
! `...` must be empty.
✖ Problematic argument:
• burn_in = 10
(the correct argument is burnin). The inputs of the estimation functions are also validated more thoroughly: missing values, empty time series and time series with a single state are rejected with an informative error instead of crashing R or producing degenerate models.
Documentation and tests
The vignettes have been proofread and reorganised in the documentation site, with a Getting started section and sections dedicated to the use of models and to advanced topics. In addition to the two documents mentioned above, a new article covers in detail the draw() functions.
Finally, a large part of the work on this version went into bug hunting. The test suite has grown significantly, in particular to check systematically that the R and C++ implementations agree, and the NEWS lists almost forty bug fixes, from crashes of the C++ backend to wrong positions of contexts.