[R] extracting the first few eigenvectors

Mike Miller mbmiller+l at gmail.com
Sat May 3 03:09:31 CEST 2014


Thank you, and thanks for writing that code!  That is the perfect answer 
to my question.  I hope the R development team will consider expanding the 
functionality of eigen() to include the option to retain only the first 
few eigenvectors and/or eigenvalues.  To me it seems very common in 
statistics to work with a few eigenvectors instead of with all of them.

Mike


On Fri, 2 May 2014, Yixuan Qiu wrote:

> Exactly.
> The syntax is intended to mimic eigs() in Matlab and Octave.
>
> library(rARPACK)
> eigs(X, 10)           # If your X is of class "dsyMatrix"
> eigs_sym(X, 10)   # If X is of class "matrix"
>
>
> Best,
> Yixuan
>
> 2014-05-02 4:48 GMT-04:00 Berend Hasselman <bhh at xs4all.nl>:
>>
>> On 02-05-2014, at 09:17, Mike Miller <mbmiller+l at gmail.com> wrote:
>>
>>> I have a symmetric matrix, X, and I just want the first K eigenvectors (those associated with the K largest eigenvalues).  Clearly, this works:
>>>
>>> eigs <- eigen( X, symmetric=TRUE )
>>>
>>> K_eigenvectors <- eigs$vectors[ , 1:K ]
>>> K_eigenvalues <- eigs$values[ 1:K ]
>>>
>>> rm(eigs)
>>>
>>> In order to do that, I have to create the matrix eigs$vectors which is the same size as X.  Sometimes X has 100 million elements or more.  Usually I want only the first 10 eigenvectors instead of all 10,000.  Is there any R function that will allow me to extract just the few that I want?  This would be analogous to the [V,d] = eigs(X,K) function in Octave/MATLAB.
>>>
>>
>> You can find possibly relevant stuff with
>>
>> library(sos)
>> findFn("eigenvalue”)
>>
>> which is how I found package rARPACK, which may be exactly what you need/want.
>>
>> Berend
>>
>>> Best,
>>> Mike


More information about the R-help mailing list