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 21:53:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 63
Message-ID: <fp2d7u$1eh$1@fred.mathworks.com>
References: <fp1qjo$ka8$1@fred.mathworks.com> <fp24vh$49a$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203025982 1489 172.30.248.37 (14 Feb 2008 21:53:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 Feb 2008 21:53:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:451494


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in 
message <fp24vh$49a$1@fred.mathworks.com>...
>   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
-------
  I should have warned you that matlab's numerical quadrature functions 
cannot actually accept infinite limits.  in your problem you will have to use a 
finite limit that is sufficiently large to encompass all the areas with significant 
probability densities, but not so large as to confuse the routine into taking 
too few samples of the integrands in the critical areas to attain the needed 
accuracy.  These routines don't seem to be particularly robust in this regard.  
You'll have to experiment with them a bit.

Roger Stafford