plot_mix_comps_normal: Custom Function for Overlaying Mixture Components for Normal...

View source: R/plot_mix_comps_normal.R

plot_mix_comps_normalR Documentation

Custom Function for Overlaying Mixture Components for Normal Distributions

Description

Plots a mixture component conditioned on a superimposed function

Usage

plot_mix_comps_normal(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 assuming a normal distribution. This is the original function for the package, which is also included in the updated plot_mix_comps() function.

Examples


if(require(mixtools)){
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_normal,
                args = list(mixmdl$mu[1], mixmdl$sigma[1], lam = mixmdl$lambda[1]),
                colour = "red") +
  ggplot2::stat_function(geom = "line", fun = plot_mix_comps_normal,
                args = list(mixmdl$mu[2], mixmdl$sigma[2], lam = mixmdl$lambda[2]),
               colour = "blue")



plotmm documentation built on Nov. 10, 2022, 5:14 p.m.