Tscancor <- function(z,lagmax=NULL) { # function to compute canonical correlation ARMA ID matrix # described in BJR pp. 197-200 # returns lagmax by lagmax matrix of canonical correlations # WARNING: NO GUARANTEE THAT THIS IS DEBUGGED. n_length(z) z0_z-mean(z) if(is.null(lagmax)) lagmax_ceiling(10*log10(n)) idmat_matrix(NA,nrow=lagmax,ncol=lagmax) for(m in 1:lagmax) { Ymt_z0[(m+1):n] for(k in 1:m) Ymt_cbind(Ymt,z0[(m+1-k):(n-k)]) for(j in 1:lagmax) { Y1_Ymt[(j+2):(n-m),] Y2_Ymt[1:(n-m-j-1),] temp_cancor(Y1,Y2) idmat[m,j]_min(temp$cor)^2 NULL } NULL } return(idmat) } Ymt <- function(z,m,j) { # function to set up Y1, Y2 matrices to # compute canonical correlation ARMA ID matrix # described in BJR pp. 197-200 n_length(z) Ymt_z[(m+1):n] for(k in 1:m) Ymt_cbind(Ymt,z[(m+1-k):(n-k)]) Y1_Ymt[(j+2):(n-m),] Y2_Ymt[1:(n-m-j-1),] return(Y1,Y2) }