Skip to content

Commit

Permalink
allow reference category included
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 13, 2024
1 parent 4b0a9d1 commit 9c8a2c8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/compare_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ compare_parameters <- function(...,
coefficient_names = NULL,
keep = NULL,
drop = NULL,
include_reference = FALSE,
verbose = TRUE) {
models <- list(...)

Expand Down Expand Up @@ -186,6 +187,7 @@ compare_parameters <- function(...,
keep = keep,
drop = drop,
wb_component = FALSE,
include_reference = include_reference,
verbose = verbose
)
}
Expand Down
2 changes: 2 additions & 0 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@
# here we either have "<br>" or " " as line breaks, followed by empty "()"
i <- gsub("<br>()", "", i, fixed = TRUE)
i <- gsub(" ()", "", i, fixed = TRUE)
i <- gsub(" (, )", "", i, fixed = TRUE)
i[i == "()"] <- ""
i[i == "(, )"] <- ""
# remove other non-matched patterns
i <- gsub("{stars}", "", i, fixed = TRUE)
i <- gsub("{rhat}", "", i, fixed = TRUE)
Expand Down
8 changes: 8 additions & 0 deletions man/compare_parameters.Rd

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

33 changes: 33 additions & 0 deletions tests/testthat/_snaps/compare_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,36 @@
| SD (Residual) | 31.13 (27.89, 34.75) | | 31.30 (28.02, 34.96) | |
+-------------------------+-----------------------+--------+----------------------+--------+

---

Code
print(out)
Output
+----------------+-----------------------+----------------------+
| | lm1 | lm2 |
+----------------+-----------------------+----------------------+
| Parameter | lm1 | lm2 |
+================+=======================+======================+
| *Groups* |
+----------------+-----------------------+----------------------+
| grp (1) | 0.00 | 0.00 |
+----------------+-----------------------+----------------------+
| grp (2) | -4.31 (-15.95, 7.32) | 0.32 (-22.56, 23.20) |
+----------------+-----------------------+----------------------+
| grp (3) | -1.31 (-13.47, 10.84) | 3.77 (-19.72, 27.26) |
+----------------+-----------------------+----------------------+
| *Interactions* |
+----------------+-----------------------+----------------------+
| Days * grp (2) | | -1.01 (-5.35, 3.32) |
+----------------+-----------------------+----------------------+
| Days * grp (3) | | -1.11 (-5.53, 3.31) |
+----------------+-----------------------+----------------------+
| *Controls* |
+----------------+-----------------------+----------------------+
| Days | 10.44 (8.84, 12.03) | 11.23 (7.87, 14.60) |
+----------------+-----------------------+----------------------+
| | | |
+----------------+-----------------------+----------------------+
| Observations | 180 | 180 |
+----------------+-----------------------+----------------------+

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, drop = "^\\(Intercept", include_reference = TRUE)
out <- print_md(cp, groups = list(
Groups = 2:4,
Interactions = 5:6,
Controls = 1
))
expect_snapshot(print(out))

# error
cp <- compare_parameters(lm1, lm2, select = "{estimate} ({ci})|{p}", drop = "^\\(Intercept")
expect_error(
Expand Down

0 comments on commit 9c8a2c8

Please sign in to comment.