# [R] Covariance matrix for GMM

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Feb 11 18:33:03 CET 2003

```"Feng Zhang" <f0z6305 at labs.tamu.edu> writes:

> There is no way to answer this question?
>
> even for writing the sample covariance matrix
> formulation for the data set [X, Y] where
> X(n observations) and Y (m observations) are from
> the class 1 and class 2 which both are
> multidimensional normal distribution?

It's hardly an R question, is it? However, the calculation is easy
enough in principle, at least in your original formulation: You need
the conditioning event C (the latent class) and then work out

E(X) = E(E(X|C)) = a1 * mu1 + a2 * mu2 = mu
V(X) = E(V(X|C)) + V(E(X|C))  = a1*V1 + a2*V2 + foo

with

foo = a1 * (mu1 - mu)^2 + a2 * (mu2 - mu)^2 = a1 * a2 * (mu1 - mu2)^2

where "x^2" really means x x' (==outer(x,x)) so that you get a matrix
of the proper dimensions. (And do check the math rather than believe
that I get it right 1st time...)

-p

>
> ----- Original Message -----
> From: "Feng Zhang" <f0z6305 at labs.tamu.edu>
> To: "R-Help" <r-help at stat.math.ethz.ch>
> Sent: Tuesday, February 11, 2003 12:11 AM
> Subject: [R] Covariance matrix for GMM
>
>
> > Hey, All
> >
> > Now I generate a data vector X (d-dimension column vector) from a Gaussian
> > Mixture Model (GMM).
> > That is, the pdf of vector X is
> > f(X) = a1*N(u1, Cov1) + a2*(u2, Cov2)
> > where a1+a2 = 1, N is multidimensional normal distribution, ui is the mean
> > vecotr, Covi is the covariance matrix, i=1, 2.
> >
> > So can I get the close forms of the mean and covariance matrix for the
> > random vector X?
> >
> > Thanks very much.
> >
> > Fred
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

```