0

I am a quant newbie trying to compute regression coefficients using apache common math libraries in Java. I am trying to use OLSMultipleLinearRegression class to estimate the regression coefficients and residuals for a multiple linear regression model which defines a regressand y which is a [nX1] state vector. The observations or regressors are defined by a state vector x which is again a [nX1] state vector. A test with sample data looks as follows:

//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. 

The regressor x is composed of 5 independent state variables which is captured at a given time t. The multiple regression model will attempt to predict a state y or the regressand at t+1 using the regression co-efficients which I am trying to determine using historical data as shown above.

How do I input data of this nature to the model? Apologies in advance if any of this sounds trivial or obvious to you but any help would be much appreciated.

K.Nicholas
  • 10,956
  • 4
  • 46
  • 66
  • 1
    Ignoring your syntax errors (such as missing semi colons) - the method you are trying to call has the following signature: public void newSampleData(double[] y, double[][] x) -- so 'y' cannot be 'double[][]' - only 'double[]'. So before we start getting the syntax right - you need a better understanding of what you are trying to achieve. – tbsalling Aug 15 '18 at 19:11
  • Sorry about the syntax errors of the missing semicolons. The idea is if I have a machine state composed of 5 variables & each of those are measured at x(k-1) & x(k) resulting in 2 double arrays with 5 measurements each then I need to find the regression coefficient between x(k-1) & x(k) to then predict x(k+1) which needs to be a 5 element array. How do I use OLSMuitpleLinearRegression to achieve the same? Hope that explains it better? – quantnewbie Aug 16 '18 at 09:13

0 Answers0