'Problems in drawing a Gaussian Mixture on observations in R
I am analysing genetic data and using mclust package in R to fit a model consisting of a Gaussian Mixture with 2 components to my data. The package gives me the following report:
Clustering table: 1 - 28081; 2 - 49324; Mixing probabilities: 1 - 0.3504733; 2 - 0.6495267; Means: 1 - 0.3887262; 2 - 0.8179646; Variances: 1 - 0.01275553; 2 - 0.02633131.
In addition, the package provides the density plot of the fitted model by using the command:
plot(fit2, what = "density")
Image 1
Then, I changed the plot by representing the original data as well:
plot(fit2, what = "density", data = mynew, breaks = seq(from=0, to=3, by=0.05),col="red3",lwd=2)
lines(density(mynew), col="black", lwd=2)
#where mynew corresponds to the vector with my observations
My goal now is to have a density plot similar to image 2, but that represents the 2 full curves of the Gaussian mixture (with 2 components) fitted with mclust, together with the original data.
So, my idea was to plot the original data and then use the rnorm function to represent the two full curves of mclust over the original data.
However, after so many tries the two curves look always strange and nothing similar to the density plot created with the fitted model, i.e. Image 2.
Here is the code and plot that I am obtaining (please see image 3):
hist(mynew, freq = F, ylim = c(0,4), breaks = seq(from=0, to=3, by=0.05))
x=seq(0,3,length=300000)
y=rnorm(x,mean=0.8179646,sd=sqrt(0.02633131)) #values of mclust
lines(density(y), col="blue",lwd=2)
a=seq(0,3,length=300000)
b=rnorm(a,mean=0.3887262,sd=sqrt(0.01275553)) #values of mclust
lines(density(b),col="green",lwd=2)
Does anyone know how to fix this, i.e. have a density plot with the two full curves (provided by mclust) represented over the original data?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|



