plot_mix_comps: Custom Function for Overlaying Mixture Components

Description Usage Arguments Details Examples

View source: R/plot_mix_comps.R

Description

Plots a mixture component conditioned on a superimposed function

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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")

plotGMM documentation built on July 8, 2020, 7:26 p.m.