Re: standard normal cumulative distribution function - Mailing list pgsql-general

From Michael Fuhr
Subject Re: standard normal cumulative distribution function
Date
Msg-id 20060121191209.GA62176@winnie.fuhr.org
Whole thread Raw
In response to Re: standard normal cumulative distribution function  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
On Fri, Jan 20, 2006 at 04:54:00PM -0700, Michael Fuhr wrote:
> On Sat, Jan 21, 2006 at 12:00:49AM +0100, SunWuKung wrote:
> > Does somebody have/know of a function for pg returning the standard
> > normal cumulative distribution for a Z score?
>
> Are you looking for something like this?
>
> test=> SELECT z, cdf_ugaussian_p(z) FROM generate_series(-3, 3) AS g(z);

You can also do this with the R language, which you can access from
PostgreSQL via PL/R.

http://www.r-project.org/
http://www.joeconway.com/plr/

CREATE FUNCTION pnorm(z double precision) RETURNS double precision AS $$
return(pnorm(z))
$$ LANGUAGE plr IMMUTABLE STRICT;

SELECT z, pnorm(z) FROM generate_series(-3, 3) AS g(z);
 z  |        pnorm
----+---------------------
 -3 | 0.00134989803163009
 -2 |  0.0227501319481792
 -1 |   0.158655253931457
  0 |                 0.5
  1 |   0.841344746068543
  2 |   0.977249868051821
  3 |    0.99865010196837

--
Michael Fuhr

pgsql-general by date:

Previous
From: Stephan Vollmer
Date:
Subject: Re: Creation of tsearch2 index is very slow
Next
From: "Sander Steffann"
Date:
Subject: Re: RAID 5 and postgresql