formatters | R Documentation |
Functions to format various types of outputs. \loadmathjax
fmtp(p, digits=4, pname="", equal=FALSE, sep=FALSE, add0=FALSE, quote=FALSE)
fmtx(x, digits=4, flag="", quote=FALSE, ...)
fmtt(val, tname, df, df1, df2, pval, digits=4,
pname="p-val", format=1, sep=TRUE, quote=FALSE, call=FALSE, ...)
Arguments for fmtp
:
p |
vector of p-values to be formatted. |
digits |
integer to specify the number of decimal places to which the values should be rounded. For |
pname |
string to add as a prefix to the p-value (e.g., something like |
equal |
logical to specify whether an equal symbol should be shown before the p-value (when it is larger than the rounding cutoff). |
sep |
logical to specify whether a space should be added between |
add0 |
logical to specify whether a 0 should be shown before the decimal point when the p-value is below the rounding cutoff. |
quote |
logical to specify whether formatted strings should be quoted when printed. |
Arguments specific for fmtx
:
x |
vector of numeric values to be formatted. |
flag |
a character string giving a format modifier as defined for |
Arguments specific for fmtt
:
val |
test statistic value to be formatted. |
tname |
character string for the name of the test statistic. |
df |
optional value for the degrees of freedom of the test statistic. |
df1 |
optional value for the numerator degrees of freedom of the test statistic. |
df2 |
optional value for the denominator degrees of freedom of the test statistic. |
pval |
the p-value corresponding to the test statistic. |
format |
either |
call |
logical to specify whether the formatted test result should be returned as a call or not. |
... |
other arguments. |
The fmtp
function takes one or multiple p-values as input and rounds them to the chosen number of digits. For p-values that are smaller than 10^(-digits)
(e.g., 0.0001
for digits=4
), the value is shown to fall below this bound (e.g., <.0001
).
The fmtx
function takes one or multiple numeric values as input and rounds them to the chosen number of digits, without using scientific notation and without dropping trailing zeros (using formatC
).
The fmtt
function takes a single test statistic value as input (and, if applicable, its degrees of freedom via argument df
or its numerator and denominator degrees of freedom via arguments df1
and df2
) and the corresponding p-value and formats it for printing. Two different formats are available (chosen via the format
argument), one giving the degrees of freedom before the test statistic (in parentheses) and one after the test statistic.
A character vector with the formatted values. By default (i.e., when quote=FALSE
), formatted strings are not quoted when printed.
The option in fmtt
to return the formatted test result as a call can be useful when adding the output to a plot with text
and one would like to use plotmath
formatting for tname
.
Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org
Viechtbauer, W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1–48. https://doi.org/10.18637/jss.v036.i03
# examples for fmtp()
fmtp(c(.0002, .00008), quote=TRUE, digits=4)
fmtp(c(.0002, .00008), quote=TRUE, digits=4, equal=TRUE)
fmtp(c(.0002, .00008), quote=TRUE, digits=4, equal=TRUE, sep=TRUE)
fmtp(c(.0002, .00008), quote=TRUE, digits=4, equal=TRUE, sep=TRUE, add0=TRUE)
# examples for fmtx()
fmtx(c(1.0002, 2.00008, 3.00004), digits=4)
fmtx(c(-1, 1), digits=4)
fmtx(c(-1, 1), digits=4, flag=" ")
# examples for fmtt()
fmtt(2.45, "z", pval=0.01429, digits=2)
fmtt(3.45, "z", pval=0.00056, digits=2)
fmtt(2.45, "t", df=23, pval=0.02232, digits=2)
fmtt(3.45, "t", df=23, pval=0.00218, digits=2)
fmtt(3.45, "t", df=23, pval=0.00218, digits=2, format=2)
fmtt(46.23, "Q", df=29, pval=0.0226, digits=2)
fmtt(46.23, "Q", df=29, pval=0.0226, digits=2, format=2)
fmtt(8.75, "F", df1=2, df2=35, pval=0.00083, digits=c(2,3))
fmtt(8.75, "F", df1=2, df2=35, pval=0.00083, digits=c(2,3), format=2, pname="p")
fmtt(8.75, "F", df1=2, df2=35, pval=0.00083, digits=c(2,3), format=2, pname="p", sep=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.