2

I need to check two conditions:

  1. $E[X]\stackrel{?}{=}\mu$,
  2. $E[(X-\mu)(X-\mu)^{\top}]\stackrel{?}{=}\Sigma$.

Here $X$ is generated (output) data, $\mu$ is the mean vector, $\Sigma$ is the covariance matrix. $\mu$, $\Sigma$ are input data.

For the test the first condition I wrote the code in R:

all( abs(apply(X, 1, mean) - mu) < .Machine$double.eps)
# [1] TRUE

For the test the second condition I wrote the code in R with Error:

SS <- mean((X - mu) %*% t(X - mu)) # Error in X - mu : non-conformable arrays

Also I have tried

XX <- apply(X, 2, X- mu); 
all(abs(cov(XX)-Sigma) <Machine$double.eps)

Question. How to check the second condition?

The input and output data are below.

> dput(X)
structure(c(0.0613307578354561, 0.0793852352305158, 0.106501868600655, 
0.0613307578354561, 0.0793852352305158, 0.106501868600655, 0.0613307578354561, 
0.0793852352305158, 0.106501868600655, 0.0613307578354561, 0.0793852352305158, 
0.106501868600655, 0.0613307578354561, 0.0793852352305158, 0.106501868600655, 
-0.0580547578354561, -0.0677532352305158, -0.102897868600655, 
-0.0580547578354561, -0.0677532352305158, -0.102897868600655, 
-0.0580547578354561, -0.0677532352305158, -0.102897868600655, 
-0.0580547578354561, -0.0677532352305158, -0.102897868600655, 
-0.0580547578354561, -0.0677532352305158, -0.102897868600655, 
0.001638, 0.005816, 0.001802, -0.0632519844767603, -0.0984530938115999, 
-0.0957267222612055, 0.0665279844767603, 0.1100850938116, 0.0993307222612055
), .Dim = c(3L, 13L))
> dput(mu)
structure(c(0.001638, 0.005816, 0.001802), .Dim = c(3L, 1L))
> dput(Sigma)
structure(c(0.00164362748495062, 0.00127550132157053, 0.00109066033003292, 
0.00127550132157053, 0.00296017401626616, 0.00168755721411896, 
0.00109066033003292, 0.00168755721411896, 0.00280257641141517
), .Dim = c(3L, 3L))
Nick
  • 1,086
  • 7
  • 21

1 Answers1

2

You just need to define a distance between covariance matrices, which is what you basically did for the mean, i.e. using abs. You can choose from commonly used matrix norms listed here, e.g. Frobenius, $L_2$ etc. You also need to pick a reasonable threshold based on each of these norms. Here is another good topic on CV.

gunes
  • 288
  • 3
  • 11