MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Computing a covariance matrix

In article <erme5t$i8b$1 at>,
 eleutheroskaiwraios at wrote:

> I was looking on how to compute a covariance matrix given a set of
> measurements and I was utterly frustrated having to jump from one
> discussion group to another and harvesting the web through maths
> websites having to cope with all sorts of notations. 

I would have thought that you would find the required 
derivation/computation in _many_ places.

> I managed to find a nice example on how to derive a covariance matrix and decided to
> share it with you :)
> Go to:
> "How the stat packages compute a correlation matrix"
> It should be quite easy to understand how it is done. It even shows
> you how to standardise the matrix at the end.
> NOTE: this is cross-posted at:
> sci.math
> sci.stat.math
> comp.soft-sys.math.mathematica
> alt.math.undergrad

As far as I can see, you have only posted this message to MathGroup 
(comp.soft-sys.math.mathematica), not to the other groups.

Also, I'm not sure what this has to do with Mathematica specificially? I 
note that CovarianceMatrix, which computes VCV in your notation, is in 
the package

  << Statistics`MultiDescriptiveStatistics`

Here is a direct Mathematica implementation of your example:

 X = {{1, 2, 3}, {2, 3, 4}, {1, 2, 3}, {5, 4, 3}, {4, 4, 4}}

 x = Transpose[X] - Mean[X]

 SSCP = x . Transpose[x]

 VCV = SSCP/(Length[X] - 1)

 s = Sqrt[Variance /@ x]

 correlationmatrix = VCV/Outer[Times, s, s]


Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    

  • Prev by Date: Re: Question: Plots via command-line using front-end fonts?
  • Next by Date: Re: Fw: 2
  • Previous by thread: Computing a covariance matrix
  • Next by thread: Re: Computing a covariance matrix