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

Liaw, Andy andy_liaw at merck.com
Fri Jun 18 02:50:24 CEST 2004


I believe eigen(), svd() and qr() can all do it.

Andy

> From: Jonathan Baron
> 
> 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