/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
- Original Message -
From: Vumani Dlamini [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Wednesday, March 23, 2005 2:53 PM
Subject: [R] sampling from
For each variate, generate it from f1() with probability p1, and from
f2() with probability p2. In other words, flip a p1-biased coin to
decide which distribution, f1 or f2, to generate from.
HTH,
Giovanni
Date: Wed, 23 Mar 2005 13:53:10 +
From: Vumani Dlamini [EMAIL PROTECTED]
Sender:
Here's one possible way:
rmix2 - function(n, p1, rF1, rF2, argF1=NULL, argF2=NULL) {
## n is the number of deviates to simulate
## p1 is the probability of a point coming from the 1st component
## rF1, rF2 are functions for generating random deviates
## from the two components
I would like to sample from a mixture distribution p1*f(x1)+p2*f(x2).
***Surely*** you mean ``p1*f1(x)+p2*f2(x)'' !!!
I usually sample variates from both distributions and weight them
with their respective probabilities, but someone told me that was
wrong. What is the correct way?