Learn R Programming

DMAR (version 1.0.0)

format_p: Format p-values for Display the DMAR Way

Description

Render a vector of p-values as character strings at a fixed number of decimal places (default 4) with a floor label “< 10^(-digits_p)” for values too small to express. Never uses scientific notation. This is the package-wide convention for displaying p-values used by the dmar_tbl print layer, by correlations_test, and by the helper display functions print_anova and print_summary. Exposing it as a user-facing function lets analysts apply the same convention to ad hoc p-values that they want to report in prose or in a manually constructed table.

Usage

format_p(p, digits_p = 4L)

Value

A character vector of the same length as p.

Arguments

p

Numeric vector of p-values. NA values pass through as NA_character_.

digits_p

Integer number of decimal places. Default 4L. Values strictly below \(10^{-\mathrm{digits\_p}}\) render as the floor label “< 10^(-digits_p)” (for example “< 0.0001” when digits_p = 4).

Author

Ken Kelley

Details

The function does not modify the input value; the underlying numeric p-value retains full precision and can still be indexed out of whatever object holds it. Only the returned display string is rounded.

See Also

print_anova, print_summary, dmar_tbl.

Examples

Run this code
# Round to four decimals with a "< 0.0001" floor:
format_p(c(0.5, 0.0234, 0.0001234, 1e-10, NA))

# Six decimals when more precision is wanted:
format_p(0.0001234, digits_p = 6)

# Use inline in prose for a publication-style summary:
fit <- lm(weight ~ Time + Diet, data = ChickWeight)
p_time <- summary(fit)$coefficients["Time", "Pr(>|t|)"]
paste0("The Time coefficient was significant (p = ", format_p(p_time), ").")

Run the code above in your browser using DataLab