Learn R Programming

dclone (version 2.3-2)

make.symmetric: Make a square matrix symmetric by averaging.

Description

Matrix symmetry might depend on numerical precision issues. The older version of JAGS had a bug related to this issue for multivariate normal nodes. This simple function can fix the issue, but new JAGS versions do not require such intervention.

Usage

make.symmetric(x)

Value

A symmetric square matrix.

Arguments

x

A square matrix.

Author

Peter Solymos, solymos@ualberta.ca

Details

The function takes the average as (x[i, j] + x[j, i]) / 2 for each off diagonal cells.

Examples

Run this code
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)

Run the code above in your browser using DataLab