Re: Rounding problem with corrcoef() ?
- From: "Pierre Bushel" <bushel@xxxxxxxxxxxxx>
- Date: Thu, 11 Oct 2007 20:20:27 +0000 (UTC)
Greg Heath <heath@xxxxxxxxxxxxxxxx> wrote in message
<1186088305.613189.242970@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Aug 2, 3:32 pm, "Gautam Vallabha"<gvall...@xxxxxxxxxxxxx> wrote:
message"Pawel Zdziarski" <pawel.zdziar...@xxxxxxxxxx> wrote in
times
news:f8t5mr$pit$1@xxxxxxxxxxxxxxxxxxxxx
I am calculating the correlation coefficient of two
completely random samples, and repating this many
the(say, 100k times). Then I look at the average of this
coefficient and get something around -0.0267. What is
shouldproblem? Obviously, the mean correlation coefficient
randombe 0. I have run this several times, getting this
negatively biased result each time.
========== MATLAB code I use for my simulation======
count = 100000;
for i=1:count
x = randn(2000,1);
y = randn(2000,1);
c=corrcoef(x,y);
res(i) = c(1,2);
end;
mean(res)
ans =
-0.0267
====================================================
what is going on??
(I also get biased means for autocorrelations of a
100000 before you runarray of normally distributed numbers).
count = 10000;
for i=1:count
x = randn(2000,1);
y = randn(2000,1);
c=corrcoef(x,y);
res(i) = c(1,2);
end;>> mean(res)
ans =
1.0266e-004>> std(res)
ans =
0.0222
Is it possible that your array 'res' is larger than
calculation of the mean?your loop, with values that are skewing your
In addition to initializing res, note that
stderr = std(res)/sqrt(count)
Hope this helps.
Greg
I've encounted a similar problem using corr(), corrceof()
and when I implement a function for Pearson correlation in
Matlab. It seems that Matlab is not interpreting an
operation that results in an answer of zero to be zero.
For instance, I'm correlating two vectors of data:
x1 = 0.3302 0.3302 0.3302 0.3302
y1 = 1.5318 1.4268 1.2248 1.0988
the mean of x1 = 0.3302
the mean of y1 = 1.3205
Since all the values of x1 are the same, the correlation
should result in a divide by zero error since the numerator
and the denominator of the correlation equation equals to
zero. Howver, this is how Matlab interprets the numerator
of the correlation equation:
1.0e-014 *
-0.1665 -0.1665 -0.1610 0.4885
resulting in a correlation of -0.7624. Which doesn't make
sense. Seems that Matlab is avoiding an interpretation of
a result that equals zero and giving it a very small number
(1.0e-014 * -0.1665 for instance).
When I do the calculation of the correlation by hand in
Excel and also use Excel's Correl function I get a divide
by zero error. This should be the true answer unless I'm
mis-informed. I'll report this to Matlab.
Pierre
.
- Follow-Ups:
- Re: Rounding problem with corrcoef() ?
- From: Steven Lord
- Re: Rounding problem with corrcoef() ?
- Prev by Date: Re: large slow for loop
- Next by Date: line colors in plot
- Previous by thread: Plot a line to a specific axis?
- Next by thread: Re: Rounding problem with corrcoef() ?
- Index(es):
Relevant Pages
|