Functions to fromat p values.
NOTE: concider using scales::pvalue()
instead.
format_p_values( p, digits_p = 3, cols = NULL, ..., alpha = 0.05, signif_stars = TRUE, rm_zero = FALSE, add_p = FALSE, rm_spaces = FALSE, ss = signif_syms ) # S3 method for default format_p_values( p, digits_p = 3, cols = NULL, ..., signif_stars = TRUE, rm_zero = FALSE, add_p = FALSE, rm_spaces = FALSE, ss = signif_syms ) format_p( p_i, digits_p = 3, signif_stars = TRUE, rm_zero = FALSE, add_p = FALSE, rm_spaces = FALSE, ss = signif_syms ) # S3 method for data.frame format_p_values( p, digits_p = 3, cols = NULL, ..., ss = signif_syms, signif_stars = TRUE, rm_zero = FALSE, add_p = FALSE, rm_spaces = FALSE ) add_signif_stars(p, ss = signif_syms) get_signif_stars(p, ss = signif_syms) signif_syms_05s p05 signif_syms_01s p01 signif_syms_001s p001 signif_syms_001 signif_syms_01 signif_syms_05 signif_syms p05_01_001 p05plus signif_stars_legend_2(ss = signif_syms) signif_stars_legend( ss = signif_syms, decreasing = FALSE, collapse = c(" \n", ", ", "; ") ) rm_zero(str, dec = ".") format_as_p_columns( data, colnames = c("p.value", "p.adjust"), digits_p = 3, rm_zero = FALSE, signif_stars = FALSE, ... )
p | A (vector of) p-value(s). Numeric or coercible to numeric.
Or a |
---|---|
digits_p | (numeric) Number of significant digits to round a p value to. No less than 2.
|
cols, alpha, ss, decreasing, collapse, dec |
|
... | Arguments to further methods. |
signif_stars | (logical) Flag if significance stars should be added to each p value. Not less than 2. |
rm_zero | (logical) Flag if leading zero before the point should be removed. |
add_p | (logical) Flag if letter "p" should included in the expression. |
rm_spaces | (logical) Flag if all spaces should be removed. |
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 1.
An object of class numeric
of length 2.
An object of class numeric
of length 3.
An object of class numeric
of length 4.
An object of class numeric
of length 4.
An object of class numeric
of length 4.
A character vector with formatted p values.
format_p
- formats single p value.
format_as_p_columns
- formats indicated numeric columns in a dataframe as p values (columns are converted into strings).
get_signif_stars
- takes numeric p values brings appopriate stars of statistical significance.
add_signif_stars
- formats numeric p values by adding significance stars (result is character vector).
signif_stars_legend
- generates legend for significance stars (result is a string).
rm_zero
- function removes zero at the beginning of a number (returns a string with the same value but without the leading zero).
#> [1] "<0.001 ***"format_p_values(0.005)#> [1] " 0.005 ** "format_p_values(0.005, signif_stars = FALSE)#> [1] " 0.005"format_p_values(0.005, rm_zero = TRUE)#> [1] " .005 ** "format_p_values(0.005, digits_p = 2)#> [1] "<0.01 ** "format_p_values(0.005, digits_p = 2, rm_zero = TRUE, signif_stars = FALSE)#> [1] "<.01"format_p_values(0.00022)#> [1] "<0.001 ***"format_p_values("0.00022")#> [1] "<0.001 ***"format_p_values("0.052")#> [1] " 0.052 . "#> [1] " 0.005 ** " "<0.001 ***" " 0.052 . "get_signif_stars(0.005)#> [1] "**" #> attr(,"legend") #> [1] "0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"add_signif_stars(0.005)#> [1] "0.005 **"get_signif_stars(0.0005)#> [1] "***" #> attr(,"legend") #> [1] "0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"add_signif_stars(0.0005)#> [1] "5e-04 ***"get_signif_stars(0.052147)#> [1] "." #> attr(,"legend") #> [1] "0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"add_signif_stars(0.052147)#> [1] "0.052147 ."signif_stars_legend()#> [1] "*** - p < 0.001 \n** - p < 0.01 \n* - p < 0.05 \n. - p < 0.1"format_p(0)#> [1] "<0.001 ***"format_p(.02, digits_p = 2)#> [1] " 0.02 * "format_p(.0002)#> [1] "<0.001 ***"format_p(.0002, signif_stars = FALSE)#> [1] "<0.001"#> [1] "<0.001 *****"# TODO **[!!!]**: # 1. Add parameter to emable p value correction # from p = 1 into, e.g., p > 0.999; # # 2. merge parameters `ss` and `signif_stars` # 3. test: format_p(NaN) -- [OK] # 4. test: format_p(NA) -- this function fails with NA as input. rm_zero(0.020)#> [1] ".02"