contexts.covlmc {mixvlmc} | R Documentation |
Contexts of a VLMC with covariates
Description
This function returns the different contexts present in a VLMC with covariates, possibly with some associated data.
Usage
## S3 method for class 'covlmc'
contexts(
ct,
sequence = FALSE,
reverse = FALSE,
frequency = NULL,
positions = FALSE,
local = FALSE,
metrics = FALSE,
model = NULL,
hsize = FALSE,
merging = FALSE,
...
)
Arguments
ct |
a fitted covlmc model. |
sequence |
if |
reverse |
logical (defaults to |
frequency |
specifies the counts to be included in the result
data.frame. The default value of |
positions |
logical (defaults to FALSE). Specify whether the positions
of each context in the time series used to build the context tree should be
reported in a |
local |
specifies how the counts reported by |
metrics |
if TRUE, adds predictive metrics for each context (see
|
model |
specifies whether to include the model associated to a each
context. The default result with |
hsize |
if TRUE, adds a |
merging |
if TRUE, adds a |
... |
additional arguments for the contexts function. |
Details
The default behaviour of the function is to return a list of all the
contexts using ctx_node_covlmc
objects (as returned by
find_sequence.covlmc()
). The properties of the contexts can then be
explored using adapted functions such as counts()
, covariate_memory()
,
cutoff.ctx_node()
, metrics.ctx_node()
, model()
, merged_with()
and
positions()
.
When sequence=TRUE
the method returns a data.frame whose first column,
named context
, contains the contexts as vectors (i.e. the value returned
by as_sequence()
applied to a ctx_node
object). Other columns contain
context specific values specified by the additional parameters. Setting any
of those parameters to a value that ask for reporting information will
toggle the result type of the function to data.frame
.
See contexts.ctx_tree()
for details about the frequency
parameter. When
model
is non NULL
, the resulting data.frame
contains the models
associated to each context (either the full R model or its coefficients).
Other columns are added is the corresponding parameters are set to TRUE
.
Value
A list of class contexts
containing the contexts represented in
this tree (as ctx_node_covlmc
) or a data.frame.
Positions
A position of a context ctx
in the time series x
is
an index value t
such that the context ends with x[t]
. Thus x[t+1]
is
after the context. For instance if x=c(0, 0, 1, 1)
and ctx=c(0, 1)
(in
standard state order), then the position of ctx
in x
is 3.
State order in a context
Notice that contexts are given by default
in the temporal order and not in the "reverse" order used by many VLMC
research papers: older values are on the left. For instance, the context
c(1, 0)
is reported if the sequence 0, then 1 appeared in the time series
used to build the context tree. Set reverse to TRUE
for the reverse
convention which is somewhat easier to relate to the way the context trees
are represented by draw()
(i.e. recent values at the top the tree).
See Also
find_sequence()
and find_sequence.covlmc()
for direct access to
a specific context, and contexts.ctx_tree()
, contexts.vlmc()
and
contexts.covlmc()
for concrete implementations of contexts()
.
Examples
pc <- powerconsumption[powerconsumption$week == 5, ]
breaks <- c(0, median(pc$active_power), max(pc$active_power))
dts <- cut(pc$active_power, breaks = breaks)
dts_cov <- data.frame(day_night = (pc$hour >= 7 & pc$hour <= 17))
m_cov <- covlmc(dts, dts_cov, min_size = 5)
## direct representation with ctx_node_covlmc objects
m_cov_ctxs <- contexts(m_cov)
m_cov_ctxs
sapply(m_cov_ctxs, covariate_memory)
sapply(m_cov_ctxs, is_merged)
sapply(m_cov_ctxs, model)
## data.frame interface
contexts(m_cov, model = "coef")
contexts(m_cov, model = "full", hsize = TRUE)