[R] Is there an easy way to generate linearly independent vectors

Jonathan Baron baron at psych.upenn.edu
Fri Jun 18 02:45:57 CEST 2004


On 06/17/04 19:04, Fred wrote:
>Dear R-listers:
>
>I am trying to test an algorithm on a set of linearly independent vectors
>{x1,x2,...,xn}.

Well, here's an idea, for 10 vectors of length 10,
as columns of a matrix m1.  The 11th seems to be needed.

m1 <- matrix(rnorm(110),10,11)
for (i in 2:11) {
 m1[,i] <- resid(lm(m1[,i] ~ m1[, 1:(i-1)]))
}

Test it with cor(m1[,-11])

I'm sure there are better ways.

Of course
m1 <- matrix(rnorm(100),10,10)
is ALMOST what you want.

Jon
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page:            http://www.sas.upenn.edu/~baron




More information about the R-help mailing list