formatPval: Format p-Values

View source: R/formatPval.R

formatPvalR Documentation

Format p-Values

Description

formatPval returns p-values according to the number of significant digits:

  • p-values < break.eps are written as "< break.eps".

  • p-values >= break.eps but < break.middle have 1 significant digit.

  • p-values >= break.middle have 2 significant digits.

whereas formatPvalStrict allows the user to fix the number of digits after the decimal point. In case of digits = 2 this means:

  • p-values < 0.01 (10^(-digits)) are written as "< 0.01".

  • p-values >= 0.01 are rounded to 2 digits after the decimal point.

Usage

formatPval(x, break.eps = 1e-04, break.middle = 0.01, na.form = "NA", ...)

formatPvalStrict(x, digits = 2L, na.form = "NA", ...)

Arguments

x

Numeric vector of p-values.

break.eps

Numeric vector of length 1.

break.middle

Numeric vector of length 1.

na.form

Character representation of NAs.

...

Additional arguments passed to format or formatC.

digits

Numeric vector of length 1 or length(x) indicating the number of digits after the decimal point that should be returned.

Details

formatPval internally uses format whereas formatPvalStrict uses formatC.

Value

A vector of length(x) with formatted p-values.

Author(s)

Sina Rueeger, Sebastian Meyer, and Felix Hofmann

See Also

the base function format.pval, format.pval in package Hmisc, formatPval in package reporttools, formatPval in package surveillance

Examples


x <- c(1e-8, 0.00568, 0.0345, 0.885)
biostatUZH::formatPval(x)  # "< 0.0001" "0.006" "0.035" "0.89"
biostatUZH::formatPvalStrict(x, digits = 2) # "< 0.01" "< 0.01" "0.03" "0.89"

## compare to formatting of other packages
if (requireNamespace("reporttools")) {
    reporttools::formatPval(x) # "< 0.0001" "0.0057" "0.03" "0.88"
}
if (requireNamespace("Hmisc")) {
    Hmisc::format.pval(x)  # "0" "0.00568" "0.03450" "0.88500"
}
if (requireNamespace("surveillance")) {
    surveillance::formatPval(x)  # "<0.0001" "0.0057" "0.035" "0.89"
}

## adapt break.middle
biostatUZH::formatPval(x, break.middle = 0.001)


felix-hof/biostatUZH documentation built on Sept. 27, 2024, 1:48 p.m.