0

I am trying to generate a bivariate sample from a mixture of two component distributions viz., normal and gamma distributions. I am using the 'copula' package for that.

The code I wrote is as follows-

library("copula")

mycop = normalCopula(param=c(0), dim=2, dispstr="ex")
mymvd = mvdc(
  copula=mycop, 
  margins=c("norm", "norm"),
  paramMargins=list(list(mean=-1, sd=0.5),list(mean=1, sd=0.5)))

This gave a bivariate sample from Normal(-1,1,0.5^2,0.5^2,0). The same code with exponential will lead give a bivariate sample from that distribution. But I don't know how to generate from w*BivariateNormal + (1-w)*BivariateGamma. Please help. I searched everywhere in yt but couldn't find anything. Thanks in advance.

Tim
  • 697
  • 2
  • 9

1 Answers1

1

In general, you sample from a mixture of two distributions by:

  • Generating a uniform(0, 1) variate (runif in R), then
  • Sampling from the first distribution if that variate is less than w, or
  • Sampling from the second distribution otherwise.

Similarly, you sample from a mixture of multiple distributions by generating a uniform, or non-uniform random integer, then sampling from a distribution depending on the integer chosen.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • Suppose I want to sample from 0.3* Normal((0,0),diag(2,2)) + 0.7* Gamma(shape=(2,2), rate=(1,1)) where 0.3 and 0.7 are corresponding weights of the marginals. Can you please kindly explain what to do after generating a sample from Unif(0,1)? – Rituparna Dey Jun 13 '21 at 14:34
  • In your example, compare the uniform variate `U` with 0.3. If `U` is less than 0.3, sample from `Normal(...)`. Otherwise, sample `Gamma(...)`. In this way, you sample from `Normal(...)` with probability 3/10, and from `Gamma(...)` with probability 7/10. – Peter O. Jun 13 '21 at 15:49