beta
Syntax
beta(Y, X, [intercept=true])
Details
Return the coefficient estimate of an ordinary-least-squares regression of Y on X (with intercept).
Difference from Python’s scipy.stats.beta:
scipy.stats.beta is a beta continuous random variable object for
calculating probability density, distribution functions, random variates, and
related statistics. DolphinDB’s beta is a statistical
regression function that returns the OLS regression coefficient of Y on
X.
Difference from Python TA-Lib’s BETA: TA-Lib’s BETA(high,
low, timeperiod=5) is a rolling technical-analysis statistic. It
calculates beta on the rate-of-change series of high and low over each
window and does not support specifying whether to include an intercept term.
DolphinDB’s beta(Y, X) calculates one OLS regression coefficient
over the full input when vectors are specified and supports specifying whether to
include an intercept term via the intercept parameter. To reproduce TA-Lib’s
indicator behavior, use DolphinDB’s TA module ta::beta.
Parameters
Y and X are numeric vectors of the same length, matrices of the same dimensions, or tables. If X is a table, only its numeric and Boolean columns are used in the calculation.
intercept (optional) is a BOOL scalar, default true. It specifies whether the linear regression includes an intercept term. If set to false, the intercept is fixed at 0, resulting in a regression through the origin.
Returns
A DOUBLE scalar/vector/table.
Examples
x=1 3 5 7 11 16 23
y=0.1 4.2 5.6 8.8 22.1 35.6 77.2;
beta(y,x);
// output: 3.378632
x=1 3 5 7 11 16 23
y=0.1 4.2 5.6 8.8 22.1 35.6 77.2;
beta(y,x);
// output: 3.378632
// By default, intercept=true, which includes an intercept term.
beta(y, x, true)
// output: 3.378632
// intercept=false excludes the intercept term (regression through the origin).
beta(y, x, false)
// output: 2.717778
