Search code examples
sassas-iml

IML correlation from different matrices


given a matrix X(n * p), I want to split X into Y1(n * p-k) and Y2(n * k), where Y1 is composed by the first k columns of X and Y2 the others.

Now, in R I can get the "crossed" correlation between the columns of Y1 and Y2 calling cor(Y1,Y2, use="pairwise.complete.obs"), how can I get the same result in SAS IML where the corr function admits only 1 dataset?

I tried to find an appropriate solution or algorithm to implement it but with bad results.

Can anyone help with this? Also pointing me some literature about this kind or correlation would be great! I don't want you to code it for me, simply some help or hint on existing functions or algorithms to translate.

Thank you.

EDIT: don't search on the web for crossed correlation, I wrote it simply for trying to explain myself.


Solution

  • Looking up "crossed correlation" leads you to a series of literature on signal processing and a function much like the autocorrelation function. In fact, in R it is documented with acf https://stat.ethz.ch/R-manual/R-devel/library/stats/html/acf.html.

    But that is not what your code is doing. In R:

    n = 100
    p = 6
    k = 2
    
    set.seed(1)
    
    r = rnorm(n*p)
    x= matrix(r,n,p)
    
    y1 = x[,1:k]
    y2 = x[,(k+1):p]
    
    cor.ys = cor(y1,y2,use="pairwise.complete.obs")
    
    cor.x = cor(x)
    
    (cor.ys - cor.x[1:k,(k+1):p])
    

    You see the result from cor(y1,y2) is just a piece of the correlation matrix from x.

    You should be able to put this in IML easily.