[R] mixture univariate distributions fit

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Fri Dec 31 09:25:49 CET 2021


On Fri, 31 Dec 2021 07:59:11 +0000
PIKAL Petr <petr.pikal using precheza.cz> wrote:

> x <- (0:100)/100
> y1 <- dnorm((x, mean=.3, sd=.1)
> y2 <- dnorm((x, mean=.7, sd=.1)
> ymix <- ((y1+2*y2)/max(y1+2*y2))
 
> My question is if there is some package or function which could get
> those values ***directly from x and ymix values***, which is
> basically what is measured in my case.

Apologies if I'm missing something, but, this being a peak fitting
problem, shouldn't nls() (or something from the minpack.lm or nlsr
packages) work for you here?

minpack.lm::nlsLM(
 ymix ~ a1 * dnorm(x, mu1, sigma1) + a2 * dnorm(x, mu2, sigma2),
 start = c(a1 = 1, mu1 = 0, sigma1 = 1, a2 = 1, mu2 = 1, sigma2 = 1),
 lower = rep(0, 6) # help minpack avoid NaNs
)
# Nonlinear regression model
#  model: ymix ~ a1 * dnorm(x, mu1, sigma1) + a2 * dnorm(x, mu2, sigma2)
#  data: parent.frame()
#      a1    mu1 sigma1     a2    mu2 sigma2
#  0.1253 0.3000 0.1000 0.2506 0.7000 0.1000
# residual sum-of-squares: 1.289e-31
# 
# Number of iterations to convergence: 23 
# Achieved convergence tolerance: 1.49e-08

(Some nonlinear least squares problems will be much harder to solve
though.)

-- 
Best regards,
Ivan



More information about the R-help mailing list