Example: TimeSeriesFilter

In this example a matrix with 5 rows and 2 columns is lagged twice. This produces a two-dimensional matrix with 5 rows, but 2*3=6 columns. The first two columns correspond to lag=0, which just places the original data into these columns. The 3rd and 4th columns contain the first lags of the original 2 columns and the 5th and 6th columns contain the second lags.

import com.imsl.stat.*;
import com.imsl.math.*;
import com.imsl.datamining.neural.*;

public class TimeSeriesFilterEx1 {
    public static void main(String args[]) throws Exception {
        TimeSeriesFilter filter = new TimeSeriesFilter();
        int nLag = 2;
        double[][] x = {
            {1, 6},
            {2, 7},
            {3, 8},
            {4, 9},
            {5, 10}
        };
        double[][] z = filter.computeLags(nLag, x);
         // Print result without row/column labels.
        PrintMatrix pm = new PrintMatrix();
        PrintMatrixFormat mf;
        mf = new PrintMatrixFormat();
        mf.setNoRowLabels();
        mf.setNoColumnLabels();
        pm.setTitle("Lagged data");
        pm.print(mf, z);
    }
}

Output

     Lagged data
                     
1  6  2  7  3   8  
2  7  3  8  4   9  
3  8  4  9  5  10  

Link to Java source.