Skip to content

REGR_R2

  • expr1: This is the dependent variable. In statistical terms, the dependent variable is the outcome or the one that is being tested. It is the variable whose variation depends on that of another. This should be a numeric or non-numeric field present in the Oracle database.
  • expr2: This is the independent variable. Statistically, the independent variable is the variable considered to cause, influence, or affect outcomes. It is the predictor variable in the regression analysis. It should also be a numeric or non-numeric field present in the Oracle database.
SELECT REGR_R2(sales, quantity) OVER (PARTITION BY store_id) as r2
FROM store_sales;
| R2
| -------------
| 0.9056284
| 0.8565223
| 0.9342156
| ...

This example demonstrates the use of REGR_R2() function in Oracle. The function calculates the square of the correlation coefficient (R2), indicating how closely the data in the sales column tracks the data in the quantity column for each store_id. The result, r2, is a value between 0 and 1. A higher value indicates a tighter correlation between sales and quantity.