I have a large matrix 1xN containing z values. I would like to know how to turn these z scores to p values using normcdf function?
How to obtain p values both for one-tailed and two-tailed p values using normcdf?
Many thanks in advance!

 Respuesta aceptada

Star Strider
Star Strider el 7 de Dic. de 2016

1 voto

If I remember correctly, the probability of a one-tailed test is twice the probability of a two-tailed test, so:
p_one = 2*normcdf(z_vector);
p_two = normcdf(z_vector);

11 comentarios

lou
lou el 7 de Dic. de 2016
Editada: lou el 7 de Dic. de 2016
Are these p_one & p_two the p values or they need to be subtracted from 1?
for example
p_one = 2*normcdf(z_vector);
p_value=1-p_one
Star Strider
Star Strider el 7 de Dic. de 2016
If you want the complementary values, use the 'upper' option:
p_one = 2*normcdf(z_vector, 'upper');
p_two = normcdf(z_vector, 'upper');
lou
lou el 8 de Dic. de 2016
Unfortunately this does not work - I get this error after command
p_one = 2*normcdf(z_values, 'upper');
Error using normcdf (line 56)
Non-scalar arguments must match in size.
Star Strider
Star Strider el 8 de Dic. de 2016
I cannot reproduce that error, given the information you have supplied. There may be version differences. I’m using R2016b.
Try one of these to see if it works for you:
N = 5;
z_vector = randn(1,N); % Create Data
p_one = 2*normcdf(-abs(z_vector));
p_two = normcdf(-abs(z_vector));
p_one_c = 1-2*normcdf(-abs(z_vector));
p_two_c = 1-normcdf(-abs(z_vector));
The last two are complementary to the first two.
lou
lou el 8 de Dic. de 2016
This works! thank you!
Star Strider
Star Strider el 8 de Dic. de 2016
My pleasure!
Jos (10584)
Jos (10584) el 9 de Dic. de 2016
Be aware that can have a left-tail one-sided z-test and a right-tail one-sided test, so simply taking the absolute value is inappropriate:
p_left = normcdf(zval)
p_right = normcdf(-zval)
Star Strider
Star Strider el 9 de Dic. de 2016
I agree, but that wasn’t the Question here.
lou
lou el 30 de Mzo. de 2017
why for right-sided p-values I need to take "-zval"? I mean why do I need to insert the negative z values?
Star Strider
Star Strider el 30 de Mzo. de 2017
It depends upon the hypothesis you are testing.
Noah
Noah el 23 de Jul. de 2021
Note that the accepted answer is backwards, unless you mean something strange by your hypothesis. The probability of one-tailed test is HALF the probability of a two-tailed test. The area under a bell curve on one side is half the area on both sides.
p_oneTailed = normcdf(z_vector);
p_twoTailed = 2*normcdf(z_vector);

Iniciar sesión para comentar.

Más respuestas (1)

Ziwei Liu
Ziwei Liu el 18 de Ag. de 2023

1 voto

Two-tailed p value should actually be 2 * (1 - normcdf(z)).
normcdf(z) gives the area under curve on the left side of z. This is not p value. One-tailed p value should be the area on the right side, which is (1 - normcdf(z)).Two-tailed p value should be the double of that.
You can use the arrayfun function to compute p value for each entry in your z score matrix. i.e. p = arrayfun(@(x) 2*(1-normcdf(x)), ZScoreMatrix).

1 comentario

For this to work with negative z scores, you also need to take the absolute value of z:
z = [-2.58 -1.96 -1.65 0 1.65 1.96 2.58]; % vector of z scores
p = 2 * (1 - normcdf(abs(z))); % vector of associated pvalues
disp([z' p'])
-2.5800 0.0099 -1.9600 0.0500 -1.6500 0.0989 0 1.0000 1.6500 0.0989 1.9600 0.0500 2.5800 0.0099

Iniciar sesión para comentar.

Etiquetas

Preguntada:

lou
el 7 de Dic. de 2016

Comentada:

el 28 de Feb. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by