mplnVisualizeBar: Visualize Posterior Probabilities via Bar Plot

View source: R/mplnVisualize.R

mplnVisualizeBarR Documentation

Visualize Posterior Probabilities via Bar Plot

Description

A function to produce a barplot of posterior probabilities for each observation, after clustering via mixtures of multivariate Poisson-log normal (MPLN) model.

Usage

mplnVisualizeBar(
  vectorObservations,
  probabilities = NA,
  clusterMembershipVector = NA,
  fileName = paste0("Plot_", date()),
  printPlot = TRUE,
  format = "pdf"
)

Arguments

vectorObservations

A vector of length observations (N), that contains either integers or characters, specifying the observations. E.g., c(1:100) for 100 different observations or c("a", "b", ...).

probabilities

A matrix of numeric probabilities containing N (observation) rows and G (number of maximum clusters) columns. Row sums should be 1. Default value is NA.

clusterMembershipVector

A numeric vector of length nrow(dataset) containing the cluster membership of each observation. 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 bar plot of posterior probabilities for each observation in the dataset.

Author(s)

Anjali Silva, anjali@alumni.uoguelph.ca

Examples

# Example 1
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 = 2,
                              initMethod = "kmeans",
                              nInitIterations = 1,
                              normalize = "Yes")

 # Visualize posterior probabilities via a bar plot
 MPLNVisuals <- MPLNClust::mplnVisualizeBar(vectorObservations = 1:nrow(simulatedCounts$dataset),
                                            probabilities =
                                            MPLNClustResults$allResults$`G=2`$probaPost,
                                            clusterMembershipVector =
                                            MPLNClustResults$allResults$`G=2`$clusterlabels,
                                            fileName = 'PosteriorProbMPLN',
                                            printPlot = FALSE,
                                            format = 'png')


anjalisilva/MPLNClust documentation built on Sept. 19, 2024, 7:34 a.m.