This function will round p values according to the APA guideline. It will try to round to two decimals where possible, and will try to avoid printing the value of alpha, see Examples.

format_p_value(p, alpha = 0.05, prepend_p = FALSE)

Arguments

p

p value(s) to transform

alpha

the value of alpha, defaults to 0.05

prepend_p

a logical to indicate whether "p =" should be prepended to the result

Value

A character

Examples

format_p_value(0.345678)
#> [1] "0.35"
format_p_value(0.05125)
#> [1] "0.051"

# this must not be "0.05", but is not "0.049" either,
# so it will add as many decimals as needed:
format_p_value(0.04993) 
#> [1] "0.0499"

format_p_value(c(0.123, 0.00000001))
#> [1] "0.12"    "< 0.001"
format_p_value(c(0.123, 0.00000001), prepend_p = TRUE)
#> [1] "p = 0.12"  "p < 0.001"