Is there a function to round p values?

In glm , lm and other functions in r that pvalues ​​produced are kindly printed. For instance:

 p found | p printed --------- | ----- 0.000032 | <0.001 *** 0.012322 | 0.012 ** 0.233432 | 0.233 

There must be a built-in function to create this function, but I could not find it. I am looking in the documentation of R, Google and in SO without success. At the moment, I use the manual function, but I need to copy it and call it every time I do an analysis, where I want to create a nice pvalue for displaying tables.

+6
source share
1 answer

(I answer my question, thanks to @James for the comments.)

Use format.pval with the correct 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 returns a character vector.

So that stars use only ifelse or record a function

 ifelse(pvalues < 0.05, "*", "") 
+4
source

Source: https://habr.com/ru/post/972027/


All Articles