plot_mix_comps {plotGMM}R Documentation

Custom Function for Overlaying Mixture Components

Description

Plots a mixture component conditioned on a superimposed function

Usage

plot_mix_comps(x, mu, sigma, lam)

Arguments

x

Input data

mu

Mean of component

sigma

Variance of component

lam

Mixture weight of component

Details

Allows for specifying a custom function to be superimposed when plotting a mixture component

Examples

set.seed(1)
mixmdl <- mixtools::normalmixEM(faithful$waiting, k = 2)
x <- mixmdl$x
x <- data.frame(x)
ggplot2::ggplot(data.frame(x)) +
  ggplot2::geom_density(ggplot2::aes(x), color="black", fill="black") +
  ggplot2::stat_function(geom = "line", fun = plot_mix_comps,
                args = list(mixmdl$mu[1], mixmdl$sigma[1], lam = mixmdl$lambda[1]),
                colour = "red") +
  ggplot2::stat_function(geom = "line", fun = plot_mix_comps,
                args = list(mixmdl$mu[2], mixmdl$sigma[2], lam = mixmdl$lambda[2]),
               colour = "blue")

[Package plotGMM version 0.2.2 Index]