Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: random number generator from logistic distribution
Date: Wed, 30 Jan 2008 10:40:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 61
Message-ID: <fnpk66$gq7$1@fred.mathworks.com>
References: <fnod3l$po$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1201689606 17223 172.30.248.38 (30 Jan 2008 10:40:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 30 Jan 2008 10:40:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:448262


"Jessica " <jandre@mathworks.com> wrote in message <fnod3l$po
$1@fred.mathworks.com>...
> Hi,
> I'm trying to create a random number generator from the 
> logistic distribution. Does the following function look 
> right or am I completely off track?!
> 
> r=lrnd(m,n,mu,sigma)
> p=rand(m,n)
> r=log(p./(1-p)).*sigma+mu
> 
> Thanks for your help
> 
> Jess
--------
  Because you expressed doubt about the validity of the method in your 
logistic distribution generator, Jessica, I have decided that it would be 
appropriate to show details of the reasoning behind it.

  You defined the random variable p in terms of matlab's 'rand' function:

 p = rand

(forget for a moment that your p is actually an m by n array) and the random 
variable r in terms of p as:

 r = f(p) = log(p/(1-p))*s+m

This is easily shown to be mathematically equivalent to saying

 p = f_inverse(r) = 1/(1+exp(-(r-m)/s))

Then we can write the cumulative distribution of r as:

 P{r <= c} = P{f(p) <= c} = 
 P{p <= f_inverse(c)} = P{p <= 1/(1+exp(-(c-m)/s)

This holds because f is a monotonically increasing function so that

 f(p) <= c

is equivalent to

 p <= f_inverse(c)

and so have equal probabilities.  Next notice that random variable p = rand 
has the important special property that P{p <= t} is always equal to t itself for 
any t in 0 <= t <= 1, because MathWorks has gone to great lengths to ensure 
that rand is uniformly distributed from 0 to 1.  Thus, applying this to t = 1/(1
+exp(-(c-m)/s)), we have

 P{r <= c} = P{p <= 1/(1+exp(-(c-m)/s))} = 1/(1+exp(-(c-m)/s))

Therefore r has the required cumulative logistic distribution.

  The same kind of reasoning applies to any random variable which is to be 
defined in terms of the special random variable p = rand.  One simply applies 
the inverse of the desired cumulative distribution function to p.

Roger Stafford