Re: Truncated version of lognormal distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg82779] Re: Truncated version of lognormal distribution
- From: Mark Fisher <particlefilter at gmail.com>
- Date: Wed, 31 Oct 2007 06:02:53 -0500 (EST)
- References: <fg6qj6$dks$1@smc.vnet.net>
On Oct 30, 4:39 am, P_ter <peter_van_summe... at yahoo.co.uk> wrote: > Hello, > did anyone program the truncated version of the lognormal distribution? Or have a reference how to do it? I would like to draw from such distribution. > For the truncated version of the gaussian distribution I only know about Myron Tribus (Rational Descriptions 1969). It has a nice explanation. It is not difficult to use that, but I need anyway some reference for the results. > What Tribus did by tens of BASIC lines, can now be done in three lines in Mathematica. That is for me also interesting to experience. > with friendly greetings, > P_ter Hi, Here is a simple way to draw from the truncated lognormal: fun[{m_, s_}, {min_, max_}] := Block[{r}, While[ r = RandomReal[LogNormalDistribution[m, s]]; !(min <= r <= max)]; r] (If you are using a version of Mathematica prior to 6, change RandomReal to Random.) This is an example of "importance sampling", whereby one makes draws from pdf f by drawing from pdf g and then resampling the draws using the weights w = f[#]/g[#]& /@ draws In this case, g is simply the pdf for the lognormal and f is proportional to g for draws that are in-bounds and zero for draws that are out-of-bounds. Thus, all out-of-bounds draws get a weight of zero (so these draws are discarded) and all in-bounds draws get the same positive weight (so these draws are all retained). For more general problems, one could use RandomChoice[w -> draws, Length[draws]] to resample the data. Unfortunately, RandomChoice does not allow zero- valued weights and thus one is forced to write code that traps for this. (I believe this is a design error. Perhaps the folks at WRI will rethink this decision in the fullness of time.) --Mark