Learn R Programming

mdir (version 0.9.0)

comparePSMsAcrossChains: Compare Posterior Similarity Matrices Across Chains

Description

Takes the PSMs from the output of ``processMCMCChains`` and converts them to a data.frame prepared for ``ggplot2``.

Usage

comparePSMsAcrossChains(
  mcmc,
  matrix_setting_order = 1,
  use_common_ordering = TRUE,
  ignore_checks = TRUE
)

Value

A long data.frame containing columns `x` (the x-axis position of the entry for geom_tile()), `y` (the y-axis position of the entry for geom_tile()), `Entry` (value in similarity matrix), `Chain` (assumes chains are ordered from one to the number of chains present) and `View`.

Arguments

mcmc

Output of ``processMCMCChains`` with the argument ``construct_psm = TRUE``.

matrix_setting_order

The matrix that defines the ordering of all others, if a common ordering is used. Defaults to `1`.

use_common_ordering

Logical indicating if a common ordering should be used. If false all matrices are ordered individually, defaults to `TRUE`.

ignore_checks

Logical indicating if checks for matrix symmetry and a commmon size should be ignored. Defaults to TRUE as these checks seem to break when they should not.

Examples

Run this code
# \donttest{
N <- 500
K <- 4
P <- 10

X <- generateSimulationDataset(K, N, P)
Y <- generateSimulationDataset(K, N, P)
Z <- generateSimulationDataset(K, N, P)

row.names(Z$data) <- row.names(Y$data) <- row.names(X$data)

data_modelled <- list(X$data, Y$data, Z$data)

n_chains <- 4
R <- 10000
thin <- 25
types <- c("G", "G", "G")
K <- c(10, 10, 10)
mcmc <- runMCMCChains(data_modelled, n_chains, R, thin, types, K = K)

burn <- 2500
mcmc <- processMCMCChains(mcmc, burn, construct_psm = TRUE)
psm_df <- comparePSMsAcrossChains(mcmc)

psm_df |>
  ggplot2::ggplot(ggplot2::aes(x = x, y = y, fill = Entry)) +
  ggplot2::geom_tile() +
  ggplot2::facet_grid(View ~ Chain, labeller = ggplot2::label_both) +
  ggplot2::scale_fill_gradient(low = "#FFFFFF", high = "#146EB4") +
  ggplot2::labs(x = "Item", y = "Item", fill = "Coclustering\nproportion") +
  ggplot2::theme(
    axis.text = ggplot2::element_blank(),
    axis.ticks = ggplot2::element_blank(),
    panel.grid = ggplot2::element_blank(),
    axis.title.y = ggplot2::element_text(size = 10.5),
    axis.title.x = ggplot2::element_text(size = 10.5),
    plot.title = ggplot2::element_text(size = 18, face = "bold"),
    plot.subtitle = ggplot2::element_text(size = 14),
    strip.text.x = ggplot2::element_text(size = 10.5),
    legend.text = ggplot2::element_text(size = 10.5)
  )
# }

Run the code above in your browser using DataLab