format_p_values: *!!!* Format p-values

Description Usage Arguments Format Details Value Examples

View source: R/format_p_value.R

Description

Functions to fromat p values. NOTE: concider using scales::pvalue() instead.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
)

## Default S3 method:
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 class '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,
  ...
)

Arguments

p

A (vector of) p-value(s). Numeric or coercible to numeric. Or a data.frame.

digits_p

(numeric) Number of significant digits to round a p value to. No less than 2.

  • if digits_p = 2:

    1. values below 0.001 are printed as "<0.001";

    2. values between 0.001 and 0.01 as "<0.01";

    3. all other values are rounded to two decimal places.

  • if digits_p = 3, only formatting "<0.01" is skipped.

cols, alpha, ss, decreasing, collapse, dec

# FIXME: not documented

...

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.

Format

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.

Details

Value

A character vector with formatted p values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(biostat)

# Prettify p-values

format_p_values(0.0005)

format_p_values(0.005)
format_p_values(0.005, signif_stars = FALSE)
format_p_values(0.005, rm_zero = TRUE)
format_p_values(0.005, digits_p = 2)
format_p_values(0.005, digits_p = 2, rm_zero = TRUE, signif_stars = FALSE)

format_p_values(0.00022)
format_p_values("0.00022")
format_p_values("0.052")

format_p_values(c(0.005, 0.0005, 0.052147))


get_signif_stars(0.005)
add_signif_stars(0.005)

get_signif_stars(0.0005)
add_signif_stars(0.0005)

get_signif_stars(0.052147)
add_signif_stars(0.052147)

signif_stars_legend()

format_p(0)
format_p(.02, digits_p = 2)
format_p(.0002)
format_p(.0002, signif_stars = FALSE)
format_p(.0002, ss = c("*****" = 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)

GegznaV/BioStat documentation built on Aug. 14, 2020, 9:30 p.m.