1

I don't understand how to find a plot of the true mixture density. In the following, I have provided the code which creates a function for the normal mixture. And I understand how to create each individual density plot, but I do not know how to find the true density.

NormalMix <- function(n,omega,mu1,mu2,sigma1,sigma2) {
z <- sample(2,n,replace=T,prob=c(omega,1-omega))
n1 <- sum(z==1)
n2 <- sum(z==2)
z[z==1] <- rnorm(n1,mu1,sigma1)
z[z==2] <- rnorm(n2,mu2,sigma2)
z
}

Simulated Data

Fire
  • 301
  • 1
  • 2
  • 9
  • So is this a statistics question? Like are you trying to find the functional form of the combined pdf? – MrFlick Oct 28 '19 at 17:48
  • Maybe this will help: https://stackoverflow.com/questions/23480529/r-function-to-generate-a-mixture-distribution or this https://stackoverflow.com/questions/39945473/plot-density-curve-of-mixture-of-two-normal-distribution or this https://stackoverflow.com/questions/20452650/writing-a-bimodal-normal-distribution-function-in-r – MrFlick Oct 28 '19 at 17:50

1 Answers1

2

I and my professor wrote this paper: D. S. Young, X. Chen, D. C. Hewage, and R. N. Poyanco (2018). “Finite Mixture-of-Gamma Preparation Distributions: Estimation, Inference, and Model-Based Clustering.”

And he also has an R library, which is called mixtools: https://cran.r-project.org/web/packages/mixtools/vignettes/mixtools.pdf

You can use the wait1 <- normalmixEM(waiting, lambda = .5, mu = c(55, 80), sigma = 5) for example, on page 6, to extimate the parameters.

This library doesn't need you to provide the mean and standard deviation, it will estimate for you based on the range you provided. And you can use native R plot function to generate nice plots.

I hope it helps.

Bill Chen
  • 1,699
  • 14
  • 24