Hello Does anybody know how one can compute d largest eigenvalues/eigenvectors in R, like in MATLAB eigs function ? eigen function computes all eigenvectors/eigenvalues, and they are slightly different than those generated by matlab eigs. Thanks in advance -- View this message in context: http://www.nabble.com/matlab-eigs-function-in-R-tp17619641p17619641.html Sent from the R help mailing list archive at Nabble.com.
Dear kayteck, Function eigen (see ?eigen) will do what you want. HTH, Jorge On Tue, Jun 3, 2008 at 5:42 AM, kayteck_master <kayteck_master@o2.pl> wrote:> > Hello > > Does anybody know how one can compute d largest eigenvalues/eigenvectors in > R, like in MATLAB eigs function ? eigen function computes all > eigenvectors/eigenvalues, and they are slightly different than those > generated by matlab eigs. > > Thanks in advance > -- > View this message in context: > http://www.nabble.com/matlab-eigs-function-in-R-tp17619641p17619641.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
"Jorge Ivan Velez" <jorgeivanvelez at gmail.com> wrote in news:317737de0806030529t50fdced9r49156de606a0d198 at mail.gmail.com:> Dear kayteck, > > Function eigen (see ?eigen) will do what you want. > > HTH,He had looked, but since eigen returns both eigenvalues and eigenvectors, and does so in a list, perhaps he needs advice about how to extract his values from the list structure. x <- matrix(c(1:5, (1:5)^2, (1:5)^(1/2), 0,0,0,1,0, 0,0,0,0,1),5, 5) str(eigen(x)) #List of 2 # $ values : cplx [1:5] 7.43+0i 1.00+0i 1.00+0i ... # $ vectors: cplx [1:5, 1:5] 0.0699+0i 0.1600+0i 0.2894+0i ... d <- 3 eigen(x)$values[1:d] [1] 7.431675+0i 1.000000+0i 1.000000+0i #no need to sort since eigen does that by default. Not sure we can help him out regarding the "slight difference" btwn Matlab values and R values due to the unnecessary vagueness of his concern. -- David Winsemius> > Jorge > > > On Tue, Jun 3, 2008 at 5:42 AM, kayteck_master > <kayteck_master at o2.pl> wrote: > >> >> Hello >> >> Does anybody know how one can compute d largest >> eigenvalues/eigenvectors in R, like in MATLAB eigs function ? eigen >> function computes all eigenvectors/eigenvalues, and they are >> slightly different than those generated by matlab eigs. >> >> Thanks in advance >> -->
Presumably the original poster was looking for a function that would compute just the largest five eigenvalues and associated vectors, because that is enormously more efficient for a large matrix than computing all of them. eigen() computes all of them. One way to compute just a few is to use svd(), where you can specify the number of left and right singular vectors to compute. -thomas On Tue, 3 Jun 2008, David Winsemius wrote:> "Jorge Ivan Velez" <jorgeivanvelez at gmail.com> wrote in > news:317737de0806030529t50fdced9r49156de606a0d198 at mail.gmail.com: > >> Dear kayteck, >> >> Function eigen (see ?eigen) will do what you want. >> >> HTH, > > He had looked, but since eigen returns both eigenvalues and > eigenvectors, and does so in a list, perhaps he needs advice about how > to extract his values from the list structure. > > x <- matrix(c(1:5, (1:5)^2, (1:5)^(1/2), 0,0,0,1,0, 0,0,0,0,1),5, 5) > > str(eigen(x)) > #List of 2 > # $ values : cplx [1:5] 7.43+0i 1.00+0i 1.00+0i ... > # $ vectors: cplx [1:5, 1:5] 0.0699+0i 0.1600+0i 0.2894+0i ... > > d <- 3 > > eigen(x)$values[1:d] > > [1] 7.431675+0i 1.000000+0i 1.000000+0i > > #no need to sort since eigen does that by default. > > Not sure we can help him out regarding the "slight difference" btwn > Matlab values and R values due to the unnecessary vagueness of his > concern. > > -- > David Winsemius > > >> >> Jorge >> >> >> On Tue, Jun 3, 2008 at 5:42 AM, kayteck_master >> <kayteck_master at o2.pl> wrote: >> >>> >>> Hello >>> >>> Does anybody know how one can compute d largest >>> eigenvalues/eigenvectors in R, like in MATLAB eigs function ? eigen >>> function computes all eigenvectors/eigenvalues, and they are >>> slightly different than those generated by matlab eigs. >>> >>> Thanks in advance >>> -- > >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle