Tools for Visualizing Gaussian Mixture Models

The main function, plot_GMM, is used for plotting output from Gaussian mixture models, including both densities and overlaying mixture weight component curves from the fit GMM. The package includes another function, plot_mix_comps, which is used in the plot_GMM function, and can be used in any plot generated by the user for overlaying mixture component curves from Gaussian mixture models. For the plot_mix_comps function, usage most often will be specifying the "fun" argument within "stat_function" in a ggplot2 object.



title: "README.md" author:

  • Philip D. Waggoner^[College of William & Mary]
  • Fong Chun Chan^[Achilles Therapeutics] date: 4/17/2019 output: html_document

In collaboration with Fong Chan @tinyheero, the latest release (v 0.2.0) of plotGMM includes substantial updates with easy-to-use tools for visualizing output from Gaussian mixture models:

  1. plot_GMM: The main function of the package, plot_GMM allows the user to simply input the name of a mixEM class object (from fitting a Gaussian mixture model (GMM) using the mixtools package), as well as the number of components, k, that were used in the original GMM fit. The result is a clean ggplot2 class object showing the density of the data with overlaid mixture weight component curves.

  2. plot_cut_point: Gaussian mixture models (GMMs) are not only used for uncovering clusters in data, but are also often used to derive cut points, or lines of separation between clusters in feature space (see the Benaglia et al. 2009 reference in the package documentation for more). The plot_cut_point function plots data densities with the overlaid cut point (the mean of the calculated mu) from mixEM class objects, which are GMM's fit using the mixtools package.

  3. plot_mix_comps: This is a custom function for users interested in manually overlaying the components from a Gaussian mixture model. This allows for clean, precise plotting constraints, including mean (mu), variance (sigma), and mixture weight (lambda) of the components. The function superimposes the shape of the components over a ggplot2 class object. Importantly, while the plot_mix_comps function is used in the main plot_GMM function in our plotGMM package, users can use the plot_mix_comps function to build their own custom plots.

mixmdl <- mixtools::normalmixEM(faithful$waiting, k = 2)
 
plot_GMM(mixmdl, 2)

Plotting Cut Points from GMMs using plot_cut_point

mixmdl <- mixtools::normalmixEM(faithful$waiting, k = 2)
 
plot_cut_point(mixmdl, plot = TRUE) # produces plot
 
plot_cut_point(mixmdl, plot = FALSE) # produces only numeric summary output from GMM

Manually using the plot_mix_comps function in a custom ggplot2 plot

library(plotGMM)
library(magrittr)
library(ggplot2)
library(mixtools)
 
# Fit a GMM using EM
set.seed(576)
mixmdl <- normalmixEM(faithful$waiting, k = 2)
 
# Plot mixture components using the `plot_mix_comps` function
data.frame(x = mixmdl$x) %>%
ggplot() +
geom_histogram(aes(x, ..density..), binwidth = 1, colour = "black",
                 fill = "white") +
   stat_function(geom = "line", fun = plot_mix_comps,
                 args = list(mixmdl$mu[1], mixmdl$sigma[1], lam = mixmdl$lambda[1]),
                 colour = "red", lwd = 1.5) +
   stat_function(geom = "line", fun = plot_mix_comps,
                 args = list(mixmdl$mu[2], mixmdl$sigma[2], lam = mixmdl$lambda[2]),
                 colour = "blue", lwd = 1.5) +
   ylab("Density")

News


title: "NEWS.md" author: "Philip D. Waggoner" date: "4/17/2019" output: html_document

plotGMM v 0.2.0

Tools for Visualizing Gaussian Mixture Models

Changes: New Functions Added

  1. plot_GMM: Now the main function of the package, plot_GMM allows the user to simply input the name of a mixEM class object (from fitting a Gaussian mixture model (GMM) using the mixtools package), as well as the number of components, k, that were used in the original GMM fit. The result is a clean ggplot2 class object showing the density of the data with overlaid mixture weight component curves.

  2. plot_cut_point: Gaussian mixture models (GMMs) are not only used for uncovering clusters in data, but are also often used to derive cut points, or lines of separation between clusters in feature space (see the Benaglia et al. 2009 reference in the package documentation for more). The plot_cut_point function plots data densities with the overlaid cut point (the mean of the calculated mu) from mixEM class objects, which are GMM's fit using the mixtools package.

How do I get plotGMM?

The package is released on CRAN. If you have any questions or find any bugs requiring fixing, please feel free to contact us either directly (see the DESCRIPTION file for more) or by opening an issue ticket on GitHub. Thanks and enjoy!

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("plotGMM")

0.2.0 by Philip Waggoner, 2 months ago


Report a bug at https://github.com/pdwaggoner/plotGMM/issues


Browse source code at https://github.com/cran/plotGMM


Authors: Philip Waggoner [aut, cre] , Fong Chan [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports methods, graphics

Suggests ggplot2, mixtools, testthat


See at CRAN