pval_string: Format P-values for Reports

Description Usage Arguments Details Functional Requirements Author(s) Examples

View source: R/pval_string.R

Description

Convert numeric p-values to character strings according to pre-defined formatting parameters. Additional formats may be added for required or desired reporting standards.

Usage

1
2
3
pval_string(p, format = c("default", "exact", "scientific"), digits = 3, ...)

pvalString(p, format = c("default", "exact", "scientific"), digits = 3, ...)

Arguments

p

a numeric vector of p-values.

format

A character string indicating the desired format for the p-values. See Details for full descriptions.

digits

For "exact" and "scientific"; indicates the number of digits to precede scientific notation.

...

Additional arguments to be passed to format

Details

When format = "default", p-values are formatted:

  1. p > 0.99: "> 0.99"

  2. 0.99 > p > 0.10: Rounded to two digits

  3. 0.10 > p > 0.001: Rounded to three digits

  4. 0.001 > p: "< 0.001"

When format = "exact", the exact p-value is printed with the number of places after the deimal equal to digits. P-values smaller that 1*(10^-digits) are printed in scientific notation.

When format = "scientific", all values are printed in scientific notation with digits digits printed before the e.

Functional Requirements

  1. When format = "default", print p-values greater than 0.99 as "> 0.99"; greater than 0.10 with two digits; greater than 0.001 with three digits; and less than 0.001 as "< 0.001".

  2. when format = "exact", print the exact p-value out to at most digits places past the decimal place.

  3. When format = "scientific", print the p-value in scientific notation with up to digits values ahead of the e.

  4. Cast an error if p is not numeric on the interval [0, 1]

  5. Cast an error if format is not one of c("default", "exact", "scientific").

  6. Cast an error if digits is not integerish(1).

Author(s)

Benjamin Nutter

Examples

1
2
3
4
5
6
7
8
 p <- c(1, .999, .905, .505, .205, .125, .09531,
        .05493, .04532, .011234, .0003431, .000000342)
 pvalString(p, format="default")
 pvalString(p, format="exact", digits=3)
 pvalString(p, format="exact", digits=2)
 pvalString(p, format="scientific", digits=3)
 pvalString(p, format="scientific", digits=4)
 

Example output

Additional documentation is being constructed at http://nutterb.github.io/pixiedust/index.html
 [1] "> 0.99"  "> 0.99"  "0.90"    "0.50"    "0.20"    "0.12"    "0.095"  
 [8] "0.055"   "0.045"   "0.011"   "< 0.001" "< 0.001"
 [1] "1.000"    "0.999"    "0.905"    "0.505"    "0.205"    "0.125"   
 [7] "0.095"    "0.055"    "0.045"    "0.011"    "3.43e-04" "3.42e-07"
 [1] "1.00"    "1.00"    "0.90"    "0.50"    "0.20"    "0.12"    "0.10"   
 [8] "0.05"    "0.05"    "0.01"    "3.4e-04" "3.4e-07"
 [1] "1.00e+00" "9.99e-01" "9.05e-01" "5.05e-01" "2.05e-01" "1.25e-01"
 [7] "9.53e-02" "5.49e-02" "4.53e-02" "1.12e-02" "3.43e-04" "3.42e-07"
 [1] "1.000e+00" "9.990e-01" "9.050e-01" "5.050e-01" "2.050e-01" "1.250e-01"
 [7] "9.531e-02" "5.493e-02" "4.532e-02" "1.123e-02" "3.431e-04" "3.420e-07"

pixiedust documentation built on Jan. 16, 2021, 5:25 p.m.