我需要检查两个条件:
- $E[X]\stackrel{?}{=}\mu$ ,
- $E[(X-\mu)(X-\mu)^{\top}]\stackrel{?}{=}\Sigma$。
这里$X$是生成(输出)数据,$\mu$是均值向量,$\Sigma$是协方差矩阵。$\mu$ , $\Sigma$是输入数据。
对于测试的第一个条件,我在 R 中编写了代码:
all( abs(apply(X, 1, mean) - mu) < .Machine$double.eps)
# [1] TRUE
为了测试第二个条件,我在 R 中编写了带有错误的代码:
SS <- mean((X - mu) %*% t(X - mu)) # Error in X - mu : non-conformable arrays
我也试过
XX <- apply(X, 2, X- mu);
all(abs(cov(XX)-Sigma) <Machine$double.eps)
问题。如何检查第二个条件?
输入和输出数据如下。
> 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))