Thread: Covariance Function in Postgresql??

Covariance Function in Postgresql??

From
jonathan.nichols@sbcglobal.net (Jonathan Nichols)
Date:
Hello,

    I'm looking to take the covariance of two columns in a postgresql
table.  I know there are sum, average, variance and standard deviation
functions.  Is there a covariance function hiding somewhere?

thanks,

jon

Re: Covariance Function in Postgresql??

From
Joe Conway
Date:
Jonathan Nichols wrote:
>     I'm looking to take the covariance of two columns in a postgresql
> table.  I know there are sum, average, variance and standard deviation
> functions.  Is there a covariance function hiding somewhere?

There is no built in aggregate for covariance. In fact, there is no
notion of an aggregate that works across two columns (at least that I'm
aware of). But you could use PL/R to create a function that executes a
sql statement and calculates covariance. For more on PL/R, see:
http://www.joeconway.com/

HTH,

Joe