Skip to content
Prev 167142 / 398506 Next

Precision in R

On Thu, 15 Jan 2009, dos Reis, Marlon wrote:

            
Thanks for posting your data, Marlon.

This is what I get on windows XP:
[,1]          [,2]          [,3]
[1,] -2.861023e-06 -4.768372e-07 -4.768372e-07
[2,] -4.768372e-07 -3.814697e-06  2.622604e-06
[3,] -4.768372e-07  2.622604e-06 -5.960464e-08
but on my Gentoo Linux Intel Core 2 Duo:

  print(tcp1-tcp2,digits=20)
      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0
[3,]    0    0    0
So, it would seem to be that the floating point calcs on my Windows
box, David's Mac, and whatever system you are using are not as
accurate as they might be.

It is well known that rounding error can play havoc with crossproducts 
(particularly when the range of magnitudes of the numbers is wide as it is 
here), which is why matrix decompositions are generally used for solving 
least squares problems.

The internal code for crossprod and tcrossprod is different, so the
computations are likely done in a different order, which would account
for the difference in tcp1 and tcp2 . Ultimately, array.c and blas.f SUBROUTINE
DSYRK have the code if you want to dig into it.

So to summarize: the difference is not due to R per se, but in the
limited accuracy of floating point calcs on the system used.

HTH,

Chuck