Skip to content

Commit

Permalink
Add delimiters around p-values (issue #66).
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrice-rossi committed Mar 13, 2024
1 parent 1c5b9f6 commit 559f4b8
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 73 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
## Breaking changes
* defaults for `draw.covlmc()` have changed (issue #66):
* `p_value` is now `FALSE` by default
* when `p_value` is `TRUE` the p-values are represented between separators
given by the `open_p_value` and `close_p_value` members of the `control`
list. Defaults are `<` and `>`
* the intercept is separated from other coefficients by the characters
specified in the `intercept_sep` member of the `control` list. Defaults
to `" & "`
Expand Down
16 changes: 14 additions & 2 deletions R/covlmc_draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ draw_covlmc_model <- function(coefficients, p_value, hsize, names, lev, params,
}
if (length(coeffs) == 1) {
if (isTRUE(params$p_value)) {
stringr::str_c(signif_null(p_value, params$digits), "[", coeffs, "]", sep = " ")
p_value_str <- stringr::str_c(control$open_p_value,
signif_null(p_value, params$digits),
control$close_p_value,
sep = ""
)
stringr::str_c(p_value_str, "[", coeffs, "]", sep = " ")
} else {
stringr::str_c("[", coeffs, "]", sep = " ")
}
} else {
if (isTRUE(params$p_value)) {
p_value_str <- as.character(signif_null(p_value, params$digits))
p_value_str <- stringr::str_c(control$open_p_value,
as.character(signif_null(p_value, params$digits)),
control$close_p_value,
sep = ""
)
pad <- stringr::str_pad("", stringr::str_length(p_value_str) + 2)
coeffs[1] <- stringr::str_c(p_value_str, "[", coeffs[1], sep = " ")
} else {
Expand Down Expand Up @@ -185,6 +194,9 @@ covlmc_node2txt <- function(node, vals, params, control) {
#'
#' - `level_sep`: character(s) used separate levels from model, see below.
#'
#' - `open_p_value` and `close_p_value`: delimiters used around the p-values
#' when `p_value=TRUE`
#'
#' @section Variable representation:
#'
#' When `model="full"`, the representation includes the names of the variables
Expand Down
12 changes: 10 additions & 2 deletions R/ctx_tree_draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#' @param time_sep characters used to separate temporal blocks in [draw.covlmc()].
#' @param intercept_sep characters used to the intercept from the other parameters
#' in [draw.covlmc()]
#' @param open_p_value characters used as opening delimiters for the p value of
#' a node in [draw.covlmc()]
#' @param close_p_value characters used as closing delimiters for the p value of
#' a node in [draw.covlmc()]
#'
#' @returns a list
#' @export
Expand All @@ -28,7 +32,9 @@ draw_control <- function(root = "*",
close_ct = ")",
level_sep = " ~ ",
time_sep = " | ",
intercept_sep = " & ") {
intercept_sep = " & ",
open_p_value = "<",
close_p_value = ">") {
list(
root = root,
first_node = first_node,
Expand All @@ -39,7 +45,9 @@ draw_control <- function(root = "*",
close_ct = close_ct,
level_sep = level_sep,
time_sep = time_sep,
intercept_sep = intercept_sep
intercept_sep = intercept_sep,
open_p_value = open_p_value,
close_p_value = close_p_value
)
}

Expand Down
2 changes: 2 additions & 0 deletions man/draw.covlmc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion man/draw_control.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 68 additions & 68 deletions tests/testthat/_snaps/covlmc_trim.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
| +-- (0,1.28]
| | +-- (0,1.28]
| | | +-- (0,1.28]
| | | | +-- (0,1.28] (0.0025 [ (1.28,7.54]/(0,1.28] ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (0.12 [ (1.28,7.54]/(0,1.28] ~ -2.3 ])
| | | '-- (1.28,7.54] (0.9 [ (1.28,7.54]/(0,1.28] ~ -2.1 ])
| | '-- (1.28,7.54] (0.036 [ (1.28,7.54]/(0,1.28] ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (0.15 [ (1.28,7.54]/(0,1.28] ~ -1.6 ])
| | | | +-- (0,1.28] (<0.0025> [ (1.28,7.54]/(0,1.28] ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (<0.12> [ (1.28,7.54]/(0,1.28] ~ -2.3 ])
| | | '-- (1.28,7.54] (<0.9> [ (1.28,7.54]/(0,1.28] ~ -2.1 ])
| | '-- (1.28,7.54] (<0.036> [ (1.28,7.54]/(0,1.28] ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (<0.15> [ (1.28,7.54]/(0,1.28] ~ -1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (0.75 [ (1.28,7.54]/(0,1.28] ~ 1.6 ])
+-- (0,1.28] (<0.75> [ (1.28,7.54]/(0,1.28] ~ 1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (1 [ (1.28,7.54]/(0,1.28] ~ 1.8 ])
+-- (0,1.28] (<1> [ (1.28,7.54]/(0,1.28] ~ 1.8 ])
'-- (1.28,7.54] (collapsing: 0.0032)
+-- (0,1.28] (0.029 [ (1.28,7.54]/(0,1.28] ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (0.72 [ (1.28,7.54]/(0,1.28] ~ 2.8 ])
+-- (0,1.28] (<0.029> [ (1.28,7.54]/(0,1.28] ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (<0.72> [ (1.28,7.54]/(0,1.28] ~ 2.8 ])

---

Expand Down Expand Up @@ -54,18 +54,18 @@
| +-- (0,1.28]
| | +-- (0,1.28]
| | | +-- (0,1.28]
| | | | +-- (0,1.28] (0.0025 [ (1.28,7.54]/(0,1.28] ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (0.12 [ (1.28,7.54]/(0,1.28] ~ -2.3 ])
| | | '-- (1.28,7.54] (0.9 [ (1.28,7.54]/(0,1.28] ~ -2.1 ])
| | '-- (1.28,7.54] (0.036 [ (1.28,7.54]/(0,1.28] ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (0.15 [ (1.28,7.54]/(0,1.28] ~ -1.6 ])
| | | | +-- (0,1.28] (<0.0025> [ (1.28,7.54]/(0,1.28] ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (<0.12> [ (1.28,7.54]/(0,1.28] ~ -2.3 ])
| | | '-- (1.28,7.54] (<0.9> [ (1.28,7.54]/(0,1.28] ~ -2.1 ])
| | '-- (1.28,7.54] (<0.036> [ (1.28,7.54]/(0,1.28] ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (<0.15> [ (1.28,7.54]/(0,1.28] ~ -1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (0.75 [ (1.28,7.54]/(0,1.28] ~ 1.6 ])
+-- (0,1.28] (<0.75> [ (1.28,7.54]/(0,1.28] ~ 1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (1 [ (1.28,7.54]/(0,1.28] ~ 1.8 ])
+-- (0,1.28] (<1> [ (1.28,7.54]/(0,1.28] ~ 1.8 ])
'-- (1.28,7.54] (collapsing: 0.0032)
+-- (0,1.28] (0.029 [ (1.28,7.54]/(0,1.28] ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (0.72 [ (1.28,7.54]/(0,1.28] ~ 2.8 ])
+-- (0,1.28] (<0.029> [ (1.28,7.54]/(0,1.28] ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (<0.72> [ (1.28,7.54]/(0,1.28] ~ 2.8 ])

---

Expand Down Expand Up @@ -139,15 +139,15 @@
draw(t_m_cov_model, model = "coef", with_state = TRUE, digits = 2, p_value = TRUE)
Output
*
+-- (0,0.48] (8.7e-07 [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
+-- (0,0.48] (<8.7e-07> [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
'-- (0.48,1.63]
| +-- (0,0.48] (0.016 [ (0.48,1.63]/(0,0.48] ~ 0.12 & -16 | 17
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -16 | 15 ])
| '-- (0.48,1.63], (1.63,7.54] (0.0049 [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (2.4e-06 [ (0.48,1.63]/(0,0.48] ~ 18 & -15
(1.63,7.54]/(0,0.48] ~ 20 & -16 ])
| +-- (0,0.48] (<0.016> [ (0.48,1.63]/(0,0.48] ~ 0.12 & -16 | 17
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -16 | 15 ])
| '-- (0.48,1.63], (1.63,7.54] (<0.0049> [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (<2.4e-06> [ (0.48,1.63]/(0,0.48] ~ 18 & -15
(1.63,7.54]/(0,0.48] ~ 20 & -16 ])

---

Expand All @@ -171,15 +171,15 @@
draw(t_m_cov, model = "coef", with_state = TRUE, digits = 2, p_value = TRUE)
Output
*
+-- (0,0.48] (8.7e-07 [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
+-- (0,0.48] (<8.7e-07> [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
'-- (0.48,1.63]
| +-- (0,0.48] (0.016 [ (0.48,1.63]/(0,0.48] ~ 0.12 & -16 | 17
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -16 | 15 ])
| '-- (0.48,1.63], (1.63,7.54] (0.0049 [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (2.4e-06 [ (0.48,1.63]/(0,0.48] ~ 18 & -15
(1.63,7.54]/(0,0.48] ~ 20 & -16 ])
| +-- (0,0.48] (<0.016> [ (0.48,1.63]/(0,0.48] ~ 0.12 & -16 | 17
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -16 | 15 ])
| '-- (0.48,1.63], (1.63,7.54] (<0.0049> [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (<2.4e-06> [ (0.48,1.63]/(0,0.48] ~ 18 & -15
(1.63,7.54]/(0,0.48] ~ 20 & -16 ])

---

Expand Down Expand Up @@ -233,18 +233,18 @@
| +-- (0,1.28]
| | +-- (0,1.28]
| | | +-- (0,1.28]
| | | | +-- (0,1.28] (0.0025 [ 1/0 ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (0.12 [ 1/0 ~ -2.3 ])
| | | '-- (1.28,7.54] (0.9 [ 1/0 ~ -2.1 ])
| | '-- (1.28,7.54] (0.036 [ 1/0 ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (0.15 [ 1/0 ~ -1.6 ])
| | | | +-- (0,1.28] (<0.0025> [ 1/0 ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (<0.12> [ 1/0 ~ -2.3 ])
| | | '-- (1.28,7.54] (<0.9> [ 1/0 ~ -2.1 ])
| | '-- (1.28,7.54] (<0.036> [ 1/0 ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (<0.15> [ 1/0 ~ -1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (0.75 [ 1/0 ~ 1.6 ])
+-- (0,1.28] (<0.75> [ 1/0 ~ 1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (1 [ 1/0 ~ 1.8 ])
+-- (0,1.28] (<1> [ 1/0 ~ 1.8 ])
'-- (1.28,7.54] (collapsing: 0.0032)
+-- (0,1.28] (0.029 [ 1/0 ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (0.72 [ 1/0 ~ 2.8 ])
+-- (0,1.28] (<0.029> [ 1/0 ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (<0.72> [ 1/0 ~ 2.8 ])

---

Expand Down Expand Up @@ -279,18 +279,18 @@
| +-- (0,1.28]
| | +-- (0,1.28]
| | | +-- (0,1.28]
| | | | +-- (0,1.28] (0.0025 [ 1/0 ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (0.12 [ 1/0 ~ -2.3 ])
| | | '-- (1.28,7.54] (0.9 [ 1/0 ~ -2.1 ])
| | '-- (1.28,7.54] (0.036 [ 1/0 ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (0.15 [ 1/0 ~ -1.6 ])
| | | | +-- (0,1.28] (<0.0025> [ 1/0 ~ -3 & -0.43 | -0.64 | 1.5 | -2.3 | 2.6 ])
| | | | '-- (1.28,7.54] (<0.12> [ 1/0 ~ -2.3 ])
| | | '-- (1.28,7.54] (<0.9> [ 1/0 ~ -2.1 ])
| | '-- (1.28,7.54] (<0.036> [ 1/0 ~ -2.7 & 1.3 ])
| '-- (1.28,7.54] (<0.15> [ 1/0 ~ -1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (0.75 [ 1/0 ~ 1.6 ])
+-- (0,1.28] (<0.75> [ 1/0 ~ 1.6 ])
'-- (1.28,7.54]
+-- (0,1.28] (1 [ 1/0 ~ 1.8 ])
+-- (0,1.28] (<1> [ 1/0 ~ 1.8 ])
'-- (1.28,7.54] (collapsing: 0.0032)
+-- (0,1.28] (0.029 [ 1/0 ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (0.72 [ 1/0 ~ 2.8 ])
+-- (0,1.28] (<0.029> [ 1/0 ~ 0.99 & 1.3 ])
'-- (1.28,7.54] (<0.72> [ 1/0 ~ 2.8 ])

---

Expand Down Expand Up @@ -364,15 +364,15 @@
draw(t_m_cov_model, model = "coef", with_state = TRUE, digits = 2, p_value = TRUE)
Output
*
+-- (0,0.48] (8.7e-07 [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
+-- (0,0.48] (<8.7e-07> [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
'-- (0.48,1.63]
| +-- (0,0.48] (0.016 [ (0.48,1.63]/(0,0.48] ~ 0.12 & -9.1 | 9.6
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -9.4 | 8.5 ])
| '-- (0.48,1.63], (1.63,7.54] (0.0049 [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (2.4e-06 [ (0.48,1.63]/(0,0.48] ~ 10 & -7.5
(1.63,7.54]/(0,0.48] ~ 13 & -8.4 ])
| +-- (0,0.48] (<0.016> [ (0.48,1.63]/(0,0.48] ~ 0.12 & -9.1 | 9.6
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -9.4 | 8.5 ])
| '-- (0.48,1.63], (1.63,7.54] (<0.0049> [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (<2.4e-06> [ (0.48,1.63]/(0,0.48] ~ 10 & -7.5
(1.63,7.54]/(0,0.48] ~ 13 & -8.4 ])

---

Expand All @@ -396,15 +396,15 @@
draw(t_m_cov, model = "coef", with_state = TRUE, digits = 2, p_value = TRUE)
Output
*
+-- (0,0.48] (8.7e-07 [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
+-- (0,0.48] (<8.7e-07> [ (0.48,1.63]/(0,0.48] ~ -2.7 & 1.1
| (1.63,7.54]/(0,0.48] ~ -4.5 & 0.84 ])
'-- (0.48,1.63]
| +-- (0,0.48] (0.016 [ (0.48,1.63]/(0,0.48] ~ 0.12 & -9.1 | 9.6
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -9.4 | 8.5 ])
| '-- (0.48,1.63], (1.63,7.54] (0.0049 [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (2.4e-06 [ (0.48,1.63]/(0,0.48] ~ 10 & -7.5
(1.63,7.54]/(0,0.48] ~ 13 & -8.4 ])
| +-- (0,0.48] (<0.016> [ (0.48,1.63]/(0,0.48] ~ 0.12 & -9.1 | 9.6
| | (1.63,7.54]/(0,0.48] ~ -0.37 & -9.4 | 8.5 ])
| '-- (0.48,1.63], (1.63,7.54] (<0.0049> [ (0.48,1.63]/(0,0.48] ~ 2 & 0.58
| (1.63,7.54]/(0,0.48] ~ -0.31 & 1 ])
'-- (1.63,7.54] (<2.4e-06> [ (0.48,1.63]/(0,0.48] ~ 10 & -7.5
(1.63,7.54]/(0,0.48] ~ 13 & -8.4 ])

---

Expand Down

0 comments on commit 559f4b8

Please sign in to comment.