Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 11, 2023
1 parent b696f4a commit 36a29cb
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 26 deletions.
6 changes: 3 additions & 3 deletions R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ display.parameters_model <- function(object,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand Down Expand Up @@ -132,7 +132,7 @@ display.parameters_brms_meta <- display.parameters_model
display.compare_parameters <- function(object,
format = "markdown",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
select = NULL,
column_labels = NULL,
Expand Down Expand Up @@ -165,7 +165,7 @@ display.compare_parameters <- function(object,
display.parameters_sem <- function(object,
format = "markdown",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = c("(", ")"),
...) {
Expand Down
6 changes: 3 additions & 3 deletions R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ equivalence_test.ggeffects <- function(x,
#' @export
format.equivalence_test_lm <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -736,7 +736,7 @@ format.equivalence_test_lm <- function(x,
#' @export
print.equivalence_test_lm <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = NULL,
zap_small = FALSE,
Expand Down Expand Up @@ -794,7 +794,7 @@ plot.equivalence_test_lm <- function(x, ...) {
#' #' @export
#' print_md.equivalence_test_lm <- function(x,
#' digits = 2,
#' ci_digits = 2,
#' ci_digits = digits,
#' p_digits = 3,
#' ci_brackets = NULL,
#' zap_small = FALSE,
Expand Down
6 changes: 3 additions & 3 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ format.parameters_model <- function(x,
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -259,7 +259,7 @@ format.compare_parameters <- function(x,
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = NULL,
ci_brackets = NULL,
Expand Down Expand Up @@ -468,7 +468,7 @@ format.compare_parameters <- function(x,
#' @export
format.parameters_sem <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
format = NULL,
ci_width = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/methods_lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ p_value.blavaan <- p_value.BFBayesFactor
# print ---------------------------

#' @export
print.parameters_sem <- function(x, digits = 2, ci_digits = 2, p_digits = 3, ...) {
print.parameters_sem <- function(x, digits = 2, ci_digits = digits, p_digits = 3, ...) {
# check if user supplied digits attributes
if (missing(digits)) digits <- .additional_arguments(x, "digits", 2)
if (missing(ci_digits)) ci_digits <- .additional_arguments(x, "ci_digits", 2)
Expand Down
2 changes: 1 addition & 1 deletion R/print.compare_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ print.compare_parameters <- function(x,
subtitle = NULL,
footer = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
groups = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/print.parameters_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ print.parameters_random <- function(x, digits = 2, ...) {
split_components = TRUE,
select = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
ci_width = "auto",
Expand Down
4 changes: 2 additions & 2 deletions R/print_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print_html.parameters_model <- function(x,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand Down Expand Up @@ -139,7 +139,7 @@ print_html.compare_parameters <- function(x,
subtitle = NULL,
footer = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
zap_small = FALSE,
groups = NULL,
Expand Down
6 changes: 3 additions & 3 deletions R/print_md.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print_md.parameters_model <- function(x,
footer = NULL,
align = NULL,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
footer_digits = 3,
ci_brackets = c("(", ")"),
Expand Down Expand Up @@ -124,7 +124,7 @@ print_md.parameters_simulate <- print_md.parameters_model
#' @export
print_md.compare_parameters <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
caption = NULL,
subtitle = NULL,
Expand Down Expand Up @@ -178,7 +178,7 @@ print_md.compare_parameters <- function(x,
#' @export
print_md.parameters_sem <- function(x,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_brackets = c("(", ")"),
...) {
Expand Down
4 changes: 2 additions & 2 deletions R/utils_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
.format_columns_single_component <- function(x,
pretty_names,
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
ci_width = "auto",
ci_brackets = TRUE,
Expand Down Expand Up @@ -758,7 +758,7 @@
pretty_names,
split_column = "Component",
digits = 2,
ci_digits = 2,
ci_digits = digits,
p_digits = 3,
coef_column = NULL,
format = NULL,
Expand Down
4 changes: 2 additions & 2 deletions R/utils_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
if ("ci_digits" %in% names(dot.arguments)) {
attr(params, "ci_digits") <- dot.arguments[["ci_digits"]]
} else {
attr(params, "ci_digits") <- 2
attr(params, "ci_digits") <- attr(params, "digits")
}

if ("p_digits" %in% names(dot.arguments)) {
Expand Down Expand Up @@ -394,7 +394,7 @@
if ("ci_digits" %in% names(dot.arguments)) {
attr(params, "ci_digits") <- eval(dot.arguments[["ci_digits"]])
} else {
attr(params, "ci_digits") <- 2
attr(params, "ci_digits") <- attr(params, "digits")
}

if ("p_digits" %in% names(dot.arguments)) {
Expand Down
10 changes: 5 additions & 5 deletions man/display.parameters_model.Rd

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

38 changes: 38 additions & 0 deletions tests/testthat/_snaps/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,44 @@
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a Wald t-distribution approximation.

# digits and ci_digits

Code
print(out, digits = 4)
Output
Parameter | Coefficient | SE | 95% CI | t(24) | p
-------------------------------------------------------------------
hp | -0.0627 | 0.0199 | [-0.10, -0.02] | -3.1541 | 0.004
gear [4] | 0.8223 | 2.2921 | [-3.91, 5.55] | 0.3587 | 0.723
gear [5] | 5.1839 | 2.6751 | [-0.34, 10.71] | 1.9378 | 0.064
vs | 1.9583 | 2.0920 | [-2.36, 6.28] | 0.9361 | 0.359
cyl [6] | -2.3057 | 2.1418 | [-6.73, 2.11] | -1.0765 | 0.292
cyl [8] | 0.9279 | 4.3980 | [-8.15, 10.00] | 0.2110 | 0.835
drat | 2.3430 | 1.9741 | [-1.73, 6.42] | 1.1869 | 0.247
Message <simpleMessage>
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a Wald t-distribution approximation.

---

Code
print(out, digits = 4, ci_digits = 2)
Output
Parameter | Coefficient | SE | 95% CI | t(24) | p
-------------------------------------------------------------------
hp | -0.0627 | 0.0199 | [-0.10, -0.02] | -3.1541 | 0.004
gear [4] | 0.8223 | 2.2921 | [-3.91, 5.55] | 0.3587 | 0.723
gear [5] | 5.1839 | 2.6751 | [-0.34, 10.71] | 1.9378 | 0.064
vs | 1.9583 | 2.0920 | [-2.36, 6.28] | 0.9361 | 0.359
cyl [6] | -2.3057 | 2.1418 | [-6.73, 2.11] | -1.0765 | 0.292
cyl [8] | 0.9279 | 4.3980 | [-8.15, 10.00] | 0.2110 | 0.835
drat | 2.3430 | 1.9741 | [-1.73, 6.42] | 1.1869 | 0.247
Message <simpleMessage>
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
using a Wald t-distribution approximation.

# select pattern

Code
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ withr::with_options(
})


# Digits ------
test_that("digits and ci_digits", {
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
model <- lm(mpg ~ hp + gear + vs + cyl + drat, data = mtcars)

# don't select "Intercept" parameter
out <- model_parameters(model, drop = "^\\(Intercept")
expect_snapshot(print(out, digits = 4))
expect_snapshot(print(out, digits = 4, ci_digits = 2))
})


# Table templates ------
test_that("select pattern", {
mtcars$cyl <- as.factor(mtcars$cyl)
Expand Down

0 comments on commit 36a29cb

Please sign in to comment.