knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

blotr: Blotting matrices since 2016

This package does one thing: create symmetric matrices from asymmetric matrices. It is inspired by This tweet.

The basic idea is that you fold your matrix across the diagonal to create a symmetric matrix like an inkblot for a Rorschach test.

How do I use it?

There is only one function called blot().

Simple example

library("blotr")
set.seed(20160325)
mat <- matrix(sample(c(NA, 1), 100, replace = TRUE), 10, 10)
diag(mat) <- 0
mat
isSymmetric(mat)

The matrix is non-symmetrical! We'll make it symmetrical with blot()!

blot(mat)
isSymmetric(blot(mat))

We can also choose to keep only the upper triangle if we wish:

blot(mat, ut = TRUE)

Now let's have some fun

Let's generate some inkblots and visualize them:

set.seed(20160326)
mat <- matrix(NA_integer_, 100, 100)
x   <- replicate(10, rnorm(250, mean = sample((3:7)*10, 1), 5))
y   <- replicate(10, rnorm(250, mean = sample((3:7)*10, 1), 5))
obs <- matrix(round(c(x, y)), ncol = 2)
mat[obs]  <- 1L
diag(mat) <- 0L
isSymmetric(mat)

Now for the plotting. First, the without blotting:

robs  <- range(obs)/100
fx    <- seq(0, 1, length.out = 100)
omar  <- par("mar")
par(mar = c(0, 0, 0, 0))
plot(NA, xlim = robs, ylim = robs, type = "n", asp = 1, ann = FALSE, axes = FALSE)
.filled.contour(fx, fx, mat, c(0, 1), col = "black")
par(mar = omar)

Now, with blotting:

par(mar = c(0, 0, 0, 0))
plot(NA, xlim = robs, ylim = robs, type = "n", asp = 1, ann = FALSE, axes = FALSE)
.filled.contour(fx, fx, blot(mat), c(0, 1), col = "black")
par(mar = omar)

Installation

You can install blotr via devtools::

devtools::install_github("zkamvar/blotr")


zkamvar/blotmat documentation built on May 4, 2019, 11:24 p.m.