Java中带有矩阵的多元线性回归

时间:2018-08-15 16:00:03

标签: java regression linear-regression apache-commons-math

我是一位定量新手,试图使用Java中的apache通用数学库来计算回归系数。我正在尝试使用OLSMultipleLinearRegression类来估计多元线性回归模型的回归系数和残差,该模型定义了一个regressand y,它是[nX1]状态向量。观察值或回归值由状态矢量x定义,该状态矢量x又是[nX1]状态矢量。带有样本数据的测试如下所示:

//n=3
double[][] y = new double[][]{{-0.03125,0.0078125,0.0.0.0,0.015625},
                           {-0.03125,0.0078125,0.0.0.0,0.015625},
                           {-0.03125,0.0078125,0.0.0.0,0.015625}};

//n=3
double[][] x = new double[][]{{+0.03195,-0.005812,0.0.0.0,0.015925},
                           {-0.03125,0.0079125,0.0.0.0,0.025625},
                           {-0.03195,0.0078825,0.0.0.0,-0.015625}};

OLSMultipleLinearRegression r = new OLSMultipleLinearRegression()
r.setNoIntercept(true)
r.newSampleData(y,x) //compiler error. 

回归器x由5个独立的状态变量组成,这些变量在给定的时间t处捕获。多元回归模型将尝试使用如上所述的历史数据确定的回归系数来预测状态y或t + 1处的回归。

如何将这种性质的数据输入模型?如果对您来说这听起来微不足道或显而易见,请提前道歉,我们将不胜感激。

0 个答案:

没有答案