3
$\begingroup$

Let $A$ be a $2 \times 2$ matrix. What does $\mbox{diag}(A)$ denote?

It can't refer to a block-diagonal matrix, so does it basically mean $A$ with anything but the diagonal set to $0$?

$\endgroup$
3
  • 2
    $\begingroup$ Where did you encounter $\mbox{diag}(A)$? $\endgroup$ Jun 13, 2022 at 13:39
  • $\begingroup$ @RodrigodeAzevedo Unfortunately giving the full context is a bit challenging, but the main context would be ML estimation of the cov matrix in FA, e.g. $\hat{\Sigma}=\frac{1}{N} \operatorname{diag}\left[\left\langle x^{\prime} x^{\prime \top}\right\rangle-\left\langle x^{\prime}\langle z\rangle^{\top}\right\rangle \hat{W}^{\top}\right]$. But the source is not very reputable or so so if the usage is not common then the author might have missed redefining the notation. $\endgroup$
    – zareami10
    Jun 13, 2022 at 13:47
  • 1
    $\begingroup$ Take a look at section 5 of Minka's Old and new Matrix Algebra useful for Statistics. $\endgroup$ Jun 13, 2022 at 14:12

1 Answer 1

5
$\begingroup$

$\operatorname{diag}(A)$ for a matrix $A$ usually refers to the vector holding the diagonal entries of $A$.

Conversely, $\operatorname{diag}(v)$ for a vector $v$ usually refers to the square matrix which has $v$ on the diagonal and zeros everywhere else.

A third common usage is to let $\operatorname{diag}(A)$ for a matrix $A$ be the matrix with all non-diagonal entries replaced by zero, which is like Misha mentioned in the comments equivalent to $\operatorname{diag}(\operatorname{diag}(A))$ using the other convention.

In your context, given $\hat{\Sigma}=\frac{1}{N} \operatorname{diag}\left[\left\langle x^{\prime} x^{\prime \top}\right\rangle-\left\langle x^{\prime}\langle z\rangle^{\top}\right\rangle \hat{W}^{\top}\right]$ as the estimation of the covariance matrix in a factor analysis, obviously only the 3rd defition applies as the input is a matrix and the output is a matrix.

$\endgroup$
2
  • 2
    $\begingroup$ This is the Matlab convention. Another existing convention is to write $\operatorname{diag}(A)$ for the vector of diagonal entries, but $\operatorname{Diag}(A)$ or $\operatorname{Diag}(v)$ when the output should be a diagonal matrix (so $\operatorname{Diag}(A)$ is what the Matlab convention would call $\operatorname{diag}(\operatorname{diag}(A))$. $\endgroup$ Jun 13, 2022 at 13:49
  • $\begingroup$ The convention in Julia is similar to Matlab. The function diag(B) takes a matrix argument and returns a vector result, while the function Diagonal(b) takes a vector argument and returns a (diagonal) matrix, but courtesy of Julia's multiple dispatch feature, you can also call this function with a matrix argument and it will behave like Diagonal(diag(B)) $\,$ It seems odd at first, but I have come to appreciate the difference in the function names yet the consistency of their return types. $\;$ [NB: calling diag(b) throws an error.] $\endgroup$
    – greg
    Jun 13, 2022 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .