Suppose one wanted to consider random variables X_1,...X_n and from each subtract off the piece which is correlated with the previous variables in the list. i.e. make new variables Z_i so that Z_1=X_1 and Z_i=X_i-cov(X_i,Z_1)Z_1/var(Z_1)-...- cov(X_i,Z__{i-1})Z__{i-1}/var(Z_{i-1})  I have code to do this but I keep getting a "non-conformable array" error in the line with the covariance.  Does anyone have any suggestions?  Here is my code:

gov=read.table(file.choose(), sep="\t",header=T)

gov1=gov[3:length(gov[1,])]
n_indices=length(names(gov1))

x=data.matrix(gov1)


v=x
R=matrix(rep(0,length(x[,1])*length(x[1,])),length(x[,1]))

for(j in 1:n_indices){
   u=matrix(rep(0,length(v[,1])),length(v[,1]))

for(i in 1:j-1){
   u = u+cov(v[,j],v[,i])*v[,i]/var(v[,i])                #(error here)
   }
   v[,j]=v[,j]-u

}

Thanks,
                Andrew



	[[alternative HTML version deleted]]

