make.symmetric {dclone} | R Documentation |
Matrix symmetry might depend on numerical precision issues. There is a bug in JAGS related to this issue for multivariate normal nodes. This simple function can fix the issue.
make.symmetric(x)
x |
A square matrix. |
The function takes the average of (x[i, j] + x[j, i]) / 2
for each off diagonal cells.
A symmetric square matrix.
The function works for any matrix, even for those not intended to be symmetric.
P\'eter S\'olymos, solymos@ualberta.ca
x <- as.matrix(as.dist(matrix(1:25, 5, 5))) diag(x) <- 100 x[lower.tri(x)] <- x[lower.tri(x)] - 0.1 x[upper.tri(x)] <- x[upper.tri(x)] + 0.1 x make.symmetric(x)