In DolphinDB, how to perform multiple regression by using metaprogramming?

18 views Asked by At

I intend to use metaprogramming to perform multiple regression on several columns, but an error occurs.

My script:

sql(sqlColAlias(makeUnifiedCall(toArray, makeUnifiedCall(ols, (sqlCol(`rr), sqlCol(t.columnNames()[12:16]), false, 0))), `param), from=t.nullFill(0.0), groupBy=sqlCol(`month`symbol)).eval() 

Error message:

::evaluate(sql(sqlColAlias(makeUnifiedCall(toArray, makeUnifiedCall(ols, (sqlCol("rr"), sqlCol(::columnNames(t)[12 : 16]), 0, 0))), "param"), ::nullFill(t, 0), , sqlCol(["month","tsymbol"]))) => The dimension of dependent doesn't match the dimension of independent factors.

Then I change my script as follows, which runs normally.

sql(sqlColAlias(makeUnifiedCall(rowSum, sqlCol(t.columnNames()[12:16])), `newCol), t.nullFill(0.0)).eval()
1

There are 1 answers

0
Claire On BEST ANSWER

In metaprogramming, it is necessary to combine multiple columns into a matrix, instead of a tuple; otherwise, the script may not be parsed normally. Here is an example script:

x = `x+string(1..3)
residual = makeCall(member, makeCall(ols, sqlCol(`factor0), makeUnifiedCall(matrix, sqlCol(x)), 1, 2), "Residual")
sql(residual, t).eval()