Skip to content
Prev 167156 / 398502 Next

Precision in R

Hi there,
Thanks for the help. 
I see now where my results are coming from.
Marlon.

-----Original Message-----
From: Charles C. Berry [mailto:cberry at tajo.ucsd.edu] 
Sent: Friday, 16 January 2009 6:26 a.m.
To: dos Reis, Marlon
Cc: David Winsemius; r-help at r-project.org
Subject: RE: [R] 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
well:
=====================================================================
=======================================================================
attachments
privileged
or
AgResearch
=======================================================================
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive
Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego
92093-0901


=======================================================================
Attention: The information contained in this message and...{{dropped:12}}