Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a R function that convert p.value to significance code?

Tags:

r

p-value

summary displays significance code for p.values. Is there a R function that convert p.value to significance code? for example: 0.02 --> '*' and 0.005 --> '**'?

like image 526
mt1022 Avatar asked Dec 21 '16 12:12

mt1022


People also ask

How do you find the p-value in R software?

P−value=Pr[χ211≥20.66], as the P-value is the probability of getting your observed test statistic or worse in the null distribution. The formula above tells you that the P-value can be calculated by evaluating the CCDF of the χ211 random variable!

What is the significance of the number of stars?

The stars are only intended to flag levels of significance for 3 of the most commonly used levels. If a p-value is less than 0.05, it is flagged with one star (*). If a p-value is less than 0.01, it is flagged with 2 stars (**). If a p-value is less than 0.001, it is flagged with three stars (***).


2 Answers

Use symnum as shown below. ?symnum for more info.

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("***", "**", "*", ".", " "))

giving:

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

The above code is used in R itself in stats::printCoefmat (see ?printCoefmat) which is called from stats:::print.summary.lm . Note that it produces an object of class "noquote" and also provides a legend in the "legend" attribute.

like image 127
G. Grothendieck Avatar answered Sep 21 '22 19:09

G. Grothendieck


Tracking down the code used by summary, you can find the following in stats:::printCoefmat:

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

You can create your own function to do it, such as

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))

(Note the last value is just a space and not visible in the output)

like image 31
Calimo Avatar answered Sep 24 '22 19:09

Calimo