Calculating P-Values From Z-Scores
4
13
Entering edit mode
12.5 years ago
Diana ▴ 910

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

statistics r • 124k views
9
Entering edit mode
12.5 years ago

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

1
Entering edit mode

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

0
Entering edit mode

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

1
Entering edit mode
12.5 years ago
Gjain 5.8k

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.

0
Entering edit mode

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

0
Entering edit mode

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.

0
Entering edit mode

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

0
Entering edit mode

That is very informative. Thanks Gjain!

1
Entering edit mode
9.4 years ago
Emre ▴ 110

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

1
Entering edit mode
5.9 years ago

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

Kevin