Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 13, 2024
1 parent 62aa8ba commit 217ac37
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ print_md.parameters_distribution <- function(x, digits = 2, ci_brackets = c("(",
col_groups <- sapply(models, function(i) which(i == col_names), simplify = FALSE)
# clean column names. These still contain the model name
colnames(formatted_table) <- gsub("(.*) \\((.*)\\)$", "\\1", colnames(formatted_table))
# check if we have column spans at all?
if (all(lengths(col_groups) == 1)) {
col_groups <- NULL
}
# group rows?
if (!is.null(groups)) {
# make sure we have numeric indices for groups
Expand Down
35 changes: 33 additions & 2 deletions tests/testthat/_snaps/compare_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,39 @@
Code
print(out)
Output
+----------------+-----------------------+----------------------+
| | lm1 | lm2 |
+----------------+-----------------------+--------+----------------------+--------+
| | lm1 | lm2 |
+----------------+-----------------------+--------+----------------------+--------+
| Parameter | Estimate (ci) | p | Estimate (ci) | p |
+================+=======================+========+======================+========+
| *Groups* |
+----------------+-----------------------+--------+----------------------+--------+
| grp (1) | 0.00 | | 0.00 | |
+----------------+-----------------------+--------+----------------------+--------+
| grp (2) | -4.31 (-15.95, 7.32) | 0.465 | 0.32 (-22.56, 23.20) | 0.978 |
+----------------+-----------------------+--------+----------------------+--------+
| grp (3) | -1.31 (-13.47, 10.84) | 0.831 | 3.77 (-19.72, 27.26) | 0.752 |
+----------------+-----------------------+--------+----------------------+--------+
| *Interactions* |
+----------------+-----------------------+--------+----------------------+--------+
| Days * grp (2) | | | -1.01 (-5.35, 3.32) | 0.645 |
+----------------+-----------------------+--------+----------------------+--------+
| Days * grp (3) | | | -1.11 (-5.53, 3.31) | 0.621 |
+----------------+-----------------------+--------+----------------------+--------+
| *Controls* |
+----------------+-----------------------+--------+----------------------+--------+
| Days | 10.44 (8.84, 12.03) | <0.001 | 11.23 (7.87, 14.60) | <0.001 |
+----------------+-----------------------+--------+----------------------+--------+
| | | | | |
+----------------+-----------------------+--------+----------------------+--------+
| Observations | 180 | | 180 | |
+----------------+-----------------------+--------+----------------------+--------+

---

Code
print(out)
Output
+----------------+-----------------------+----------------------+
| Parameter | lm1 | lm2 |
+================+=======================+======================+
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-compare_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ withr::with_options(
regex = "Cannot combine"
)

# with reference level
cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept", include_reference = TRUE)
out <- print_md(cp, groups = list(
Groups = 2:4,
Interactions = 5:6,
Controls = 1
))
expect_snapshot(print(out))

# with reference level
cp <- compare_parameters(lm1, lm2, drop = "^\\(Intercept", include_reference = TRUE)
out <- print_md(cp, groups = list(
Expand Down

0 comments on commit 217ac37

Please sign in to comment.