P value of corrcoef() is aways different !
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Jeff Miller
2018-3-13
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?
采纳的回答
the cyclist
2018-3-14
编辑:the cyclist
2018-3-14
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 个评论
the cyclist
2018-3-15
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).
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!