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.


In collaboration with Fong Chun Chan @tinyheero, plotGMM provides a custom function, plot_mix_comps, for users interested in 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. Specifically, the function superimposes the shape of the components over a ggplot2 object. We demonstrate this both in the example in the package documentation, as well as below.

library(magrittr)
library(ggplot2)
library(mixtools)
set.seed(1)
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")

This package is the first iteration of a broader project that will eventually include several other plotting and fitting tools for Gaussian mixture models and the Expectation-Maximization (EM) algorithm.

News

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, 4 days 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