Triangular matrices
The tri.mat
function in R can be used to create a triangular matrix. This function returns a matrix of true or false values, corresponding to the upper or lower triangle. The following commands return a lower triangular matrix of the cor.mat
matrix:
triangle.matrix <- cor.mat triangle.mat[upper.tri(triangle.matrix)] <- triangle.matrix
Here, we use upper.tri
to identify the elements of the matrix that we wish to set to NA. In the case of this correlation matrix, the upper and lower triangles are identical, so retaining only half of the matrix makes sense.
We will also further discuss the decomposition of a square matrix into an upper and lower triangular matrix.