Strange behavior of "autocor" with zero variance

Sébastien Villemot sebastien.villemot at ens.fr
Wed Dec 10 04:57:01 CST 2008


Hi,

I have noticed a strange behaviour of autocor function, when given a
vector with zero variance. For example, with Octave 3.0.3:


octave> A = [ 1 2; 1 4; 1 6 ]
A =

   1   2
   1   4
   1   6

octave> autocor(A)
ans =

   0.00000   2.66667
   0.00000   0.00000
   0.00000  -1.33333


The values returned here are not autocorrelations, since they are not in
the [-1;1] interval. Actually, when one of the columns of the input
matrix has zero variance (like the first column of matrix A in this
example), then autocor returns auto-covariances (output of autocov).

I think this is not a desirable behaviour. It would probably be
preferable to return NaNs for the problematic columns, like:

       NaN   1.00000
       NaN   0.00000
       NaN  -0.50000

in the present example.

An attached patch implements this behaviour, by simply removing the test
over zero variances.

Another solution would be to issue an error message. However the NaN
solution seems more sensible to me.

Best,

Sébastien Villemot


-------------- next part --------------
A non-text attachment was scrubbed...
Name: autocor.patch
Type: text/x-patch
Size: 341 bytes
Desc: not available
Url : https://www-old.cae.wisc.edu/pipermail/bug-octave/attachments/20081210/0eb3e275/attachment.bin 


More information about the Bug-octave mailing list