format_p: Format p-values

View source: R/format_p.R

format_pR Documentation

Format p-values

Description

Create rounded, character versions of p-values for presentation

Usage

format_p(p, min_digits = 2, max_digits = 3, level = 0.05, write_p = TRUE)

Arguments

p

A numeric vector of p-values to be formatted

min_digits

The minimum number of digits to display

max_digits

The maximum number of digits to display for a small p-value

level

Significance level tested at

write_p

If TRUE, small values will be written as 'P < 0.001', otherwise will be '< 0.001'

Details

The goal of this function is to round P values for tables or text. If rounding a p value to min_digits is not 0, 1, or the significance level, that is returned. Values rounded to 1 or the significance level will be iteratively rounded to another digit until a distinct value is returned. Values near zero will be iteratively rounded until reaching a nonzero value or reaching max_digits. Remaining values are labeled as 'P < 0.00...1'

Value

An atomic character vector

Author(s)

Sven Halvorson

Examples

p_vals = c(0.6963, 0.00007, 0.0247, 0.0253, 0.999964)

format_p(
  p = p_vals,
  min_digits = 3,
  max_digits = 4,
  level = 0.025
)

svenhalvorson/SvenR documentation built on Aug. 25, 2023, 1:31 p.m.