是否有一个圆p值的函数?

jom*_*ler 8 r

glm,lm和其他功能其中产生p-值,有恳请打印.例如 :

p found   | p printed
--------- | -----
0.000032  | <0.001 ***
0.012322  |  0.012 **
0.233432  |  0.233 
Run Code Online (Sandbox Code Playgroud)

必须有一个内置的功能来产生这个,但我找不到它.我在R文档,Google和SO中搜索都没有成功.目前我使用的是手工制作的功能,但我必须复制粘贴并在每次执行分析时调用它,我想为输出表生成漂亮的pvalue.

jom*_*ler 5

(我回答我自己的问题,谢谢@James评论.)

使用format.pval正确的参数.digits并且eps是最重要的.

示例:

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"
Run Code Online (Sandbox Code Playgroud)

format.pval 返回一个字符向量.

让星星只使用ifelse或写一个函数

ifelse(pvalues < 0.05, "*", "")
Run Code Online (Sandbox Code Playgroud)