Skip to content
Prev 167066 / 398502 Next

Precision in R

Thanks Nath,

I get the following results:
system.time(tcp1 <- tcrossprod(WB))
   user  system elapsed 
      0       0       0
user  system elapsed 
      0       0       0
[1] TRUE 

But, when I try the inverse: 

solve(tcp1)
          [,1]      [,2]       [,3]
[1,] -41692.80  58330.89  -78368.17
[2,]  58330.89 -81608.66  109642.09
[3,] -78368.17 109642.09 -147305.32
Error in solve.default(tcp2) : 
  system is computationally singular: reciprocal condition number =
2.17737e-17
solve(tcp1)
          [,1]      [,2]       [,3]
[1,] -41692.80  58330.89  -78368.17
[2,]  58330.89 -81608.66  109642.09
[3,] -78368.17 109642.09 -147305.32
Error in solve.default(tcp2) : 
  s
[,1]       [,2]       [,3]
[1,] 1916061939 2281366606  678696067
[2,] 2281366606 3098975504 1092911209
[3,]  678696067 1092911209  452399849
[,1]       [,2]       [,3]
[1,] 1916061939 2281366606  678696067
[2,] 2281366606 3098975504 1092911209
[3,]  678696067 1092911209  452399849




-----Original Message-----
From: Nathan S. Watson-Haigh [mailto:nathan.watson-haigh at csiro.au] 
Sent: Thursday, 15 January 2009 3:25 p.m.
To: dos Reis, Marlon
Cc: r-help at r-project.org
Subject: Re: [R] Precision in R

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've recently been working with cross products etc.

You should try the following function:
tcp1 <- tcrossprod(WB)
or
tcp2 <- crossprod(t(WB))

Both should be the same (check for equality accounting for some floating
point imprecision):
all.equal(tcp1, tcp2, check.attributes=FALSE)

You may wish to time how long it takes to do each, since in my recent
experience doing
crossprod(t(WB)) would be faster:
system.time(tcp1 <- tcrossprod(WB))
system.time(tcp2 <- crossprod(t(WB)))
all.equal(tcp1, tcp2, check.attributes=FALSE)

HTH,
Nath
dos Reis, Marlon wrote:
=======================================================================
and...{{dropped:15}}
http://www.R-project.org/posting-guide.html
- --
- --------------------------------------------------------
Dr. Nathan S. Watson-Haigh
OCE Post Doctoral Fellow
CSIRO Livestock Industries
Queensland Bioscience Precinct
St Lucia, QLD 4067
Australia

Tel: +61 (0)7 3214 2922
Fax: +61 (0)7 3214 2900
Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html
- --------------------------------------------------------

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklunowACgkQ9gTv6QYzVL7/AwCfcvoeS7QXxa/LCOQQhBrE+JHc
/qoAn24mXmd6fvhKdfiOavzbV1esBycu
=1WL+
-----END PGP SIGNATURE-----
=======================================================================
Attention: The information contained in this message and...{{dropped:12}}