View source: R/plot_mix_comps.R
plot_mix_comps | R Documentation |
Allows for plotting mixture components conditioned on a superimposed function meant for passage to ggplot's stat_function()
plot_mix_comps(x, mu = NULL, sigma = NULL, lam = 1, beta0 = NULL, beta1=NULL, alpha=NULL, beta=NULL, normal=FALSE, logisreg=FALSE, gamma=FALSE, poisson=FALSE)
x |
Input data |
mu |
Component mean |
sigma |
Component variance |
lam |
Component mixture weight |
beta0 |
Coefficient values |
beta1 |
Coefficient values |
alpha |
Initial shape parameters |
beta |
Initial parameter values |
normal |
Logical for normal distribution |
logisreg |
Logical for logistic regression mixtures |
gamma |
Logical for gamma distribution |
poisson |
Logical for poisson regression mixtures |
Allows for component curves to be superimposed over a mixture model plot
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, 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.