[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: covariance matrix
From: |
John W. Eaton |
Subject: |
Re: covariance matrix |
Date: |
Tue, 20 Feb 2007 01:40:11 -0500 |
On 19-Feb-2007, Vic Norton wrote:
| # The Octave cov function is incorrect.
| # Here is a definition with an example and references.
|
| # Example
| X = [
| 3 5 3 7 1 5
| 2 1 4 2 2 1
| 1 5 1 1 7 2
| ];
|
| Y = [
| 1 1 4 2 6 1
| 3 1 2 2 1 1
| 2 1 3 1 1 5
| ];
|
| x = X(:, 2); y = Y(:, 4);
|
| # straight from the definition below
| cov_xy = mean((x - ones(rows(x), 1) * mean(x)) .* (y - ones(rows(y), 1) *
mean(y)))
|
| # the covariance matrix
| n = rows(x); # = rows(y) also
| Xdev = X - ones(n, 1) * mean(X); # deviations from the mean
| Ydev = Y - ones(n, 1) * mean(Y); # deviations from the mean
| cov_matrix = Xdev' * (Ydev/n)
|
| # References
| # <http://planetmath.org/encyclopedia/Covariance.html>
| # <http://planetmath.org/encyclopedia/CovarianceMatrix.html>
| #
| # cov(x, y) = E[(x - E(x))(y - E(y))].
| # The (i, j) entry of cov(X, Y) sould be cov(X(:, i), Y(:, j)).
OK, thanks, but I don't have time now to fix these problems myself, so
I will have to wait for someone to submit a working patch.
Thanks,
jwe