Skip to main content

Utility Functions

Helper functions and basic metrics.

Basic Metrics

SELECT ols_r2(y, ARRAY[x1, x2]) as r_squared FROM data;

Goodness of fit (0-1)

RMSE

SELECT ols_rmse(y, ARRAY[x1, x2]) as rmse FROM data;

Root mean squared error

MSE

SELECT ols_mse(y, ARRAY[x1, x2]) as mse FROM data;

Mean squared error


Type Conversions

SQL array operations for working with STRUCT results:

-- Extract coefficients
SELECT result.coefficient[2] FROM ...

-- Extract with field names
SELECT result.p_value[2] as p_val FROM ...

Common Patterns

Extracting All Coefficients

SELECT
result.coefficient[1] as intercept,
result.coefficient[2] as x1_effect,
result.coefficient[3] as x2_effect
FROM ...;

Filtering by Significance

SELECT * FROM ...
WHERE result.p_value[j] < 0.05;

Next Steps

🍪 Cookie Settings