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:
Corrcoef(A,B) when Var(A)=0

Subject: Corrcoef(A,B) when Var(A)=0

From: laurie

Date: 4 May, 2012 16:04:13

Message: 1 of 6

Hi,

I would like to get the correlations between one vector B and another, constant, vector A.

So the constant vector A is so that Var(A)=0 and corrcoef gives either NaNs or 0 (sometimes, but I don't know why ?).

Is there a workaround this ? I don't see why a correlation coefficient would be impossible mathematically when one of the two variance is zero ?

For example can I add a little noise without alterring my data to much ?

Thank you very much

Subject: Corrcoef(A,B) when Var(A)=0

From: dpb

Date: 4 May, 2012 16:24:50

Message: 2 of 6

On 5/4/2012 11:04 AM, laurie wrote:
> Hi,
>
> I would like to get the correlations between one vector B and another,
> constant, vector A.
...

What would it mean if you got it?

Perhaps you want an autocorrelation?

What's the _end_ objective (that is, what use of the result are you
trying to make, not just the computation itself)?

--

Subject: Corrcoef(A,B) when Var(A)=0

From: laurie

Date: 4 May, 2012 17:01:13

Message: 3 of 6

no i don't think this is autocorrelation : A is different from B, but Var(A)=0

if you plotted the vectors along each observation, A would be an horizontal line, but not B.

the end objective is to have a measure of "ordered distance" between A and B.

thank you !

dpb <none@non.net> wrote in message <jo0vse$ij5$1@speranza.aioe.org>...
> On 5/4/2012 11:04 AM, laurie wrote:
> > Hi,
> >
> > I would like to get the correlations between one vector B and another,
> > constant, vector A.
> ...
>
> What would it mean if you got it?
>
> Perhaps you want an autocorrelation?
>
> What's the _end_ objective (that is, what use of the result are you
> trying to make, not just the computation itself)?
>
> --

Subject: Corrcoef(A,B) when Var(A)=0

From: dpb

Date: 4 May, 2012 17:38:07

Message: 4 of 6

On 5/4/2012 12:01 PM, laurie wrote:

...[top posting repaired; please don't do that--hard follow conversation
makes]...

...
 > no i don't think this is autocorrelation : A is different from B, but
 > Var(A)=0
 >
 > if you plotted the vectors along each observation, A would be an
 > horizontal line, but not B.
 >
> the end objective is to have a measure of "ordered distance" between
> A and B.

That would simply be abs(A-B) or perhaps sqrt((A-B).^2))

Play around w/ various values of Z in the following and see if that
doesn't show what you're asking for...

 >> Z=0.5;
 >> x=1:10;y=exp(-x/10);
 >> plot(x,y)
 >> x=0:10;y=exp(-x/10);
 >> plot(x,y)
 >> c=sqrt((y-Z).^2);
 >> plot(x,y,x,c)
 >>

--

Subject: Corrcoef(A,B) when Var(A)=0

From: Peter Perkins

Date: 4 May, 2012 17:53:59

Message: 5 of 6

Laurie, consider these two vectors:

x = [1 2 3 4 5]
y0 = [0 0 0 0 0]

If you plug those into the computational definition of the linear
correlation corr(x,y0), you will find that it's 0/0, which in floating
point is represented as NaN. So instead consider

y = [1 2 3 4 5]

Since computing corr(x,y0) directly ended up as 0/0, you might think to
compute it as the limit of corr(x,alpha*y) as alpha goes to zero. Now
corr(x,alpha*y) is 1 for alpha > 0, so the limit from that side is 1,
but for alpha < 1 the limit is -1. And if you approach y0 some other
way (using y1 = [1 2 3 2 1], say), you can make the limit anything in
[-1,1]. So the limit is path dependent. And since there's no way for
the corrcoef function to "know" which of the infinite possibilities you
want, the result is NaN, meaning, "it might be any one of many numbers."

Hope this helps.


On 5/4/2012 12:04 PM, laurie wrote:
> Hi,
>
> I would like to get the correlations between one vector B and another,
> constant, vector A.
>
> So the constant vector A is so that Var(A)=0 and corrcoef gives either
> NaNs or 0 (sometimes, but I don't know why ?).
>
> Is there a workaround this ? I don't see why a correlation coefficient
> would be impossible mathematically when one of the two variance is zero ?
>
> For example can I add a little noise without alterring my data to much ?
>
> Thank you very much

Subject: Corrcoef(A,B) when Var(A)=0

From: Roger Stafford

Date: 4 May, 2012 18:01:23

Message: 6 of 6

"laurie" wrote in message <jo0uls$gql$1@newscl01ah.mathworks.com>...
> Hi,
>
> I would like to get the correlations between one vector B and another, constant, vector A.
>
> So the constant vector A is so that Var(A)=0 and corrcoef gives either NaNs or 0 (sometimes, but I don't know why ?).
>
> Is there a workaround this ? I don't see why a correlation coefficient would be impossible mathematically when one of the two variance is zero ?
>
> For example can I add a little noise without alterring my data to much ?
>
> Thank you very much
- - - - - - - - - - - -
  Trying to find correlation with a constant quantity is an oxymoron. Covariance involving a constant must always be zero. Correlation is a method of normalizing a covariance by dividing it by the standard deviation of the two variables. It becomes meaningless when one of the quantities doesn't vary. It's like asking how well a dieter's daily weight variations correlate with that of his favorite chair. There could be a correlation if only the chair would lose weight. There is no way of knowing. It is just as indeterminate as dividing zero by zero and deserves the same response in matlab.

Roger Stafford

Tags for 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