# Solved – Compute quantile function from a mixture of Normal distribution

I have this mixture of normal distribution:

$$X sim frac{1}{2}mathcal{N}(mu_{x_1}=10,,sigma_{x_1}^{2}=1)+frac{1}{2}mathcal{N}(mu_{x_2}=13,,sigma_{x_2}^{2}=1)$$
How can i compute the quantile function of this distributionin `R`?
I have to prove this function:
`qmist2n=function(y,mu1=10,sigma1=1,pi=0.5,mu2=13,sigma2=1){ (1 - pi) * qnorm(y, mu1, sigma1) + pi * qnorm(y, mu2, sigma2) }#qmist2n`

I'm not sure if this code is correct. Thanks for the help in advance!!

Contents

The question has already been discussed here.

Possibly after it's been dealt with in 2011, the following canned solution has become available in `R`:

``library(KScorrect) qmixnorm(.95, c(0,2,5,10), c(1,1,1,1), c(.5,.25,.2,.05)) ``

Here, the first entry is the quantile, followed by the vector of means, standard deviations and weights (see https://rdrr.io/cran/KScorrect/man/dmixnorm.html).

``> qmixnorm(.95, c(0,2,5,10), c(1,1,1,1), c(.5,.25,.2,.05)) [1] 7.745521 ``