是否有一个R函数将p.value转换为重要性代码?

时间:2016-12-21 12:37:30

标签: r p-value

wp_localize_script显示p.values的重要性代码。是否有一个R函数将p.value转换为重要性代码?例如:0.02 - > summary和0.005 - > '*'

2 个答案:

答案 0 :(得分:8)

试试这个。没有使用包裹。请尝试?symnum了解详情。

p.values <- c(9.5e-15, 0.02)
Signif <- symnum(p.values, corr = FALSE, na = FALSE, cutpoints = c(0, 
    0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", "**", "*", ".", " "))

,并提供:

> str(Signif)
Class 'noquote'  atomic [1:2] *** *
  ..- attr(*, "legend")= chr "0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1"

以上代码用于stats::printCoefmat中的R本身(try ?printCoefmat),该stats:::print.summary.lm"noquote"调用。请注意,它会生成类"legend"的对象,并在CREATE TABLE superheoes ( sh_name VARCHAR2(20) ); CREATE OR REPLACE TRIGGER superheroes_audit BEFORE INSERT OR DELETE OR UPDATE ON superheoes FOR EACH ROW ENABLE DECLARE v_user VARCHAR2(30); v_date VARCHAR2(30); BEGIN SELECT user,TO_CHAR(sysdate,'DD/MON/YYYY HH24:MI:SS') INTO v_user, v_date FROM dual; IF INSERTING THEN INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation) VALUES (:NEW.sh_name, NULL, v_user, v_date, 'Insert'); ELSIF DELETING THEN INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation) VALUES (NULL, :OLD.sh_name, v_user, v_date, 'Delete'); ELSIF UPDATING THEN INSERT INTO sh_audit (new_name, old_name, user_name, entry_date, operation) VALUES ( :NEW.sh_name, :OLD.sh_name, v_user, v_date, 'Update'); END IF; END; / 属性中提供图例。

答案 1 :(得分:4)

追踪summary使用的代码,您可以在stats:::printCoefmat中找到以下内容:

Signif <- symnum(pv, corr = FALSE, na = FALSE, 
                 cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), 
                 symbols = c("***", "**", "*", ".", " "))

您可以创建自己的功能,例如

signif.num <- function(x) {
    symnum(x, corr = FALSE, na = FALSE, legend = FALSE,
           cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), 
           symbols = c("***", "**", "*", ".", " "))
}
signif.num(c(1e-8, 0.01, 0.05, 0.1, 0.2))

(注意最后一个值只是一个空格,在输出中不可见)