[R] Precision in R
David Winsemius
dwinsemius at comcast.net
Thu Jan 15 19:32:21 CET 2009
On Jan 15, 2009, at 12:25 PM, Charles C. Berry wrote:
>
>
> This is what I get on windows XP:
>
>> tcp1-tcp2
> [,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.
For the record; on an Intel Mac (Leopard) with Urbanek's compilation
of R 2.8.1
> print(tcp1-tcp2,digits=20)
[,1] [,2] [,3]
[1,] 0 0 0
[2,] 0 0 0
[3,] 0 0 0
--
David Winsemius
>
>
> 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
snip
More information about the R-help
mailing list