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

Covariance

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

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=18 HEIGHT=15 and $M$% WIDTH=21 HEIGHT=15 respectively, the output will be a $(N-1)\times(M-1)$% WIDTH=134 HEIGHT=31 rank tensor, where the $(i,j)$% WIDTH=36 HEIGHT=31 element is the covariance of the $i$% WIDTH=9 HEIGHT=15 -th slice of the first argument along the named dimension, and the $j$% WIDTH=11 HEIGHT=31 -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=13 HEIGHT=14 is supplied to the covariance, then the result is equivalent to cov$(x,x)$% WIDTH=41 HEIGHT=31 , ie each slice is covaried with each other slice.

The formula for covariance between stochastic variables $x$% WIDTH=13 HEIGHT=14 and $y$% WIDTH=12 HEIGHT=29 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=421 HEIGHT=48


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