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

Description Usage Arguments Details Value Note Author(s) Examples

View source: R/make.symmetric.R

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

1

Arguments

x

A square matrix.

Details

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

Value

A symmetric square matrix.

Note

The function works for any matrix, even for those not intended to be symmetric.

Author(s)

Peter Solymos, solymos@ualberta.ca

Examples

1
2
3
4
5
6
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)

dclone documentation built on May 29, 2017, 4:17 p.m.

Search within the dclone package
Search all R packages, documentation and source code