P value of corrcoef() is aways different !

1 visualización (últimos 30 días)
Damiano Capocci
Damiano Capocci el 13 de Mzo. de 2018
Comentada: the cyclist el 15 de Mzo. de 2018
Hi, in my tests i've introduced Matlab corrcoef(). But if i repeat this test i'm used to obtain different results for p value. The same thing if i cosider rand() function. So :
t=1:200000;
a=rand(1,200000);
[l,p]=corrcoef(a,t)
first time
l =
1.0000 0.0016
0.0016 1.0000
p =
1.0000 0.4742
0.4742 1.0000
second time
l =
1.0000 0.0025
0.0025 1.0000
p =
1.0000 0.2729
0.2729 1.0000
third time
l =
1.0000 -0.0000
-0.0000 1.0000
p =
1.0000 0.9941
0.9941 1.0000
what is the meaning of these results?
  2 comentarios
Jeff Miller
Jeff Miller el 13 de Mzo. de 2018
You seem to be generating new random values of 'a' for each run, so the correlations of those values to 't' (which are returned in 'l') naturally vary randomly as well. Since the correlations vary, so do their associated p values. What aspect of this is surprising to you?
Damiano Capocci
Damiano Capocci el 14 de Mzo. de 2018
Of course correlation varies but i expected a p value more or less the same in each generation and high because we are talking about rand(). I don't have a clear idea about the uniform distribution of p value itself. Ok if the generation is a stochastic variable p value will be also a stochastic variable but....

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
the cyclist el 14 de Mzo. de 2018
Editada: the cyclist el 14 de Mzo. de 2018

I'll one up you. I ran your code 10,000 times and calculated the P value for each run.

Here's the code:

NT = 10000;
pvec = nan(1,NT);
t=1:200000;
for n = 1:NT
      a=rand(1,200000);
      [~,p]=corrcoef(a,t);
      pvec(n) = p(1,2);
end
figure
histogram(pvec)
title(['Distribution of P values after ',sprintf('%d',NT),' trials'])
xlabel('P')
ylabel('Frequency of occurrence')

Here's resulting the distribution ...

Uniformly distributed P values (with a bit of sampling error). Exactly what I would expect. What were you expecting, and why?

  2 comentarios
Damiano Capocci
Damiano Capocci el 14 de Mzo. de 2018
I would expect a"decent" p value (or at least more or less the same) for each generation due to the fact we are testing rand() which is a good generator
the cyclist
the cyclist el 15 de Mzo. de 2018
A uniform distribution of the P value is exactly what I would expect from a good generator. The two distributions you are comparing are not correlated. Therefore, you would expect a P value of 0.05 or less to occur 5% of the time. You would expect a P value of 0.1 or less to occur 10% of the time.
This is exactly the result (within sampling error).

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by