Hi all, I am trying to perform some analysis on the residuals of pair-wise linear regressions between two large sets A with dimensions {k x m}, and B {k x n} . So I need to regress every column B[,j] of B on every column A[,i] of A and produce a matrix C with dimensions {m x n}, so that C[i,j] contains the z-score of the k-th (last) residual of the aforementioned linear regression.
I have tried the following code, but i don't seem to get it work. Moreover, any idea of using a for loop is disastrous since A and B are very large matrices. I'd be grateful for any suggestions! C <- apply( A[ ,1:dim(A)[2] ], 2, linRegZscore, y=A[ ,1:dim(A)[2]] ) where linRegZscore is the following function linRegUtility1 <- function(x,y){ regRes <- lm(y~x)$residuals ( regRes[dim(regRes)[1]]-apply(regRes, 2, mean) )/( apply(regRes,2, sd) ) } [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.