Skip to contents

This function 'draws' a context tree as a text.

Usage

# S3 method for covlmc
draw(
  ct,
  control = draw_control(),
  model = c("coef", "full"),
  p_value = TRUE,
  digits = 4,
  with_state = FALSE,
  ...
)

Arguments

ct

a fitted covlmc model.

control

a list of low level control parameters of the text representation. See details and draw_control().

model

this parameter controls the display of logistic models associated to nodes. The default model="coef" represents the coefficients of the logistic models associated to each context. model="full" includes the name of the variables in the representation (see details). Setting model=NULL removes the model representations. Additional parameters can be used to tweak model representations (see details).

p_value

specifies whether the p-values of the likelihood ratio tests conducted during the covlmc construction must be included in the representation.

digits

numerical parameters and p-values are represented using the base::signif function, using the number of significant digits specified with this parameter.

with_state

specifies whether to display the state associated to each dimension of the logistic model (see details).

...

additional arguments for draw.

Value

the context tree (invisibly).

Details

The function uses basic "ascii art" to represent the context tree. Characters used to represent the structure of the tree, e.g. branches, can be modified using draw_control().

In addition to the structure of the context tree, draw can represent information attached to the node (contexts and partial contexts). This is controlled by additional parameters depending on the type of the context tree.

Tweaking model representation

Model representations are affected by the following additional parameter:

  • time_sep: character(s) used to split the coefficients list by blocks associated to time delays in the covariate inclusion into the logistic model. The first block contains the intercept(s), the second block the covariate values a time t-1, the third block at time t-2, etc.

Variable representation

When model="full", the representation includes the names of the variables used by the logistic models. Names are the one generated by the underlying logistic model, e.g. stats::glm(). Numerical variable names are used as is, while factors have levels appended. The intercept is denoted (I) to save space. The time delays are represented by an underscore followed by the time delay. For instance if the model uses the numerical covariate y with two delays, it will appear as to variables y_1 and y_2.

State representation

When model is not NULL, the coefficients of the logistic models are presented, organized in rows associated to states. One state is used as the reference state and the logistic model aims at predicting the ratio of probability between another state and the reference one (in log scale). When with_state is TRUE, the display includes for each row of coefficients the target state. This is useful when using e.g. VGAM::vglm as unused levels of the target variable will be automatically dropped from the model, leading to a reduce number of rows. The reference state is either shown on the first row if model is "full" or after the state on each row if model is "coef".

Examples

pc <- powerconsumption[powerconsumption$week == 5, ]
dts <- cut(pc$active_power, breaks = c(0, quantile(pc$active_power, probs = c(0.5, 1))))
dts_cov <- data.frame(day_night = (pc$hour >= 7 & pc$hour <= 17))
m_cov <- covlmc(dts, dts_cov, min_size = 5)
draw(m_cov, digits = 3)
#> *
#> +-- (0,1.34]
#> |   +-- (0,1.34]
#> |   |   +-- (0,1.34] (0.0233 [ -2.81 2.18 -4.45 2.42 ])
#> |   |   '-- (1.34,7.54] (0.0183 [ -19.6 18.4 ])
#> |   '-- (1.34,7.54] (0.676 [ -1.86 ])
#> '-- (1.34,7.54] (0.818 [ 2.54 ])
draw(m_cov, model = NULL)
#> *
#> +-- (0,1.34]
#> |   +-- (0,1.34]
#> |   |   +-- (0,1.34] (0.02329)
#> |   |   '-- (1.34,7.54] (0.01834)
#> |   '-- (1.34,7.54] (0.6763)
#> '-- (1.34,7.54] (0.8175)
draw(m_cov, p_value = FALSE)
#> *
#> +-- (0,1.34]
#> |   +-- (0,1.34]
#> |   |   +-- (0,1.34] ([ -2.813 2.178 -4.449 2.418 ])
#> |   |   '-- (1.34,7.54] ([ -19.57 18.39 ])
#> |   '-- (1.34,7.54] ([ -1.856 ])
#> '-- (1.34,7.54] ([ 2.535 ])
draw(m_cov, p_value = FALSE, time_sep = " | ")
#> *
#> +-- (0,1.34]
#> |   +-- (0,1.34]
#> |   |   +-- (0,1.34] ([ -2.813 | 2.178 | -4.449 | 2.418 ])
#> |   |   '-- (1.34,7.54] ([ -19.57 | 18.39 ])
#> |   '-- (1.34,7.54] ([ -1.856 ])
#> '-- (1.34,7.54] ([ 2.535 ])
draw(m_cov, model = "full", time_sep = " | ")
#> *
#> +-- (0,1.34]
#> |   +-- (0,1.34]
#> |   |   +-- (0,1.34] (0.02329 [ (I)    | day_night_1TRUE | day_night_2TRUE | day_night_3TRUE
#> |   |   |                       -2.813 | 2.178           | -4.449          | 2.418           ])
#> |   |   '-- (1.34,7.54] (0.01834 [ (I)    | day_night_1TRUE
#> |   |                              -19.57 | 18.39           ])
#> |   '-- (1.34,7.54] (0.6763 [ (I)   
#> |                             -1.856 ])
#> '-- (1.34,7.54] (0.8175 [ (I)  
#>                           2.535 ])