# [R] FW: help with mclust

Tatiana Benaglia tab321 at stat.psu.edu
Thu Oct 4 07:04:07 CEST 2007

```Hi Ken,
I know your question was specifically about the mclus, but you can
also try to fit a univariate gaussian mixture using the normalmixEM
in the mixtools package.

library(mixtools)
out = normalmixEM(data, k=3)

That's what I got for your sample:
> out\$lambda
[1] 0.119 0.647 0.234

> out\$mu
[1]  0.180  0.002 -0.092
> out\$sigma
[1] 0.077 0.026 0.078

If you wanna visualize the density for each component, use:
plot.mixEM(out, density=T)

I hope this helps,

Tatiana Benaglia
Ph.D. Candidate
Department of Statistics
Penn State University

On Oct 3, 2007, at 6:47 PM, Lo, Ken wrote:

>> No HTML this time.  Sorry
>
> Dear all,
>
> I am attempting to model some one-dimensional data using Gaussian
> mixture model with mclust.  Generally, the data that I have have 3
> overlapping populations (with one of them being the majority, and
> the other two combining to less than 15%) and for some reason,
> mclust consistently ignores the smaller peaks, giving me strange
> values for the means (completely anti-intuitive in terms of visual
> inspection by using plot(density())).  However, when I use rnorm to
> generate some fake data, mclust works consistently well.  As I am
> quite new to R, I was wondering whether anyone could help me out.
> I am using the em function in mclust, with parameters that are
> arbitrarily set
>
> Pro <- c(0.33,0.33,0.33)
> Mean<- c(-0.5,0,0.5)
> Sigmasq <- c(0.05,0.05,0.05)
>
> And a sample of my data set is
>
> c
> (-0.016133,-0.07668,-0.000625,0.031329,-0.011094,0.014199,-0.014141,0.
> 036836,-0.007695,-0.011738,-0.021953,0.046565,0.010859,-0.050313,-0.16
> 7813,0.01543,-0.057598,-0.034336,0.182275,0.032959,0.01918,0.009248,-0
> .
> 195273,-0.00918,-0.017813,0.003828,-0.113867,0.004014,0.031504,0.00427
> 7,0.052188,-0.030859,-0.214023,-0.329102,-0.07832,-0.008379,0.05833,-0
> .
> 007285,-0.036992,0.035768,0.055006,-0.000781,0.005067,-0.025811,0.0210
> 16,-0.002598,-0.036799,-0.03119,-0.004482,-0.024473,-0.108115,-0.11631
> 8,0.158008,0.04252,-0.032129,0.00707,-0.073398,-0.115605,-0.033945,-0.
> 022793,0.041855,0.006289,0.250273,0.042607,-0.000449,0.030098,0.041238
> ,-0.028926,-0.111895,0.003867,0.015625,-0.018906,-0.00291,-0.027188,0.
> 00957,-0.133369,0.018652,0.138652,0.038789,-0.050107,0.135908,-0.05272
> 5,0.005977,0.030977,0.005371,-0.179902,-0.008691,0.033711,0.164033,-0.
> 063457,0.022734,-0.047227,0.025918,-0.005557,-0.104453,0.021348,-0.054
> 902,-0.069277,-0.115273,0.038906,0.171211,0.000645,-0.064873,0.014062,
> -0.00252,-0.017715,-0.000586,0.174609,-0.056396,0.000937,-0.217148,-0.
> 203105,0.006533,0.015371,-0.024629,0.015244,0.002949,0.024805,-0.10402
> 3,0.007964,-0.198633,-0.007833,-0.000518,0.018232,0.000195,0.028575,-0
> .
> 028145,-0.030098,-0.002148,-0.035723,-0.005996,0.023027,0.034512,0.009
> 189,0.049252,-0.016641,-0.023262,-0.013379,-0.013633,0.150996,0.040391
> ,
> 0.153809,0.001182,0.040371,-0.016191,-0.05097,-0.12041,0.042617,0.0188
> 28,-0.002617,-0.043887,-0.025764,-0.016836,0.023535,0.040625,0.158789,
> -0.026934,0.02791,-0.108027,0.037979,-0.011865,0.06127,0.04416,-0.0783
> 3,0.019922,0.000685,-0.071885,0.000479,0.006211,-0.030879,-0.009188,-0
> .
> 061895,-0.069102,0.032051,-0.082637,-0.246484,-0.015586,-0.008555,0.26
> 5664,0.050781,0.008242,0.169785,-0.025977,0.017871,-0.239492,0.005234,
> 0.006865,0.007344,0.237861,-0.110742,0.208008,0.189336,0.205469,-0.111
> 729,-0.023438,0.49,-0.028281,0.177988,0.00998,-0.002402,0.161924,0.220
> 859,0.026455,0.019629,-0.015098,-0.110771,-0.014414,0.121211,0.028439,
> -0.026143,0.024989,-0.060801,-0.023124,-0.012734,0.168398,0.039955,-0.
> 038984,-0.028543,0.157412,-0.015547,-0.012617,0.031607,-0.053437,0.027
> 246,0.003906,-0.218613,0.024902,0.020273,0.011914,0.162051,0.00582,-0.
> 019189,-0.009029,0.001875,0.015273,0.175303,-0.092441,-0.086738,-0.022
> 871,0.027852,-0.108809,0.005938,-0.016543,-0.019288,0.210566,-0.022813
> ,-0.001748,-0.108574,0.164971,-0.075186)
>
> If anyone could help me out, I would be extremely grateful.
>
> Best,
>
> Ken Lo
>
>
> **********************************************
> Ken Lo, PhD
> Post-Doctorate Research Affliliate
> Department of Cancer Genetics
> Buffalo Life Science Complex, L2-104
> Roswell Park Cancer Institute
> Elm and Carlton Streets
> Buffalo, New York 14263
> Telephone:  716-845-3941
> Fax:         716-845-3940
> E-mail:      Ken.Lo at RoswellPark.org
> Web:        www.RoswellPark.org
>
> Located in the
> Buffalo Life Science Complex
> on the Buffalo Niagara Medical Campus
> **********************************************
>
>
>
>
>
> This email message may contain legally privileged and/or
> confidential information.  If you are not the intended recipient
> (s), or the employee or agent responsible for the delivery of this
> message to the intended recipient(s), you are hereby notified that
> any disclosure, copying, distribution, or use of this email message
> is prohibited.  If you have received this message in error, please
> notify the sender immediately by e-mail and delete this email
> message from your computer. Thank you.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

```