Getting different p-values with corrcoef and regress functions

9 views (last 30 days)
I'm having trouble understanding the differences between the p-values returned from corrcoef and regress. I have a large data set with variables in the columns and instances in the rows. I determine which variables have significant relationships using corrcoef like this:
[R,P,RLO,RUP] = corrcoef(binaryDataXlx,'rows','pairwise');
[sigx,sigy] = find(P < 0.05);
sig = [sigx sigy];
Then, for those that are significant, I remove the NaN entries and use regress to find the coefficients of linear regression:
[B,BINT,Rregress,RINT,STATS] = regress(tempPruned(:,2),Xregress,0.05);
My main problem is that the p-values from corrcoef do not agree with the p-values from STATS(3). Is this because corrcoef compares all relationships, not just linear ones? And if so, why are the p-values from regress sometimes smaller than those from corrcoef?
Thanks you so much!!
Matthew

Accepted Answer

the cyclist
the cyclist on 21 Dec 2016
This is difficult to understand without the seeing the code and data.
Here is a simple example with one predictor, in which the P-value does agree:
rng default
x = (0:0.05:1)';
y = x + 8*rand(size(x,1),1);
figure
plot(x,y,'.')
[b,bint,r,rint,stats] = regress(y,[ones(size(x)) x])
stats(3)
[r,p] = corrcoef(y,x)
Maybe you could craft a simple example showing your problem? Specifically, if you have more than one predictor, I'm not sure how you are comparing the single P-value of the F-statistic of the regression with the many P-values of corrcoef.
  1 Comment
Matthew_User14
Matthew_User14 on 22 Dec 2016
Thank you very much for the kind reply. In the process of setting up an example, I found the error in my code. Now the p-values agree exactly. I was thinking that p-values of corrcoef and regress were testing different hypotheses, but it seems like that's not the case. Anyway, thank you again and sorry for the trouble!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!