nice_p.RdThis function formats p values for presentation. P values >= 0.05 are rounded to a specified number of digits, while p values < 0.05 are displayed as "<.05", "<.01", or "<.001".
nice_p(p, equal_sign = FALSE, digits = 3, stars = FALSE)A character vector with nicely formatted p values suitable for presentation.
If stars is TRUE, significance stars are added for p values < 0.05.
The function also allows to set an equal sign before p values
if equal_sign is TRUE.
P values are formatted as follows:
p >= 0.05: Rounded to the specified number of digits (e.g., 0.123)
0.01 <= p < 0.05: Displayed as "<.05" (or with stars if stars is TRUE)
0.001 <= p < 0.01: Displayed as "<.01" (or with stars if stars is TRUE)
p < 0.001: Displayed as "<.001" (or with stars if stars is TRUE)
p <- c(0.04, 0.9, 0.10, 0.001, 1, NA)
nice_p(p)
#> [1] "<.05" ".900" ".100" "<.01" "1.000" NA
paste0("p", nice_p(p, equal_sign = TRUE))
#> [1] "p<.05" "p=.900" "p=.100" "p<.01" "p=1.000" "pNA"
nice_p(p, stars = TRUE)
#> [1] ".040*" ".900" ".100" ".001**" "1.000" NA
paste0("p", nice_p(p, equal_sign = TRUE, stars = TRUE))
#> [1] "p=.040*" "p=.900" "p=.100" "p=.001**" "p=1.000" "pNA"
nice_p(c(0.0004, 0.005, 0.03, 0.2), stars = TRUE)
#> [1] "<.001***" ".005**" ".030*" ".200"
paste0("p", nice_p(c(0.0004, 0.005, 0.03, 0.2), equal_sign = TRUE, stars = TRUE))
#> [1] "p<.001***" "p=.005**" "p=.030*" "p=.200"