Is there a function to round p values?
r
Solution
(I answer my own question thank's to @James comments.)
Use `format.pval` with the right arguments. `digits` and `eps` are the most important.
Example :
pvalues <- c(0.99, 0.2, 0.32312, 0.0000123213, 0.002)
format.pval(pv = pvalues,
# digits : number of digits, but after the 0.0
digits = 2,
# eps = the threshold value above wich the
# function will replace the pvalue by "<0.0xxx"
eps = 0.001,
# nsmall = how much tails 0 to keep if digits of
# original value < to digits defined
nsmall = 3
)
# "0.990" "0.200" "0.323" "<0.001" "0.002"
`format.pval` return a character vector.
To have the stars just use `ifelse` or write a function
ifelse(pvalues < 0.05, "*", "")
Problem
In `glm`, `lm` and others function in r which produced pvalues, there are kindly printed. For example : ``` p found | p printed --------- | ----- 0.000032 | <0.001 *** 0.012322 | 0.012 ** 0.233432 | 0.233 ``` There must be a built-in function to produce this but I didn't achieve to find it. I search in the R documentation, Google and in SO without success. For the moment I use a hand-made function but I have to copy-paste it and call it each time I perform an analysis where I want to produce nice pvalue to output tables.