From p.dalgaard at biostat.ku.dk  Tue Jan 10 15:14:44 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 10 Jan 2006 15:14:44 +0100
Subject: [Rd] eigen()
In-Reply-To: <43C3B9DF.1090803@cimr.cam.ac.uk>
References: <3B7754B8-4982-49BE-B424-A0D9CFC6F056@soc.soton.ac.uk>
	<x2zmm49qb3.fsf@viggo.kubism.ku.dk> <43C3B9DF.1090803@cimr.cam.ac.uk>
Message-ID: <x2mzi49nl7.fsf@viggo.kubism.ku.dk>

Hin-Tak Leung <hin-tak.leung at cimr.cam.ac.uk> writes:

> Peter Dalgaard wrote:
> > Robin Hankin <r.hankin at noc.soton.ac.uk> writes:
> >
> >>Hi
> >>
> >>I am having difficulty with eigen() on   R-devel_2006-01-05.tar.gz
> >>
> >>Specifically,  in R-2.2.0 I get expected behaviour:
> >>
> >>
> >> > eigen(matrix(1:100,10,10),FALSE,TRUE)$values
> >>[1]  5.208398e+02+0.000000e+00i -1.583980e+01+0.000000e+00i
> >>[3] -4.805412e-15+0.000000e+00i  1.347691e-15+4.487511e-15i
> >>[5]  1.347691e-15-4.487511e-15i -4.269863e-16+0.000000e+00i
> >>[7]  1.364748e-16+0.000000e+00i -1.269735e-16+0.000000e+00i
> >>[9] -1.878758e-18+5.031259e-17i -1.878758e-18-5.031259e-17i
> >> >
> >>
> >>
> >>The same command gives different results in the development version:
> >>
> >>
> >> > eigen(matrix(1:100,10,10),FALSE,TRUE)$values
> >> [1]  3.903094e-118 -3.903094e-118 -2.610848e-312 -2.995687e-313
> >> -2.748516e-313
> >> [6] -1.073138e-314 -1.061000e-314 -1.060998e-314  4.940656e-324
> >> 0.000000e+00
> >> > R.version()
> >>Error: attempt to apply non-function
> >> > R.version
> > Strange and semi-random results on SuSE 9.3 as well:
> >
> >> eigen(matrix(1:100,10,10))$values
> >  [1] -5.393552e+194   3.512001e-68   0.000000e+00   0.000000e+00
> > 0.000000e+00
> >  [6]   0.000000e+00   0.000000e+00   0.000000e+00   0.000000e+00   0.000000e+00
> >
> >> eigen(matrix(1:100,10,10))$values
> >  [1]  1.526259e-311 -1.041529e-311  1.181720e-313   0.000000e+00
> > 0.000000e+00
> >  [6]   0.000000e+00   0.000000e+00   0.000000e+00   0.000000e+00   0.000000e+00
> >
> >> eigen(matrix(1:100,10,10))$values
> >  [1] -9.338774e+93  0.000000e+00  0.000000e+00  0.000000e+00
> > 0.000000e+00
> >  [6]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
> >
> >> eigen(matrix(1:100,10,10))$values
> >  [1]  5.4e-311+ 0.0e+00i -2.5e-311+3.7e-311i -2.5e-311-3.7e-311i
> >  [4]  2.5e-312+ 0.0e+00i -2.4e-312+ 0.0e+00i  3.2e-317+ 0.0e+00i
> >  [7]   0.0e+00+ 0.0e+00i   0.0e+00+ 0.0e+00i   0.0e+00+ 0.0e+00i
> > [10]   0.0e+00+ 0.0e+00i
> >
> 
> Mine is closer to Robin's, but not the same (EL4 x86).
> 
>  > eigen(matrix(1:100,10,10))$values
>   [1]  5.208398e+02+0.000000e+00i -1.583980e+01+0.000000e+00i
>   [3]  6.292457e-16+2.785369e-15i  6.292457e-16-2.785369e-15i
>   [5] -1.055022e-15+0.000000e+00i  3.629676e-16+0.000000e+00i
>   [7]  1.356222e-16+2.682405e-16i  1.356222e-16-2.682405e-16i
>   [9]  1.029077e-16+0.000000e+00i -1.269181e-17+0.000000e+00i
>  >
> 
> But surely, my matrix algebra is a bit rusty, I think this matrix is
> solveable analytically? Most of the eigenvalues shown are almost
> exactly zero, except the first two, actually, which is about 521
> and -16 to the closest integer.
> 
> I think the difference between mine and Robin's are rounding errors
> (the matrix is simple enough I expect the solution to be simple integers
> or easily expressible analystical expressions, so 8 e-values being zero
> is fine). Peter's number seems to be all 10 e-values are zero or one
> being a huge number! So Peter's is odd... and Peter's machine also
> seems
> to be of a different archtecture (64-bit machine)?
> 
> HTL

Notice that Robin got something completely different in _R-devel_
which is where I did my check too.  In R 2.2.1 I get the expected two
non-zero eigenvalues. 

I'm not sure whether (and how) you can work out the eigenvalues
analytically, but since all columns are linear progressions, it is
at least obvious that the matrix must have column rank two.

-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



[Rd] eigen()
Peter Dalgaard