matViz {covdepGE}R Documentation

Visualize a matrix

Description

Create a visualization of a matrix

Usage

matViz(
  x,
  color1 = "white",
  color2 = "#500000",
  grid_color = "black",
  incl_val = FALSE,
  prec = 2,
  font_size = 3,
  font_color1 = "black",
  font_color2 = "white",
  font_thres = mean(x)
)

Arguments

x

matrix; matrix to be visualized

color1

color; color for low entries. "white" by default

color2

color; color for high entries. "#500000" by default

grid_color

color; color of grid lines. "black" by default

incl_val

logical; if TRUE, the value for each entry will be displayed. FALSE by default

prec

positive integer; number of decimal places to round entries to if incl_val is TRUE. 2 by default

font_size

positive numeric; size of font if incl_val is TRUE. 3 by default

font_color1

color; color of font for low entries if incl_val is TRUE. "black" by default

font_color2

color; color of font for high entries if incl_val is TRUE. "white" by default

font_thres

numeric; values less than font_thres will be displayed in font_color1 if incl_val is TRUE. mean(x) by default

Value

Returns ggplot2 visualization of matrix

Examples

## Not run: 
library(ggplot2)

# get the data
set.seed(12)
data <- generateData()
X <- data$X
Z <- data$Z
interval <- data$interval
prec <- data$true_precision

# get overall and within interval sample sizes
n <- nrow(X)
n1 <- sum(interval == 1)
n2 <- sum(interval == 2)
n3 <- sum(interval == 3)

# visualize the distribution of the extraneous covariate
ggplot(data.frame(Z = Z, interval = as.factor(interval))) +
  geom_histogram(aes(Z, fill = interval), color = "black", bins = n %/% 5)

# visualize the true precision matrices in each of the intervals

# interval 1
matViz(prec[[1]], incl_val = TRUE) +
  ggtitle(paste0("True precision matrix, interval 1, observations 1,...,", n1))

# interval 2 (varies continuously with Z)
cat("\nInterval 2, observations ", n1 + 1, ",...,", n1 + n2, sep = "")
int2_mats <- prec[interval == 2]
int2_inds <- c(5, n2 %/% 2, n2 - 5)
lapply(int2_inds, function(j) matViz(int2_mats[[j]], incl_val = TRUE) +
         ggtitle(paste("True precision matrix, interval 2, observation", j + n1)))

# interval 3
matViz(prec[[length(prec)]], incl_val = TRUE) +
  ggtitle(paste0("True precision matrix, interval 3, observations ",
                 n1 + n2 + 1, ",...,", n1 + n2 + n3))

# fit the model and visualize the estimated graphs
(out <- covdepGE(X, Z))
plot(out)

# visualize the posterior inclusion probabilities for variables (1, 3) and (1, 2)
inclusionCurve(out, 1, 2)
inclusionCurve(out, 1, 3)

## End(Not run)

[Package covdepGE version 1.0.1 Index]