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 ...
![](/matlabcentral/answers/uploaded_files/108437/test.png)
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!