Thread Subject: Why p-value is NaN or 0 using corrcoef ?

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Kuo-Hsien

Date: 13 Apr, 2009 20:08:01

Message: 1 of 6

I play around with [R,sig] = corrcoef(a,b)

Are there any pros can explain why I got "NaN" and "0" in P-value?

Thanks,
Michael

>> a = [1 2 3 4 5 6]';
>> b= [3 4 5 6 7 8]';
>> [R,sig] = corrcoef(a,b)
R =
    1.0000
sig =
   NaN
>> a = [1 2 3 4 5 6]';
>> b= [1 2 3 NaN 5 6]';
>> [R,sig] = corrcoef(a,b)
R =
    1.0000
sig =
   NaN
>> a= [1 2 4 NaN 5 6]';
>> b= [1 2 4 NaN 5 6]';
>> [R,sig] = corrcoef(a,b)
R =
    1.0000
sig =
     0

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Wayne King

Date: 13 Apr, 2009 22:57:01

Message: 2 of 6

Hi Kuo, what version of Matlab are you using? I'm using R2009a and I don't get that behavior. For your example:

a = [1 2 3 4 5 6]';
b= [3 4 5 6 7 8]';
[R,sig] = corrcoef(a,b)

R =

     1 1
     1 1


sig =

     1 0
     0 1

which is expected.

Wayne

"Kuo-Hsien" <mchangks@hotmail.com> wrote in message <gs0631$am3$1@fred.mathworks.com>...
> I play around with [R,sig] = corrcoef(a,b)
>
> Are there any pros can explain why I got "NaN" and "0" in P-value?
>
> Thanks,
> Michael
>
> >> a = [1 2 3 4 5 6]';
> >> b= [3 4 5 6 7 8]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> NaN
> >> a = [1 2 3 4 5 6]';
> >> b= [1 2 3 NaN 5 6]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> NaN
> >> a= [1 2 4 NaN 5 6]';
> >> b= [1 2 4 NaN 5 6]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> 0

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Wayne King

Date: 13 Apr, 2009 23:01:03

Message: 3 of 6

Also Kuo-Hsien, I'm surprised that corrcoef works with NaNs. If you supply the 'rows','complete' input, corrcoef() only works on rows without NaNs.

a= [1 2 4 NaN 5 6]';
b= [1 2 4 NaN 5 6]';
[R,sig] = corrcoef(a,b,'rows','complete')

R =

     1 1
     1 1


sig =

     1 0
     0 1

Hope that helps,
wayne

"Kuo-Hsien" <mchangks@hotmail.com> wrote in message <gs0631$am3$1@fred.mathworks.com>...
> I play around with [R,sig] = corrcoef(a,b)
>
> Are there any pros can explain why I got "NaN" and "0" in P-value?
>
> Thanks,
> Michael
>
> >> a = [1 2 3 4 5 6]';
> >> b= [3 4 5 6 7 8]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> NaN
> >> a = [1 2 3 4 5 6]';
> >> b= [1 2 3 NaN 5 6]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> NaN
> >> a= [1 2 4 NaN 5 6]';
> >> b= [1 2 4 NaN 5 6]';
> >> [R,sig] = corrcoef(a,b)
> R =
> 1.0000
> sig =
> 0

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Peter Perkins

Date: 14 Apr, 2009 14:56:14

Message: 4 of 6

Kuo-Hsien wrote:
> I play around with [R,sig] = corrcoef(a,b)

I recommend typing "which -all corrcoef". It appears that you are not using the corrcoef that ships with MATLAB, or at least not from anything like a recent version. The correct behavior would be this:

>> a = [1 2 3 4 5 6]';
>> b = [3 4 5 6 7 8]';
>> [R,sig] = corrcoef(a,b)
R =
     1 1
     1 1
sig =
     1 0
     0 1

and NaNs in your other cases, whcih should lead you to read this:

        'rows' Either 'all' (default) to use all rows, 'complete' to
                   use rows with no NaN values, or 'pairwise' to compute
                   R(i,j) using rows with no NaN values in column i or j.

in the help for corrcoef.

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Kuo-Hsien

Date: 14 Apr, 2009 18:06:02

Message: 5 of 6

"Wayne King" <wmkingty@gmail.com> wrote in message <gs0fvt$3u0$1@fred.mathworks.com>...
> Hi Kuo, what version of Matlab are you using? I'm using R2009a and I don't get that behavior.

Hi Wayne,
I did not use build-in function in Matlab. I'll take time to go through the original code.
Here is the download website: http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/

Those programs take care the NaN issue in Matlab.

Michael

Subject: Why p-value is NaN or 0 using corrcoef ?

From: Kuo-Hsien

Date: 14 Apr, 2009 18:07:01

Message: 6 of 6

Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message

Hi Peter,
I use alternative functions downloaded from http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/

Michael

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com