DolphinDB:求残差

比如我现在有这样的数据,我希望创建一个新列,这列数据对应的是每行数据和一个固定的array进行ols回归得到的残差,可以怎么做?

image

阅读 1.6k
1 个回答

在这个场景中,主要是通过高阶函数each对应每一个数据来计算残差:

t=table(2020.11.01 2020.11.02 as date, `IBM`MSFT as ticker, 1.0 2 as past1, 2.0 2.5 as past3, 3.5 7 as past5, 4.2 2.4 as past10, 5.0 3.7 as past20, 5.5 6.2 as past30, 7.0 8.0 as past60);

mt = matrix(t[`past1`past3`past5`past10`past20`past30`past60]).transpose();
benchX = 10 15 7 8 9 1 2.0;
t[`residual] = each(def(y, x){ return ols(y, x, true, 2).ANOVA.SS[1]}{,benchX}, mt)
推荐问题
logo
101 新手上路
子站问答
访问
宣传栏