Details of Weighted Least Square Empirical Covariance
Source:vignettes/empirical_wls.Rmd
empirical_wls.Rmd
Weighted Least Square (WLS) Empirical Covariance
Following the notation we have without weights, Bell and McCaffrey (2002) and Pustejovsky and Tipton (2018) suggest
v=sC⊤(X⊤WX)−1∑iX⊤iWiAiϵiϵ⊤iAiWiXi(X⊤WX)−1C
where Ai takes Ii, (Ii−Hii)−12, or (Ii−Hii)−1 is unchanged, but H is changed
H=X(X⊤WX)−1X⊤W
For the degrees of freedom, we have
Gij=g⊤iΦgj
where
gi=s12(I−H)⊤iAiWiXi(X⊤X)−1C
Difference of Implementations
Comparing the previous section with our implementation, we can find
out the differences. Since they have nearly the same symbols, to
differentiate the different part, we use subscript 1 to denote the implementation suggested
by Bell and McCaffrey (2002) and Pustejovsky and Tipton (2018), and use 2 to denote the our implementation of
covariance estimator in mmrm
, we have
v1=sC⊤(X⊤WX)−1∑iX⊤iWiA1,iϵiϵ⊤iA1,iWiXi(X⊤WX)−1C
v2=sC⊤(X⊤WX)−1∑iX⊤iLiA2,iL⊤iϵiϵ⊤iLiA2,iL⊤iXi(X⊤WX)−1C
Here we will prove that they are identical.
Proof of Identity
Proof for Covariance Estimator
First of all, we assume that all Ai matrix, in any form, are positive-definite. Comparing v1 and v2, we see that the different part is
M1,d,i=WiA1,i and M2,d,i=LiA2,iL⊤i
Substitute H1 and H2 with its expression, we have
M1,d,i=Wi(Ii−Xi(X⊤WX)−1X⊤iWi)d
M2,d,i=Li(Ii−L⊤iXi(X⊤WX)−1X⊤iLi)dL⊤i
Where d takes 0, −1/2 and −1 respectively.
Apparently, if d=0, these two are identical because Wi=LiL⊤i.
When d=−1, we have
M2,−1,i=Li(Ii−L⊤iXi(X⊤WX)−1X⊤iLi)−1L⊤i=(L−1i)−1(Ii−L⊤iXi(X⊤WX)−1X⊤iLi)−1((L⊤i)−1)−1=[((L⊤i)−1)(Ii−L⊤iXi(X⊤WX)−1X⊤iLi)(L−1i)]−1=[(L⊤i)−1L−1i−Xi(X⊤WX)−1X⊤i]−1=(W−1i−Xi(X⊤WX)−1X⊤i)−1
M1,−1,i=Wi(Ii−Xi(X⊤WX)−1X⊤iWi)−1=(W−1i)−1(Ii−Xi(X⊤WX)−1X⊤iWi)−1=[(Ii−Xi(X⊤WX)−1X⊤iWi)((W−1i))]−1=(W−1i−Xi(X⊤WX)−1X⊤i)−1
Obviously, M2,−1,i=M1,−1,i, and use the following notation
M2,−1,i=LiB2,iL⊤i
M1,−1,i=WiB1,i
we have
B1,i=W−1iLiB2,iL⊤i=(L⊤i)−1B2,iL⊤i
When d=−1/2, we have the following
M2,−1/2,i=Li(Ii−L⊤iXi(X⊤WX)−1X⊤iLi)−1/2L⊤i=LiB1/22,iL⊤i
M1,−1/2,i=Wi(Ii−Xi(X⊤WX)−1X⊤iWi)−1/2=WiB1/21,i
Apparently if B1/21,i≠(L⊤i)−1B1/22,iL⊤i, we should also have B1/21,iB1/21,i≠(L⊤i)−1B1/22,iL⊤i(L⊤i)−1B1/22,iL⊤i
leading to
B1,i≠(L⊤i)−1B2,iL⊤i
which is contradictory with our previous result. Thus, these covariance estimator are identical.
Proof for Degrees of Freedom
To prove G1,ij=g⊤1,iΦg1,j and G2,ij=g⊤2,ig2,j are identical, we only need to prove that
L−1g1,i=gmmrmi
where Φ=W−1 according to our previous expression.
We first expand L−1g1,i and gmmrmi
L−1g1,i=L−1(I−X(X⊤WX)−1X⊤W)S⊤iAd1,iWiXi(X⊤WX)−1C
g2,i=(I−L⊤iX(X⊤WX)−1X⊤Li)S⊤iAd2,iL⊤iXi(X⊤WX)−1C
where Si is the row selection matrix.
We will prove the inner part equal L−1(I−X(X⊤WX)−1X⊤W)S⊤iAd1,iWi=(I−L⊤X(X⊤WX)−1X⊤L)S⊤iAd2,iL⊤i
With the previous proof of covariance estimators, we already have
M1,d,i=WiAd1,i=LiAd2,iL⊤i=M2,d,i we then need to prove L−1(I−X(X⊤WX)−1X⊤W)S⊤i=(I−L⊤X(X⊤WX)−1X⊤L)S⊤iL−1i
and note the relationship between (I−X(X⊤WX)−1X⊤W) and (I−L⊤X(X⊤WX)−1X⊤L) has already been proved in covariance estimator section, we only need to prove
L−1(I−X(X⊤WX)−1X⊤W)S⊤i=(I−L⊤X(X⊤WX)−1X⊤L)S⊤iL−1i
Apparently
L−1(I−X(X⊤WX)−1X⊤W)S⊤i=L−1S⊤i−L−1X(X⊤WX)−1X⊤iWi
(I−L⊤X(X⊤WX)−1X⊤L)S⊤iL−1i=S⊤iL−1i−L⊤X(X⊤WX)−1X⊤i
And obviously L−1S⊤i=S⊤iL−1i
L−1X(X⊤WX)−1XiWi=L⊤X(X⊤WX)−1X⊤i
because of the following (X(X⊤WX)−1XiWi)i=Xi(X⊤WX)−1XiWi=WiXi(X⊤WX)−1X⊤i=(WX(X⊤WX)−1X⊤i)i
Special Considerations in Implementations
Pseudo Inverse of a Matrix
Empirical covariance matrix is involved with the inverse of a matrix, or symmetric square root of a matrix. To calculate this, we usually requires that the matrix is positive-definite. However, Young (2016) suggest that this is not always assured in practice.
Thus, following Pustejovsky and Tipton
(2018), we use the pseudo inverse to avoid this. We follow the
following logic (see the corresponding C++
function
pseudoInverseSqrt
) to obtain the pseudo inverse:
- Conduct singular value decomposition.
- Use
cpow
to obtain the square root of the reciprocals of singular values, if the value is larger than a computational threshold; otherwise replace the value with 0. - Reconstruct the pseudo inverse matrix from modified singular values and U/V matrix.
In Eigen
package, the pseudo inverse method is already
implemented in Eigen::CompleteOrthogonalDecomposition< MatrixType_ >::pseudoInverse
,
but it is not used for the following reason:
- The pseudo inverse method is not stable and can lead to
NAN
in calculations. - To find out the symmetric square root, singular value decomposition is still needed, so not using the method but instead calculating directly the square root of the pseudo inverse can be simpler.