MLINREG - composable from SUM and COUNT

General

MLINREG - composable from SUM and COUNT

Hi All,

I need MLINREG calculation logic using SUM and COUNT functions.Alternatively can it be calculated some other Window functions?

If someone has already tried it please send the query.

It's kind of urgent.

I would really appriciate your quick response.

Thanks,

Anushree

1 REPLY
Senior Apprentice

Re: MLINREG - composable from SUM and COUNT

Hi Anushree,

MLINREG uses a least squares linear regression, which can be rewritten using INTERCEPT and SLOPE:

MLINREG(valcol,n,sortcol)

REGR_SLOPE(sortcol,valcol)
OVER (PARTITION BY items
ORDER BY valcol
ROWS BETWEEN n-1 PRECEDING AND 1 PRECEDING) * valcol
+
REGR_INTERCEPT(sortcol,valcol)
OVER (PARTITION BY itemid
ORDER BY valcol
ROWS BETWEEN n-1 PRECEDING AND 1 PRECEDING)