Learn R Programming

reporttools (version 1.1.3)

formatPval: Format P Values

Description

formatPval is intended for formatting \(p\)-values, and is based on the function format.pval in the base R-package.

Usage

formatPval(pv, digits = max(1, getOption("digits") - 2),
           eps = 0.0001, na.form = "NA", scientific = FALSE,
           includeEquality=FALSE)

Arguments

pv

a numeric vector.

digits

how many significant digits are to be used.

eps

a numerical tolerance: see ‘Details’.

na.form

character representation of NAs.

scientific

use scientific number format (not by default)

includeEquality

include equality signs in front of the large \(p\)-values? (not by default)

Value

A character vector.

Details

formatPval is mainly an auxiliary function for the family of table functions, but can also be useful on its own. If a \(p\)-value is smaller than eps, we return just that it is smaller than the threshold but no longer the exact value. This function is more general than format.pval the behaviour of which can (almost) be obtained by using the options eps = .Machine$double.eps and scientific = TRUE.

Examples

Run this code
# NOT RUN {
## include equality signs?
formatPval(c(stats::runif(5), pi^-100, NA))
formatPval(c(stats::runif(5), pi^-100, NA), include=TRUE)

## try another eps argument
formatPval(c(0.1, 0.0001, 1e-7))
formatPval(c(0.1, 0.0001, 1e-7), eps=1e-7)

## only the white space can differ with the base function result:
(a <- formatPval(c(0.1, 0.0001, 1e-27),
                 eps = .Machine$double.eps, scientific = TRUE))
(b <- format.pval(c(0.1, 0.0001, 1e-27)))
all.equal(a, b)
# }

Run the code above in your browser using DataLab