Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
n for each 'pairwise' correlation in corrcoef

Subject: n for each 'pairwise' correlation in corrcoef

From: Ulrik Nash

Date: 17 Feb, 2012 20:37:10

Message: 1 of 3

I need to extract the number of 'pairwise' observations on which each correlation in the correlation coefficient matrix is based. I have looked at the help document, but it doesn't look as if there is a parameter to extract n.

Any suggestions of a workaround?

Subject: n for each 'pairwise' correlation in corrcoef

From: Roger Stafford

Date: 17 Feb, 2012 21:40:24

Message: 2 of 3

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <jhmdpm$8v6$1@newscl01ah.mathworks.com>...
> I need to extract the number of 'pairwise' observations on which each correlation in the correlation coefficient matrix is based. I have looked at the help document, but it doesn't look as if there is a parameter to extract n.
>
> Any suggestions of a workaround?
- - - - - - - -
  Mathworks' documentation for 'corrcoef' states that "R = corrcoef(X) returns a matrix R of correlation coefficients calculated from an input matrix X whose rows are observations and whose columns are variables." So your 'n' is the number of rows in the matrix that was used to create the coefficient matrix. You cannot determine it from the coefficient matrix itself. You need to know how it was produced. The size of the coefficient matrix only tells you how many variables are involved.

Roger Stafford

Subject: n for each 'pairwise' correlation in corrcoef

From: Tom Lane

Date: 17 Feb, 2012 22:26:40

Message: 3 of 3

> I need to extract the number of 'pairwise' observations on which each
> correlation in the correlation coefficient matrix is based. I have looked
> at the help document, but it doesn't look as if there is a parameter to
> extract n.
>
> Any suggestions of a workaround?

I believe this will work. At least it seems to work in my example.

x = rand(10,4) % generate some data
x(6:6:end) = nan % sprinkle some NaNs into it
notnan = double(~isnan(x)) % find non-NaN values
notnan'*notnan % find number of matching non-NaN values

-- Tom

Tags for this Thread

No tags are associated with this thread.

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.

Contact us