plot_mix_comps {plotmm} | R Documentation |
Helper Function for Overlaying Mixture Components
Description
Allows for plotting mixture components conditioned on a superimposed function meant for passage to ggplot's stat_function()
Usage
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)
Arguments
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 |
Details
Allows for component curves to be superimposed over a mixture model plot
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,
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 plotmm version 0.1.1 Index]