Covariance - Maple Help

Student[Statistics]

 Covariance
 compute the covariance/covariance matrix

 Calling Sequence Covariance(X, Y, numeric_option, inert_option) Covariance(A, B, numeric_option) Covariance(M, numeric_option)

Parameters

 X - algebraic; random variable Y - algebraic; random variable A - B - M - numeric_option - (optional) equation of the form numeric=value where value is true or false inert_option - (optional) equation of the form inert=value where value is true or false

Description

 • The Covariance function computes the covariance of two data samples or the covariance of multiple data samples in a Matrix.
 • The first parameter can be a data sample (given as e.g. a Vector), a Matrix data sample, a random variable, or an algebraic expression involving random variables (see Student[Statistics][RandomVariable]).
 • If the option inert is not included or is specified to be inert=false, then the function will return the actual value of the result. If inert or inert=true is specified, then the function will return the formula of evaluating the actual value.

Computation

 • If a computation involves floating point data or the option numeric = true or numeric is specified, then the result is a floating point number. Otherwise, the result is an exact expression.

Examples

 > $\mathrm{with}\left(\mathrm{Student}\left[\mathrm{Statistics}\right]\right):$

Compute the covariance of two data sets.

 > $A≔\left[1,4,5,2\right]$
 ${A}{≔}\left[{1}{,}{4}{,}{5}{,}{2}\right]$ (1)
 > $B≔\left[2,\mathrm{\pi },\mathrm{sqrt}\left(2\right),4\right]$
 ${B}{≔}\left[{2}{,}{\mathrm{\pi }}{,}\sqrt{{2}}{,}{4}\right]$ (2)
 > $\mathrm{Covariance}\left(A,B\right)$
 ${-}\frac{{8}}{{3}}{+}\frac{{\mathrm{\pi }}}{{3}}{+}\frac{{2}{}\sqrt{{2}}}{{3}}$ (3)

If numeric is specified, then the result is a floating point.

 > $\mathrm{Covariance}\left(A,B,\mathrm{numeric}\right)$
 ${-0.676660073888006}$ (4)

Computations involving undefined values will eventually return an undefined result. Whenever data samples have at most one data point, the covariance is also undefined.

 > $U≔⟨\mathrm{seq}\left(57..77\right),\mathrm{undefined}⟩$
 ${U}{≔}\begin{array}{c}\left[\begin{array}{c}{57}\\ {58}\\ {59}\\ {60}\\ {61}\\ {62}\\ {63}\\ {64}\\ {65}\\ {66}\\ {⋮}\end{array}\right]\\ \hfill {\text{22 element Vector[column]}}\end{array}$ (5)
 > $V≔⟨\mathrm{seq}\left(\mathrm{sin}\left(i\right),i=57..77\right),\mathrm{undefined}⟩$
 ${V}{≔}\begin{array}{c}\left[\begin{array}{c}{\mathrm{sin}}{}\left({57}\right)\\ {\mathrm{sin}}{}\left({58}\right)\\ {\mathrm{sin}}{}\left({59}\right)\\ {\mathrm{sin}}{}\left({60}\right)\\ {\mathrm{sin}}{}\left({61}\right)\\ {\mathrm{sin}}{}\left({62}\right)\\ {\mathrm{sin}}{}\left({63}\right)\\ {\mathrm{sin}}{}\left({64}\right)\\ {\mathrm{sin}}{}\left({65}\right)\\ {\mathrm{sin}}{}\left({66}\right)\\ {⋮}\end{array}\right]\\ \hfill {\text{22 element Vector[column]}}\end{array}$ (6)
 > $\mathrm{Covariance}\left(U,V\right)$
 ${\mathrm{undefined}}$ (7)

Consider the following Matrix.

 > $M≔\mathrm{Matrix}\left(\left[\left[1,3,10\right],\left[3,4.1,2\right],\left[10,\mathrm{\pi },\mathrm{undefined}\right]\right]\right)$
 ${M}{≔}\left[\begin{array}{ccc}{1}& {3}& {10}\\ {3}& {4.1}& {2}\\ {10}& {\mathrm{\pi }}& {\mathrm{undefined}}\end{array}\right]$ (8)

Compute the covariance for this Matrix data sample. The entry at $i$th row and the $j$th column of the resulting Matrix stands for the covariance of the two data samples stored in the $i$th and $j$th columns of the input Matrix. Notice that $Float\left(\mathrm{undefined}\right)$ in the returned Matrix means the same as $\mathrm{undefined}$ but is generated from operations on the floating-point value in the original Matrix.

 > $\mathrm{Covariance}\left(M\right)$
 $\left[\begin{array}{ccc}\frac{{67}}{{3}}& {-0.539086257093885}& {\mathrm{undefined}}\\ {-0.539086257093885}& {0.358098853533942}& {Float}{}\left({\mathrm{undefined}}\right)\\ {\mathrm{undefined}}& {Float}{}\left({\mathrm{undefined}}\right)& {\mathrm{undefined}}\end{array}\right]$ (9)

Consider random variables with parameters $a$, $b$, $c$, $d$.

 > $X≔\mathrm{NormalRandomVariable}\left(a,b\right):$
 > $Y≔\mathrm{NormalRandomVariable}\left(c,d\right):$
 > $\mathrm{Covariance}\left(X+Y,X-Y\right)$
 ${{a}}^{{2}}{+}{{b}}^{{2}}{-}{{c}}^{{2}}{-}{{d}}^{{2}}{-}\left({a}{+}{c}\right){}\left({a}{-}{c}\right)$ (10)

Use the inert option.

 > $J≔\mathrm{PoissonRandomVariable}\left(\mathrm{\pi }\right):$
 > $K≔\mathrm{PoissonRandomVariable}\left(1\right):$
 > $\mathrm{Covariance}\left(JK,{K}^{2},\mathrm{inert}\right)$
 $\left({\sum }_{{\mathrm{_t0}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{\left({\sum }_{{\mathrm{_t}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\mathrm{_t}}{}{{\mathrm{_t0}}}^{{3}}{}{{\mathrm{\pi }}}^{{\mathrm{_t}}}{}{{ⅇ}}^{{-}{\mathrm{\pi }}}}{{\mathrm{_t}}{!}}\right){}{{ⅇ}}^{{-1}}}{{\mathrm{_t0}}{!}}\right){-}\left({\sum }_{{\mathrm{_t2}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{\left({\sum }_{{\mathrm{_t1}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{\mathrm{_t1}}{}{\mathrm{_t2}}{}{{\mathrm{\pi }}}^{{\mathrm{_t1}}}{}{{ⅇ}}^{{-}{\mathrm{\pi }}}}{{\mathrm{_t1}}{!}}\right){}{{ⅇ}}^{{-1}}}{{\mathrm{_t2}}{!}}\right){}\left({\sum }_{{\mathrm{_t3}}{=}{0}}^{{\mathrm{\infty }}}{}\frac{{{\mathrm{_t3}}}^{{2}}{}{{ⅇ}}^{{-1}}}{{\mathrm{_t3}}{!}}\right)$ (11)
 > $\mathrm{evalf}\left(\mathrm{Covariance}\left(JK,{K}^{2},\mathrm{inert}\right)\right)$
 ${9.424777962}$ (12)
 > $\mathrm{Covariance}\left(JK,{K}^{2},\mathrm{numeric}\right)$
 ${9.424777970}$ (13)

References

 Stuart, Alan, and Ord, Keith. Kendall's Advanced Theory of Statistics. 6th ed. London: Edward Arnold, 1998. Vol. 1: Distribution Theory.

Compatibility

 • The Student[Statistics][Covariance] command was introduced in Maple 18.
 • For more information on Maple 18 changes, see Updates in Maple 18.