STAT 3690 Lecture 04
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
STAT 3690 Lecture 04
2022
Covariance matrix of random vectors x and Y
● Random p-vector X = [Xl , . . . , Xp ]T and q-vector Y = [Yl , . . . , Yq ]T
● Expectations of random vectors/matrices are taken entry-wisely, e.g., µx = E(X) = [E(Xl ), . . . , E(Xp )]T . 一 E(AX + a) = AE(X) + a as long as both AX + a and BY + b exist.
● Covariance matrix: the (i, j)-entry is the covariance between the i-th entry of X and j-th entry of Y
一 Σxv = [cov(Xi , Yj )]p×q = E[{X 一 E(X)}{Y 一 E(Y)}T ] = E(XYT ) 一 µx µv(T)
一 ΣAx+α ,Bv+b = AΣxv BT as long as both AX + a and BY + b exist.
一 Σxx ≥ 0, i.e., Σxx is positive semi-definite
● Exercise: Verify the properties of covariance matrix
1. ΣAx+α ,Bv+b = AΣxv BT as long as both AX + a and BY + b exist.
2. Σxx ≥ 0.
Sample covariance matrix
● (Xi , Yi ) (X, Y), i = 1, . . . , n
● Sample means: = n- l Xi and = n- l Yi
● Sample covariance matrix:
n
n 一 1 i=l
一 Unbiasedness: E(Sxv ) = Σxv
一 SAx+α ,Bv+b = ASxv BT as long as both AX + a and BY + b exist.
一 Sxx ≥ 0
一 Implementation in R : cov() (or var() if X = Y)
● Exercise: Verify the properties of sample covariance matrix
1. E(Sxv ) = Σxv . (Hint: (n 一 1)Sxv = Xi Yi(T) 一 nT = Xi Yi(T) 一 n- l i,j Xi Yj(T))
2. SAx+α ,Bv+b = ASxv BT as long as both AX + a and BY + b exist.
3. Sxx ≥ 0.
Method of moments (MM) estimators for mean vectors and covariance matrices
● MM imposes no specific distribution on X or Y
● Steps
1. Equate raw moments to their sample counterparts:
,.E(X) = .E(Y) = ..E(XYT ) = n- l
i XiYi(T)
,
.
兮 .
.
µx =
µv =
Σxv + µx µv(T) = n- l
i XiYi(T)
2. Solve the above equations w.r.t. µx , µv and Σxv and obtain estimators
,.x =
. v =
..xv = n- l i XiYi(T) 一 T = n- l (n 一 1)Sxv
Computing means and covariance matrices by ←
options(digits = 4)
install.packages(c ( 'rgl ' , 'MASS '))
set.seed(1)
# parameters
n = 1000
Mu = 1 :3
Sigma = matrix(c (1 , .5 , .5 ,
.5 , 3 , .5 ,
.5 , .5 , 7),
nrow = 3 , ncol = 3)
# check the eligibility of Sigma and review the spectral decomposition
isSymmetric.matrix(Sigma)
(eigen.Sig = eigen(Sigma))
(Lambda = diag(eigen.Sig$values))
(U = eigen.Sig$vectors)
(U %*% t (U))
(U %*% Lambda %*% t (U))
# generation of samples
samples = MASS::mvrnorm(n, Mu, Sigma)
# reference for various scatterplots https://www.statmethods.net/graphs/scatterplot.html
# scatterplots for paired RVs
pairs(samples)
# (spinning) 3D scatterplot
rgl ::plot3d(samples[,1], samples[,2], samples[,3], col = "red" , size = 6)
# sample mean vector for [V1,V2,V3]ˆT
(muHat = apply(samples, 2 , mean))
(muHat = colMeans (samples))
# sample covariance matrix for [V1,V2,V3]ˆT
(S = var (samples))
(S = cov (samples))
# sample covariance matrix for V1 & [V2,V3]ˆT
cov (samples[, 1], samples[,2:3])
# sample covariance matrix for V2 & [V3,V1]ˆT
cov (samples[,2], samples[,c (3 , 1)])
2022-03-17