next up previous contents
Next: Correlation coefficient Up: Statistical Operations Previous: Histogram   Contents

Covariance

\includegraphics[height=10mm]{images/covariance}% WIDTH=48 HEIGHT=45

The operator can be placed on the canvas in two ways:

Computes the covariance of two tensors along named dimension. If the inputs are of rank $N$% WIDTH=29 HEIGHT=23 and $M$% WIDTH=34 HEIGHT=23 respectively, the output will be a $(N-1)\times(M-1)$% WIDTH=267 HEIGHT=34 rank tensor, where the $(i,j)$% WIDTH=61 HEIGHT=34 element is the covariance of the $i$% WIDTH=9 HEIGHT=23 -th slice of the first argument along the named dimension, and the $j$% WIDTH=15 HEIGHT=29 -th slice along the named dimension. As such, it is conformant with the definition of cov function in Octave, but not with the equivalently named function in Matlab: quoteCompatibility Note:: Octave always treats rows of X and Y as multivariate random variables. For two inputs, however, MATLAB treats X and Y as two univariate distributions regardless of their shapes, and will calculate covariance whenever the number of elements in X and Y are equal. This will result in a 2x2 matrix. Code relying on MATLAB's definition will need to be changed when running in Octave. If only a single argument $x$% WIDTH=17 HEIGHT=16 is supplied to the covariance, then the result is equivalent to cov$(x,x)$% WIDTH=72 HEIGHT=34 , ie each slice is covaried with each other slice.

The formula for covariance between stochastic variables $x$% WIDTH=17 HEIGHT=16 and $y$% WIDTH=16 HEIGHT=22 is \begin{displaymath}
\mathrm{cov}(x,y)=\frac{1}{N-1}\sum_{i}(x_{i}-\langle x\rangle)(y_{i}-\langle y\rangle)
\end{displaymath}% WIDTH=593 HEIGHT=85