::STSA::
 > Overview > Examples > PowerPoint Overview > O-Matrix Product Page > Online manual > Function reference

Other Toolboxes
 > Signal Processing > Image Processing > SigmaPlot Interface Toolkit > Linear Programming > ODBC/SQL Data Access > Data Visualizer

Example 11 - Problem Description

Constructing the trajectory matrix, applying SVD decomposition and reconstruction of trend and seasonal using unemployment data.

O-Matrix source code for example 11
``` clear ginit clc # Read and format the data series - note that we divide the series by 1e+4 for better graph viewing data = read("data\subbrao3.dat","double",50,8) data = nonzeros(reshape(data(4::end,:)',47*8,1))/1e+4 # Start from April as in the reference book data = data(4::end) # Construct the trajectory matrix and apply SVD decomposition M = 180 T = make_trajectory(data,M) [L,Q] = decompose_trajectory(T) # Plot the first 50 eigenvalues of the decomposition eigenvalue_plot(L,50) # Reconstruct the trend using the eigenvalues of the reference book hvec1 = { 1, 2, 5, 6, 7, 10, 11, 14, 15, 20, 21, 24, 27, 30, 33 } [F1,f1] = reconstruct_trajectory(T,L,Q,hvec1) # Plot the data and the fitted trend gaddwin("Data and Fitted Trend") gxaxis("linear",0,380,10) gxgrid("major") gygrid("major") gcolor({"black","red"}) gplot([data,f1]) # Now reconstruct the seasonal component using the eigenvalues of the reference book hvec2 = { 3, 4, 8, 9, 12, 13, 16, 17, 18, 19, 22, 23, 25, 26, 34, 35, 43, 44, 71, 72 } [F2,f2] = reconstruct_trajectory(T,L,Q,hvec2) # Plot the seasonal component gaddwin("Seasonal Component") gxaxis("linear",0,380,10) gxgrid("major") gygrid("major") gcolor({"black","red"}) gplot(f2) # If the separation of the two components (trend and seasonal) is successful then their weighted correlation should be small wcorr = weighted_correlation2(f1,f2,M) print "Weighted correlation between trend and seasonal components = ",wcorr # Here we provide an illustration about the selection of the particular eigenvalues # # For trend extraction one utilizes the indices corresponding to slowly varying eigenvectors: we take for example 1, 2, 7, 15 and 33 gaddwin("Sample Eigenvectors Corresponding to Trend") gaddview(0.,0.5,1.,0.5) gxaxis("linear",0,M,10) gtitle("Eigenvectors 1 and 2") gcolor({"black","red","green"}) gplot(Q(:,{1,2})) gaddview(0.,0.,1.,0.5) gxaxis("linear",0,M,10) gtitle("Eigenvectors 7, 15 and 33") gcolor({"black","red","green"}) gplot(Q(:,{7,15,33})) # For seasonal/cyclical component extraction one utilizes indicies corresponding to oscillating eigenvectors/eigenvector pairs that form # cyclical or other regular patterns: we take for example 3, 4, 8, 17 and 72 gaddwin("Sample Eigenvectors Corresponding to Seasonality") gaddview(0.,0.5,1.,0.5) gxaxis("linear",0,M,10) gtitle("Eigenvectors 3 and 4") gcolor({"black","red","green"}) gplot(Q(:,{3,4})) gaddview(0.,0.,1.,0.5) gxaxis("linear",0,M,10) gtitle("Eigenvectors 8, 17 and 72") gcolor({"black","red","green"}) gplot(Q(:,{8,17,72})) # Now in pairs gaddwin("Eigenvector pairs corresponding to seasonality") gaddview(0.,0.,0.5,1.) gtitle("Eigenvectors 3 and 4") gcolor("red") gplot(Q(:,3),Q(:,4)) gaddview(0.5,0.,0.5,1.) gtitle("Eigenvectors 4 and 8") gcolor("green") gplot(Q(:,4),Q(:,8)) ```

Example 11 - Output