[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
covariance matrix
From: 
John W. Eaton 
Subject: 
covariance matrix 
Date: 
Mon, 19 Feb 2007 13:33:24 0500 
On 19Feb2007, baptiste AuguiĆ© wrote:
 I was trying to use a Matlab code (SCEMUA, Monte Carlo
 optimization), and I ended up correcting for all the
 incompatibilities I could understand:

  filenames and function names do not seem to be case sensitive in
 Matlab, whereas Octave would not find a filename with random Upper/
 lower case

  more concerning is this one: I have two vectors X and Y of same
 length, and using cov(X,Y) returns a scalar (same thing with cov
 (X',Y'))! The program  and myself after reading the documentation,
 expects a covariance matrix. Is that a bug?
 I changed this line to cov(X(:),Y(:)), which seems to work, but I
 would like to know whether this is normal?
The Matlab documentation says that if cov is given two matrix
arguments with the same number of elements, it computes
cov ([X(:), Y(:)])
(not quite what you have above). This expression will always compute
a 2x2 matrix. Octave's cov function does this if X and Y are
matrices:
If each row of X and Y is an observation and each column is a
variable, the (I, J)th entry of `cov (X, Y)' is the covariance
between the Ith variable in X and the Jth variable in Y.
and this will compute an NxN matrix with N == columns(X) == columns(Y).
I don't know why we have the difference. Has Matlab always behaved
this way? If so, then I'm surprised that you are the first to
notice. Hmm. Should we change Octave to be compatible? What will
this break? Should we try to preserve the old behavior? If so, how?
Hmm. It seems corrcoeff also has similar problems.
Will someone who understands what should be happening here please fix
cov and corrcoef and submit a patch?
Thanks,
jwe