[R] Finding x-value of intersections of mixture models

Ludwig Hilger l.hilger at ku.de
Thu May 9 17:43:58 CEST 2013


Dear list,

I am trying to decompose a distribution into 4 normal distributions using
the function normalmixEM from package mixtools. This works well, I get four
mus and sds. I am now wondering how to get the 3 x values where the
distributions intersect. I have tried the following:

> summary(gemixed)
summary of normalmixEM object:
          comp 1    comp 2    comp 3    comp 4
lambda 0.0327861  0.206095  0.642772  0.118347
mu     5.4289201 15.885116 33.519228 59.564096
sigma  2.6662273  5.681445  9.337467 10.464027
loglik at estimate:  -22760961 

f.ints <- function(x, mu1, mu2, sd1, sd2) {
    f1 <- dnorm(x, mean = mu1, sd = sd1)
    f2 <- dnorm(x, mean = mu2, sd = sd2)
    f <- abs(f1 - f2)
    xs[which.min(f)]}
xintersections <- numeric() 
#
for(i in 1:(length(gemixed$mu)-1)){
xs <- seq(from = gemixed$mu[i], to  = gemixed$mu[i+1], by = 0.001)
xinter <- f.ints(x = xs, mu1 = gemixed$mu[i], mu2 = gemixed$mu[i+1], sd1 =
gemixed$sigma[i], sd2 = gemixed$sigma[i+1])
xintersections <- rbind(xintersections, xinter)}

Unfortunately, the x values I get this way are not near the intersections of
the curves as plotted in:

plot( # takes an object of class mixEM and returns various graphical output
for select mixture models
  x = gemixed,   # An object of class mixEM
  whichplots = 2,
  density = TRUE)

Maybe I get this all wrong and there is an easy way to get the intersection
x-values? Any help would be very much appreciated!

Thank you and best regards,

Ludwig

##############################
> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
LC_TIME=German_Germany.1252    

attached base packages:
[1] grDevices datasets  splines   graphics  stats     tcltk     utils    
methods   base     

other attached packages:
 [1] rgdal_0.8-8       mixtools_0.4.6    segmented_0.2-9.4 MASS_7.3-22     
boot_1.3-7        mclust_4.1        RSAGA_0.93-2.1    plyr_1.7.1       
shapefiles_0.6    foreign_0.8-52    gstat_1.0-14      spacetime_0.8-0  
[13] xts_0.8-8         zoo_1.7-9         sp_1.0-9          svSocket_0.9-53 
TinnR_1.0-5       R2HTML_2.2        Hmisc_3.9-3       survival_2.36-14 

loaded via a namespace (and not attached):
[1] cluster_1.14.3  grid_2.15.2     lattice_0.20-10 svMisc_0.9-65  
tools_2.15.2   




-----
Dipl. Geogr. Ludwig Hilger
Wiss. MA
Lehrstuhl für Physische Geographie
Katholische Universität Eichstätt-Ingolstadt
Ostenstraße 18
85072 Eichstätt
--
View this message in context: http://r.789695.n4.nabble.com/Finding-x-value-of-intersections-of-mixture-models-tp4666683.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list