Skip to content

Commit 22dcff9

Browse files
committed
1 parent 7edeef7 commit 22dcff9

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Changes to functions
44

55
* `tab_model()` now accepts all options for `p.val` that are supported by `parameters::model_parameters()`.
6+
* The `p.style` argument in `tab_model()` was slightly revised, and now also accepts `"scientific"` as option for scientific notation of p-values.
67

78
## Bug fixes
89

R/tab_model.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@
142142
#' \code{show.df = TRUE} to show the approximated degrees of freedom
143143
#' for each coefficient.
144144
#' @param p.style Character, indicating if p-values should be printed as
145-
#' numeric value (\code{"numeric"}), as asterisks (\code{"asterisk"})
146-
#' or both (\code{"both"}). May be abbreviated.
145+
#' numeric value (\code{"numeric"}), as 'stars' (asterisks) only (\code{"stars"}),
146+
#' or scientific (\code{"scientific"}). Scientific and numeric style can be
147+
#' combined with "stars", e.g. \code{"numeric_stars"}
147148
#' @param CSS A \code{\link{list}} with user-defined style-sheet-definitions,
148149
#' according to the \href{http://www.w3.org/Style/CSS/}{official CSS syntax}.
149150
#' See 'Details' or \href{https://strengejacke.github.io/sjPlot/articles/table_css.html}{this package-vignette}.
@@ -308,7 +309,7 @@ tab_model <- function(
308309
digits.p = 3,
309310
emph.p = TRUE,
310311
p.val = c("wald", "kenward", "kr", "satterthwaite", "ml1", "betwithin"),
311-
p.style = c("numeric", "asterisk", "both"),
312+
p.style = c("numeric", "stars", "numeric_stars", "scientific", "scientific_stars"),
312313
p.threshold = c(0.05, 0.01, 0.001),
313314
p.adjust = NULL,
314315

@@ -337,7 +338,7 @@ tab_model <- function(
337338
case <- NULL
338339
}
339340

340-
if (p.style == "asterisk") show.p <- FALSE
341+
if (p.style == "stars") show.p <- FALSE
341342

342343
# default robust?
343344
if (isTRUE(robust)) {
@@ -468,10 +469,15 @@ tab_model <- function(
468469
dplyr::select(-.data$conf.low, -.data$conf.high) %>%
469470
dplyr::mutate(
470471
p.stars = get_p_stars(.data$p.value, p.threshold),
471-
p.sig = .data$p.value < .05,
472-
p.value = sprintf("%.*f", digits.p, .data$p.value)
472+
p.sig = .data$p.value < .05
473473
)
474474

475+
if (grepl("scientific", p.style)) {
476+
dat$p.value <- formatC(dat$p.value, format = "e", digits = digits.p)
477+
} else {
478+
dat$p.value <- sprintf("%.*f", digits.p, dat$p.value)
479+
}
480+
475481

476482
# emphasize p-values ----
477483

@@ -519,6 +525,7 @@ tab_model <- function(
519525
facets = FALSE,
520526
show.zeroinf = show.zeroinf,
521527
p.val = p.val,
528+
p_adjust = p.adjust,
522529
standardize = std_method,
523530
bootstrap = bootstrap,
524531
iterations = iterations,
@@ -546,7 +553,7 @@ tab_model <- function(
546553

547554
# add asterisks to estimates ----
548555

549-
if (p.style %in% c("asterisk", "both")) {
556+
if (grepl("stars", p.style)) {
550557
if (obj_has_name(dat, "estimate"))
551558
dat$estimate <- sprintf("%.*f <sup>%s</sup>", digits, dat$estimate, dat$p.stars)
552559
if (!show.est && obj_has_name(dat, "std.estimate"))
@@ -1173,7 +1180,7 @@ tab_model <- function(
11731180
})
11741181

11751182

1176-
if (p.style %in% c("asterisk", "both"))
1183+
if (grepl("stars", p.style))
11771184
footnote <- sprintf(
11781185
"* p&lt;%s&nbsp;&nbsp;&nbsp;** p&lt;%s&nbsp;&nbsp;&nbsp;*** p&lt;%s",
11791186
format(p.threshold[1]),

man/tab_model.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/tab_model_estimates.Rmd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,18 @@ To show variable names, categories and include the reference level, also set `pr
240240
tab_model(model, show.reflvl = TRUE, prefix.labels = "varname")
241241
```
242242

243-
## Show asterisks instead of numeric p-values
243+
## Style of p-values
244244

245-
You can change the style of how p-values are displayed with the argument `p.style`. With `p.style = "asterisk"`, the p-values are indicated as `*` in the table.
245+
You can change the style of how p-values are displayed with the argument `p.style`. With `p.style = "stars"`, the p-values are indicated as `*` in the table.
246246

247247
```{r}
248-
tab_model(m1, m2, p.style = "a")
248+
tab_model(m1, m2, p.style = "stars")
249+
```
250+
251+
Another option would be scientific notation, using `p.style = "scientific"`, which also can be combined with `digits.p`.
252+
253+
```{r}
254+
tab_model(m1, m2, p.style = "scientific", digits.p = 2)
249255
```
250256

251257

0 commit comments

Comments
 (0)