Changes

Jump to navigation Jump to search
var_pop(expression) | smallint, int, bigint, real, double precision, or numeric| double precision for floating-point arguments, otherwise numeric| population variance of the input values (square of the population standard deviation)
var_samp(expression) | smallint, int, bigint, real, double precision, or numeric| double precision for floating-point arguments, otherwise numeric| sample variance of the input values (square of the sample standard deviation)
 
=== Sample call of an aggregate function ===
 
SELECT regr_slope(tothullcount, avghullcount) FROM hcllayerwinv;
 
==== Output ====
regr_slope
------------------
2.31850202053387
(1 row)
==Joe Conway's Documentation on pl/r==
3
(1 row)
 
=== Attempts to call R built-in function from PSQL ===
 
==== Regression ====
 
Creating Function:
 
CREATE OR REPLACE FUNCTION r_reg(y numeric[], x numeric[])
RETURNS numeric AS $$
res <- lm(y ~ x)
return(coef(res)[1])
$$ LANGUAGE 'plr' immutable;
 
Calling Function:
 
SELECT r_reg(tothullcount, avghullcount) from hcllayerwinv;
 
Results:
 
r_reg
-------
0
0
3
0
5
4
0
0
5
4
0
0
6
4
4
0
0
4
0
0
4
0
0
4
0
0
3
0
5
3
0
0
7
5
3
3
0
0
6
4
0
0
0
5
4
0
0
7
== hcllayerwinv table from tigertest database ==
337

edits

Navigation menu