[R] Higher Dimensional Matrices

downunder larsfromspace at web.de
Mon Dec 25 03:30:44 CET 2006


Hi all.

I want to calculate partial correlations while controlling for one or more
variables. That works already fine when I control for example just for x[,1]
and x[,2] that gives me one single correlation matrix and i have to to it
for 
x [,1]...x[,10]. That would give me out 10 matrices. Controlling for 2
Variables 100 matrices. how  
can I run a loop to get f.e the 10 or 100 matrices at once? I appreciate for
every hint. have nice holidays. 

greetings lars

x<-read.table("C:/.....dat")
dim(x) #200x10
a<-matrix(0,200,10)
for (i in 1:10)
a[,i] <- residuals(lm(x[,i]~1+x[,1]+x[,2]))
b<-matrix(0,200,10)
for (i in 1:10)
b[,i] <- residuals(lm(x[,i]~1+x[,1]+x[,2]))
#a=round(a,5)
#b=round(b,5)
d=cor(a,b)
d
-- 
View this message in context: http://www.nabble.com/-R--Higher-Dimensional-Matrices-tf2878430.html#a8044673
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list