Getting different p-values with corrcoef and regress functions
9 views (last 30 days)
Show older comments
Matthew_User14
on 21 Dec 2016
Commented: Matthew_User14
on 22 Dec 2016
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
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!