Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Calculating cumulative probability
Date: Thu, 14 Feb 2008 19:32:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 70
Message-ID: <fp24vh$49a$1@fred.mathworks.com>
References: <fp1qjo$ka8$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203017521 4394 172.30.248.35 (14 Feb 2008 19:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 Feb 2008 19:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:451470


"Omkar Palsule-Desai" <omkardpd@iimahd.ernet.in> wrote in message 
<fp1qjo$ka8$1@fred.mathworks.com>...
> 
> Hi,
> 
> Say, X & Y are two independent continuous random variables 
> with known distribution functions. Both X & Y range on (-
> inf, +inf). I need to find following probability 
> 
> (X-Y<= k; Y>=0; X>Y)
> 
> Since, I have two random variables and there are three 
> conditions in joint distribution, I can not use 
> traditional probability concepts. 
> 
> I guess I can calculate probability by measuring volume 
> under the surfaces defined by X-Y<=k, Y>=0 and X>Y. Is 
> this a correct procedure?
> 
> If it is, then how do I calculate the volume using matlab? 
> Can someone help me with this?
> 
> Thank you
> 
> Omkar
--------
  Since you know X and Y to be independent random variables, your desired 
probability can be expressed as the iterated integral:

 P(k) = integral, 0 to inf, (integral, y to y+k, f(x)*g(y) dx) dy

where f(x) and g(y) are the respective probability density functions of X and Y.  
That is: the integral from 0 to infinity of the integral from y to y+k of the 
product f(x)*g(y), first with respect to x and then with respect to y.  (I would 
not have used the term "cumulative probability" to describe this particular 
probability, however.)  Unfortunately, matlab's 'dblquad' is unable to evaluate 
a double integral in this form where the inner limits of integration depend on 
the outer variable.

  I can see two possibilities for numerically calculating this using matlab.  
First, if you already know the cumulative distribution of X as a function, F(x), 
the above can then be directly expressed as the single integral:

 integral, 0 to inf, (F(y+k)-F(y))*g(y) dy

by direct substitution of F(y+k)-F(y) for the inner integral after factoring out 
the g(y).  Any of the matlab single quadrature functions can be used for this: 
'quad', 'quad8', etc.

  The other possibility is to make a change of variable.  Define

 u = x - y

Then the iterated integral can be converted to the form

 integral, 0 to inf, integral, 0 to k, f(u+y)*g(y) du dy

(Note that the Jacobian in this case is just 1.)  This is in a form that can be 
used by 'dblquad' since the inner limits are independent of y values.  This is 
the method you should use if you know only the two probability density 
functions.

  Note that each of these forms requires a separate numerical integration for 
each desired value of k.  There is always the possibility that, depending on 
the functions, f(x) and g(y), there may exist an analytic solution to these 
integrals using the 'int' function of the Symbolic Toolbox, but the odds are 
heavily against this I would think.

Roger Stafford