mplnVisualizeHeatmap: Visualize Clustered Results Via Heatmaps

View source: R/mplnVisualize.R

mplnVisualizeHeatmapR Documentation

Visualize Clustered Results Via Heatmaps

Description

A function to produce heatmaps of data with clustering results.

Usage

mplnVisualizeHeatmap(
  dataset,
  clusterMembershipVector = NA,
  fileName = paste0("Plot_", date()),
  printPlot = TRUE,
  format = "pdf"
)

Arguments

dataset

A dataset of class matrix and type integer such that rows correspond to observations (N) and columns (C) correspond to variables.

clusterMembershipVector

A numeric vector of length nrow(dataset) containing the cluster membership of each observation as generated by mpln(). Default is NA.

fileName

Unique character string indicating the name for the plot being generated. Default is Plot_date, where date is obtained from date().

printPlot

Logical indicating if plot(s) should be saved in local directory. Default TRUE. Options TRUE or FALSE.

format

Character string indicating the format of the image to be produced. Default 'pdf'. Options 'pdf' or 'png'.

Value

A heatmap of data with cluster memberships.

Author(s)

Anjali Silva, anjali@alumni.uoguelph.ca

Examples

# Example 1
# Setting the parameters
trueMu1 <- c(6.5, 6, 6, 6, 6, 6)
trueMu2 <- c(2, 2.5, 2, 2, 2, 2)

trueSigma1 <- diag(6) * 2
trueSigma2 <- diag(6)

# Generating simulated data
simulatedCounts <- MPLNClust::mplnDataGenerator(nObservations = 100,
                                      dimensionality = 6,
                                      mixingProportions = c(0.79, 0.21),
                                      mu = rbind(trueMu1, trueMu2),
                                      sigma = rbind(trueSigma1, trueSigma2),
                                      produceImage = "No")

 # Clustering data
 MPLNClustResults <- MPLNClust::mplnVariational(
                              dataset = as.matrix(simulatedCounts$dataset),
                              membership = "none",
                              gmin = 1,
                              gmax = 3,
                              initMethod = "kmeans",
                              nInitIterations = 1,
                              normalize = "Yes")

 # Visualize data via a Heatmap for G = 2
 MPLNHeatmap2 <- MPLNClust::mplnVisualizeHeatmap(dataset = simulatedCounts$dataset,
                                         clusterMembershipVector =
                                         MPLNClustResults$allResults$`G=2`$clusterlabels,
                                         fileName = 'TwoClusterModel',
                                         printPlot = FALSE,
                                         format = 'png')

 # Visualize data via a Heatmap for G = 3
 MPLNHeatmap3 <- MPLNClust::mplnVisualizeHeatmap(dataset = simulatedCounts$dataset,
                                         clusterMembershipVector =
                                         MPLNClustResults$allResults$`G=3`$clusterlabels,
                                         fileName = 'ThreeClusterModel',
                                         printPlot = FALSE,
                                         format = 'png')


anjalisilva/MPLNClust documentation built on Jan. 28, 2024, 11:02 a.m.