[R] Creating q and p functions from a self-defined distribut
(Ted Harding)
ted.harding at nessie.mcc.ac.uk
Thu Mar 15 14:26:52 CET 2007
On 15-Mar-07 12:09:42, Eli Gurarie wrote:
> Hello all,
>
> I am fishing for some suggestions on efficient ways to make qdist and
> pdist type functions from an arbitrary distribution whose probability
> density function I've defined myself.
>
> For example, let's say I have a distribution whose pdf is:
>
> dRN <- function(x,d,v,s)
># d, v, and s are parameters
> return(d/x^2/sv/sqrt(2*pi)*exp(-(d-v*x)^2/2/(sv^2*x^2)))
>
> this is a legitimate distribution over the reals (though it has a
> singularity at x=0)
> [...]
> It seems surprising that it would be so hard to invert a function that
> is perfectly defined!
>
> Are there packages/functions/algorithms that allow one to manipulate
> arbitrarily defined distributions?
Do not be surprised! The Normal distribution function itself, with
pdf (1/(sv*sqrt(1*pi)))*exp(-((x - mu)^2)/(2*sv^2)), is perfectly
well defined. Yet the literature of computation over decades has
presented procedure after procedure for computing the cumulative
fucntion, and its inverse, to desired precision. None of these is
simple. Indeed, (to use your own word), the Normal distribution
is a "nightmare" from this point of view.
So being well-defined is no guarantee that computing its p and q
values will be a simple or easy problem. And what kind of method
is good for a particular distribution will depend strongly on
what the distribution is (for instance, whether it has tails
which tend rapidly to 0 like the Normal, whether there are good
asymptotic formulae, etc.).
In the case of the example you give above, the transformation
from x to u = 1/x will translate it into a Normal distribution
problem, after which you can use (circumspectly ... ) the R
functions pnorm and qnorm (which are based on the best from
the above literature) to deal with it.
But you give it only as an example ... and you are asking for
methods for a general user-defined distribution. For the reasons
given above, a good general-purpose method is unlikely to exist.
With best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 15-Mar-07 Time: 13:26:27
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list