Re: [R] R wrong, Python rigth in calcution

2019-09-18 Thread Richard O'Keefe
Here's a tip for the original poster.
> ?numeric
and then follow the link it suggests
> ?double
which says amongst other things
 All R platforms are required to work with values conforming to the
 IEC 60559 (also known as IEEE 754) standard.  This basically works
 with a precision of 53 bits, and represents to that precision a
 range of absolute values from about 2e-308 to 2e+308.
and reminds us that
> .Machine
will give you the parameters of the 'double' type.


On Wed, 18 Sep 2019 at 12:03, Abby Spurdle  wrote:

> > R by default uses floating-point arithmetic, which
> > is subject to problems described in [*].
>
> Yes.
>
> I want to note that both graphics and modern statistics, require
> efficient floating point arithmetic.
> So, R does what it's designed to do...
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R wrong, Python rigth in calcution

2019-09-17 Thread Abby Spurdle
> R by default uses floating-point arithmetic, which
> is subject to problems described in [*].

Yes.

I want to note that both graphics and modern statistics, require
efficient floating point arithmetic.
So, R does what it's designed to do...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R wrong, Python rigth in calcution

2019-09-17 Thread Richard M. Heiberger
Your numbers are 70 bits long, R double precision numbers are 53 bits long.
You need Rmpfr to get the higher precision.

> log(569936821221962380720, 2)
[1] 68.94936
> print(569936821221962380720, digits=22)
[1] 569936821221962350592

> library(Rmpfr)
> mpfr("569936821221962380720", 70)
1 'mpfr' number of precision  70   bits
[1] 569936821221962380720
>
> mpfr("569936821221962380720", 210)^3 + (mpfr("-569936821113563493509", 
> 210))^3 + (mpfr("-472715493453327032", 210))^3
1 'mpfr' number of precision  210   bits
[1] 3

See FAQ 7.31 and the help files for Rmpfr

Rich




On Tue, Sep 17, 2019 at 6:13 PM Duncan Murdoch  wrote:
>
> On 17/09/2019 6:02 p.m., Martin Møller Skarbiniks Pedersen wrote:
> > Hi,
> >I don't understand why R computes this wrong.
>
> This is pretty well documented.  R uses double precision floating point
> values for these expressions, which have about 15 digit precision.  I
> believe for whole numbers Python uses variable size integer values, so
> should get integer calculations exactly right.
>
> You can also tell R to use exact 32 bit integer calculations, but your
> values are too big for that, so it wouldn't work in this example.
>
>
>
>   I know I can use gmp and
> > R will do it correctly.
> >
> > $ echo '569936821221962380720^3 + (-569936821113563493509)^3 +
> > (-472715493453327032)^3' | Rscript - [1] -4.373553e+46
> > Correct answer is 3 and Python can do it:
> >
> > $ echo
> > 'pow(569936821221962380720,3)+pow(-569936821113563493509,3)+pow(-472715493453327032,3)'|python3
> > 3
> >
> >   [[alternative HTML version deleted]]
>
> Please don't post HTML to the list -- it's a plain text list.  That's
> also pretty well documented.
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R wrong, Python rigth in calcution

2019-09-17 Thread Ivan Krylov
On Wed, 18 Sep 2019 00:02:47 +0200
Martin Møller Skarbiniks Pedersen  wrote:

> I know I can use gmp and R will do it correctly.

Which is equivalent to what Python does: it uses so-called long
arithmetic, allowing scalar variables with as many digits as it fits in
the computer memory. R by default uses floating-point arithmetic, which
is subject to problems described in [*].

-- 
Best regards,
Ivan

[*] https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf or
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R wrong, Python rigth in calcution

2019-09-17 Thread Duncan Murdoch

On 17/09/2019 6:02 p.m., Martin Møller Skarbiniks Pedersen wrote:

Hi,
   I don't understand why R computes this wrong.


This is pretty well documented.  R uses double precision floating point 
values for these expressions, which have about 15 digit precision.  I 
believe for whole numbers Python uses variable size integer values, so 
should get integer calculations exactly right.


You can also tell R to use exact 32 bit integer calculations, but your 
values are too big for that, so it wouldn't work in this example.




 I know I can use gmp and

R will do it correctly.

$ echo '569936821221962380720^3 + (-569936821113563493509)^3 +
(-472715493453327032)^3' | Rscript - [1] -4.373553e+46
Correct answer is 3 and Python can do it:

$ echo
'pow(569936821221962380720,3)+pow(-569936821113563493509,3)+pow(-472715493453327032,3)'|python3
3

[[alternative HTML version deleted]]


Please don't post HTML to the list -- it's a plain text list.  That's 
also pretty well documented.


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R vs PYTHON vs SAS vs SPSS?

2017-11-30 Thread Hasan Diwan
Yes

On 30 November 2017 at 22:28,  wrote:

> I am a mature learner; 3 masters
> some doctoral work “ statistics for social sciences; psychological
> statistics “
> worked in spss and sas 2005 – 2006
> now have forgotten ; relearning
> my question is this can I do everything in R and Python and SAS studio
> that I did in SPSS and the paid variation of SAS we used in doctoral
> statistics class?
> Can I do in Stat in R or Python or SAS studio
> everything I need to do in multiple regression; ANOVA; ANCOVA etc
> ?
> that I did/was starting to do in SPSS?
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
OpenPGP:
https://sks-keyservers.net/pks/lookup?op=get=0xFEBAD7FFD041BBA1
If you wish to request my time, please do so using
http://bit.ly/hd1ScheduleRequest.
Si vous voudrais faire connnaisance, allez a
http://bit.ly/hd1ScheduleRequest.

Sent
from my mobile device
Envoye de mon portable

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] R and Python

2015-03-01 Thread Wensui Liu
depending on what you want.
if you'd like to run r within python, there are 2 solutions as far as i've
known, either by rpys or by pyper.
here is a brief comparison i did before
https://statcompute.wordpress.com/2012/12/10/a-brief-comparison-between-rpy2-and-pyper/


On Sun, Mar 1, 2015 at 8:41 AM, linda.s samrobertsm...@gmail.com wrote:

 Is there any good example codes of integrating R and Python?
 Thanks.
 Linda

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
==
WenSui Liu
Credit Risk Manager, 53 Bancorp
wensui@53.com
513-295-4370
==

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2015-03-01 Thread Sarah Goslee
You mean like rPython? Or rpy? Or rpy2?

Googling R Python is a great place to start.

Sarah

On Sun, Mar 1, 2015 at 9:41 AM, linda.s samrobertsm...@gmail.com wrote:
 Is there any good example codes of integrating R and Python?
 Thanks.
 Linda

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2015-03-01 Thread Collin Lynch
I recommend rpy2.  http://rpy.sourceforge.net/rpy2.html

It provides direct access to a running R instance with full support for R
functions including package loading.  It has some minor issues with
graphics drivers making it best for programmatic and not interactive use
but it is excellent for munging data in python and then passing it off to R
for calculations.

Collin.

On Sun, Mar 1, 2015 at 10:17 AM, Sarah Goslee sarah.gos...@gmail.com
wrote:

 You mean like rPython? Or rpy? Or rpy2?

 Googling R Python is a great place to start.

 Sarah

 On Sun, Mar 1, 2015 at 9:41 AM, linda.s samrobertsm...@gmail.com wrote:
  Is there any good example codes of integrating R and Python?
  Thanks.
  Linda
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2009-11-14 Thread lgautier
There appear to be win32 binaries for the the current release of rpy2.


L.




On Nov 4, 4:21 pm, Gabor Grothendieck ggrothendi...@gmail.com wrote:
 As far as I know the latest versions of neither RSpython norrpy2
 support Windows. For accessing SymPy (which is a python computer
 algebra system) from R rSymPy went with jython.  Its slower than
 cpython, particularly the startup, but it should work on all
 platforms.  See
  http://rsympy.googlecode.com
 The latest version is 0.1-4.

 If ruby is an option see the rinruby project for accessing R from
 ruby.  There is a paper on it on jstatsoft.org .

 If java is an option see the RServe package for accessing R from java.
  Also in the other direction the rJava package can be used to access
 java from R.



 On Mon, Nov 2, 2009 at 11:37 AM, Ryan Sheftel ryan.shef...@rmbaries.com 
 wrote:
  I am a long time user of R for financial time series analysis (xts, zoo,
  etc) and for my next project I am thinking of adding the Python language to
  the mix. The reason for adding Python is primarily its non-statistical
  capabilities.

  So my questions are what have people's experiences been with using interop
  between R and Python. I see there are two items, rPy and RSPython. It looks
  like rPy makes it possible to call R code from Python, and RSPython goes
  both ways. My needs would be to use Python to drive R to get it's extensive
  time series and stats, and also to get to Python objects from inside R.

  I searched the list archives and it looks like many people use rPy, but what
  about RSPython for calling Python from R? It looks like rPy only goes from R
  into Python, and RSPython has not been updated since 2005?

  Other messages in the archives state that RSPython only works on Unix?

  Would I be foolish to build anything mission critical on RSPython? Is there
  a better way to get at Python from R?

  Thanks as always.

         [[alternative HTML version deleted]]

  __
  r-h...@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2009-11-04 Thread Gabor Grothendieck
As far as I know the latest versions of neither RSpython nor rpy2
support Windows. For accessing SymPy (which is a python computer
algebra system) from R rSymPy went with jython.  Its slower than
cpython, particularly the startup, but it should work on all
platforms.  See
  http://rsympy.googlecode.com
The latest version is 0.1-4.

If ruby is an option see the rinruby project for accessing R from
ruby.  There is a paper on it on jstatsoft.org .

If java is an option see the RServe package for accessing R from java.
 Also in the other direction the rJava package can be used to access
java from R.


On Mon, Nov 2, 2009 at 11:37 AM, Ryan Sheftel ryan.shef...@rmbaries.com wrote:
 I am a long time user of R for financial time series analysis (xts, zoo,
 etc) and for my next project I am thinking of adding the Python language to
 the mix. The reason for adding Python is primarily its non-statistical
 capabilities.

 So my questions are what have people's experiences been with using interop
 between R and Python. I see there are two items, rPy and RSPython. It looks
 like rPy makes it possible to call R code from Python, and RSPython goes
 both ways. My needs would be to use Python to drive R to get it's extensive
 time series and stats, and also to get to Python objects from inside R.

 I searched the list archives and it looks like many people use rPy, but what
 about RSPython for calling Python from R? It looks like rPy only goes from R
 into Python, and RSPython has not been updated since 2005?

 Other messages in the archives state that RSPython only works on Unix?

 Would I be foolish to build anything mission critical on RSPython? Is there
 a better way to get at Python from R?

 Thanks as always.

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2009-11-04 Thread Doran, Harold
I use both python and R, but decided not to mix the two. I'd rather work 
directly in R for statistics, visual displays, etc. I really like python for 
pre-processing data, some preliminary data organization, and XML capes.

 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Gabor Grothendieck
 Sent: Wednesday, November 04, 2009 10:22 AM
 To: Ryan Sheftel
 Cc: r-help@r-project.org
 Subject: Re: [R] R and Python
 
 As far as I know the latest versions of neither RSpython nor 
 rpy2 support Windows. For accessing SymPy (which is a python 
 computer algebra system) from R rSymPy went with jython.  Its 
 slower than cpython, particularly the startup, but it should 
 work on all platforms.  See
   http://rsympy.googlecode.com
 The latest version is 0.1-4.
 
 If ruby is an option see the rinruby project for accessing R 
 from ruby.  There is a paper on it on jstatsoft.org .
 
 If java is an option see the RServe package for accessing R from java.
  Also in the other direction the rJava package can be used to 
 access java from R.
 
 
 On Mon, Nov 2, 2009 at 11:37 AM, Ryan Sheftel 
 ryan.shef...@rmbaries.com wrote:
  I am a long time user of R for financial time series analysis (xts, 
  zoo,
  etc) and for my next project I am thinking of adding the Python 
  language to the mix. The reason for adding Python is primarily its 
  non-statistical capabilities.
 
  So my questions are what have people's experiences been with using 
  interop between R and Python. I see there are two items, rPy and 
  RSPython. It looks like rPy makes it possible to call R code from 
  Python, and RSPython goes both ways. My needs would be to 
 use Python 
  to drive R to get it's extensive time series and stats, and 
 also to get to Python objects from inside R.
 
  I searched the list archives and it looks like many people use rPy, 
  but what about RSPython for calling Python from R? It looks 
 like rPy 
  only goes from R into Python, and RSPython has not been 
 updated since 2005?
 
  Other messages in the archives state that RSPython only 
 works on Unix?
 
  Would I be foolish to build anything mission critical on 
 RSPython? Is 
  there a better way to get at Python from R?
 
  Thanks as always.
 
         [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2009-11-04 Thread stephenb

Not only RSPython does not support Windows, but it won't compile on most Unix
platforms and fixing it may be more time than writing a package on your own.

Like the other post, I use Python for pre-processing and then load into R.
If you need text processing with line by line access you can also use Java,
which will communicate to R.

cheers
Stephen


Ryan Sheftel-2 wrote:
 
 I am a long time user of R for financial time series analysis (xts, zoo,
 etc) and for my next project I am thinking of adding the Python language
 to
 the mix. The reason for adding Python is primarily its non-statistical
 capabilities.
 
 So my questions are what have people's experiences been with using interop
 between R and Python. I see there are two items, rPy and RSPython. It
 looks
 like rPy makes it possible to call R code from Python, and RSPython goes
 both ways. My needs would be to use Python to drive R to get it's
 extensive
 time series and stats, and also to get to Python objects from inside R.
 
 I searched the list archives and it looks like many people use rPy, but
 what
 about RSPython for calling Python from R? It looks like rPy only goes from
 R
 into Python, and RSPython has not been updated since 2005?
 
 Other messages in the archives state that RSPython only works on Unix?
 
 Would I be foolish to build anything mission critical on RSPython? Is
 there
 a better way to get at Python from R?
 
 Thanks as always.
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 

-- 
View this message in context: 
http://old.nabble.com/R-and-Python-tp26166781p26199643.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and Python

2009-11-04 Thread baptiste auguie
Hi,

It looks like SAGE might be another option,

http://www.sagemath.org/index.html

though I never tried it.

HTH,

baptiste

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R vs Python performance-wise

2008-12-06 Thread Martin Maechler
 JQ == Jose Quesada [EMAIL PROTECTED]
 on Sat, 06 Dec 2008 12:28:34 +0100 writes:

JQ Hi, Has anyone run any R vs Python (numpy) tests?  I'd
JQ love to see what the differences performance-wise are,
JQ specially handling large sparse matrices.  Since both
JQ rely on external C code, there might not be much of a
JQ difference.

(yes).
You mention sparse matrices here,
but not the 'Matrix' package below.
For sparse matrices, I'd strongly recommend using that.

I note that you mention 'sna', and that uses sparseM
which also deals with sparse matrices, but less comprehensively
and partly based on suboptimal (mostly because less modern)
algorithms.

JQ If you know and use both languages, what are the main
JQ differences and what made you stick to one over another?

JQ I also noticed that there are strong libraries for
JQ social networks on both.


JQ python: networkX: https://networkx.lanl.gov/wiki pySNA:
JQ http://www.menslibera.com.tr/pysna/

JQ R: sna, network etc. see: http://www.jstatsoft.org/v24

yes.  IIRC, some or even most of these use graph representations without
explicit sparse matrix interfaces.
That's quite natural since sparse matrices can only represent
one number per (directed) relation.
On the other hand, I have been a bit startled to see that
(AFAICS) the 'network' package does not easily create sparse but
rather dense adjacency matrices...

One interesting package, not mentioned above (since it's rather
dealing with traditional graphs) is the 'igraph'
one.  AFAIK, it uses very efficient algorithms in some parts.

JQ Has anyone run a bechmark of the two systems doing the
JQ same operation?

JQ Which is the right environment for large social
JQ networks? Some packages have bindings for both
JQ languages, and of course, there's a reliable way to bind
JQ the two languages together, Rpy:
JQ http://rpy.sourceforge.net/

JQ So this may not be a big deal which one to pick.

JQ Thanks, -Jose

JQ -- Jose Quesada, PhD.  Max Planck Institute, Human
JQ Development, Berlin http://www.andrew.cmu.edu/~jquesada

JQ __
JQ R-help@r-project.org mailing list
JQ https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
JQ read the posting guide
JQ http://www.R-project.org/posting-guide.html and provide
JQ commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.