[R] Orthogonalization with different inner products
Michael Friendly
friendly at yorku.ca
Thu Nov 4 13:34:16 CET 2010
See gsorth() in the heplots package.
On 11/3/2010 1:55 PM, adetzel at uw.edu wrote:
> 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]]
>
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca
Toronto, ONT M3J 1P3 CANADA
More information about the R-help
mailing list