Question: Calculating P-Values From Z-Scores
13
gravatar for Diana
8.8 years ago by
Diana840
Germany
Diana840 wrote:

Hi everyone!

Can anyone tell me how to calculate p-values from z-scores in R? Is this the correct way:

pvalue = pnorm(-abs(z))

Thanks!!!

R statistics • 104k views
ADD COMMENTlink modified 2.2 years ago by Kevin Blighe67k • written 8.8 years ago by Diana840
9
gravatar for Manu Prestat
8.8 years ago by
Manu Prestat4.0k
Lyon, France
Manu Prestat4.0k wrote:

your expression is good. Just don't forget, if relevant, to take into account the two-sided characteristic of the test, it would be then:

pvalue2sided=2*pnorm(-abs(z))

And, if you think you need to use the "apply" function, you might need to think about multitesting correction... but, I agree, this is another topic ;-)

ADD COMMENTlink written 8.8 years ago by Manu Prestat4.0k
1

Thanks! my test is one-sided as I am looking at enrichment only

ADD REPLYlink written 8.8 years ago by Diana840

In one-sided case, one is interested to find how extreme is the observation compared to random expectation. Therefore, it seems to be ill defined as it fails to take into account the sign of the z-scores:

pnorm(abs(0.5)) == pnorm(abs(-0.5))

 

ADD REPLYlink modified 5.7 years ago • written 5.7 years ago by Emre90
1
gravatar for Gjain
8.8 years ago by
Gjain5.5k
Munich, Germany
Gjain5.5k wrote:

Hi Diana,

I was explaining the same thing to my friend this morning.

here is a very nice and useful link: Calculating p Values

  1. Calculating a Single p Value From a Normal Distribution
  2. Calculating a Single p Value From a t Distribution
  3. Calculating Many p Values From a t Distribution

I hope this helps.

ADD COMMENTlink written 8.8 years ago by Gjain5.5k

You talked about that to your friends!! When are you on holidays Gjain?! :-P

ADD REPLYlink written 8.8 years ago by Manu Prestat4.0k

holidays?? I do not understand Manu ... One of my friend who works on Drosophila had the same query this morning and he asked me how to do that in excel and i told me him that I am more comfortable with R.

ADD REPLYlink written 8.8 years ago by Gjain5.5k

Hi Manu, its been sometime i have been on holiday...One of my friend who works on Drosophila had the same query this morning and he asked me how to do that in excel and i told me him that I am more comfortable with R ...

ADD REPLYlink written 8.8 years ago by Gjain5.5k

That is very informative. Thanks Gjain!

ADD REPLYlink written 8.8 years ago by Diana840
1
gravatar for Emre
5.7 years ago by
Emre90
United States
Emre90 wrote:

Based on the previous answers and comments, here is a function that considers both the one-sided case (two alternatives, observed scores are greater / z is positive: "+", observed scores are lower / z is negative: "-") and two sided case ("NULL").

convert.z.score<-function(z, one.sided=NULL) {
    if(is.null(one.sided)) {
        pval = pnorm(-abs(z));
        pval = 2 * pval
    } else if(one.sided=="-") {
        pval = pnorm(z);
    } else {
        pval = pnorm(-z);                                                                                 
    }
    return(pval);
}   
   
ADD COMMENTlink written 5.7 years ago by Emre90
1
gravatar for Kevin Blighe
2.2 years ago by
Kevin Blighe67k
Republic of Ireland
Kevin Blighe67k wrote:

Yet another [late] answer, in the context of GWAS: A: SNP dataset and Z Score

Kevin

ADD COMMENTlink written 2.2 years ago by Kevin Blighe67k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 924 users visited in the last hour