Skip to content
Prev 179667 / 398513 Next

if ((x >.2 || x<(-.2)) && (col(x)!=row(x))) {x=x[,-col(x)]}

Hi. I have a correlation matrix 'x' which is of size 923x923

I need to remove variables that are highly correlated. I don't have a
sophisticated way of selecting which of the two in a highly correlated pair
to remove. I thought I would just go through each entry of the correlation
matrix and if it is greater than 0.6 (or less than -0.6) I will remove that
column and then redo the check from scratch with the matrix (where now the
matrix has one less column).
As a test, I tried if ((x >.2 || x<(-.2)) && col(x)!=row(x)) {x=x[,-col(x)]}
but it does not remove any columns.

Also, I realized that I actually need to pull out the row that is associated
with that variable as well, and so perhaps the section inside {} needs to be
something like:
{x=x[-col(x),-col(x)]
Any idea on how to do this?
Thank you.