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

2019-09-17 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

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@

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help
Oh, that's a nice option, too. Thanks! -Original Message- From: Richard M. Heiberger Sent: Tuesday, September 17, 2019 6:54 PM To: Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) Cc: r-help@r-project.org Subject: Re: [R] bi-directional bar chart with a central axis I would use the liker

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread Richard M. Heiberger
I would use the likert function in the HH package > library(HH) > likert(my.dta) > as.pyramidLikert(likert(my.dta)) > See the demo demo("likert-paper", package="HH", ask=FALSE) for more complex examples, including the population pyramid. We can also get the multiple coloring that your posted e

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help
Thanks, Jim (author of plotrix!), that's a real easy way to do it! I'll play around with options. Jen -Original Message- From: Jim Lemon Sent: Tuesday, September 17, 2019 6:43 PM To: Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) ; r-help mailing list Subject: Re: [R] bi-directional ba

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread Jim Lemon
Hi Jennifer, This is one way: library(plotrix) pyramid.plot(my.dta[,1],my.dta[,2], labels=c("Statement 1","Statement 2","Statement 3", "Statement 4","Statement 5","Statement 6", "Statement 7","Statement 8","Statement 9", "Statement 10","Statement 11","Statement 12","Statement 13"), top.labels

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help
Oh, I guess I just wasn't thinking of them as population pyramids since the variables A-M are actually responses to unrelated survey questions and not age bins. But that's silo'd thinking because why would that matter? Thanks for the brain nudge. I'll check out the plotrix link. Jen -Ori

Re: [R] bi-directional bar chart with a central axis

2019-09-17 Thread David Winsemius
On 9/17/19 3:14 PM, Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help wrote: Hi R-help, I have this data: my.dta <-data.frame(matrix(c( 26.3, 21.4, 20.1, 13.4, 7.9,3.9, 16.5, 14.6, 5.3,3.6, 38.6, 25.6, 34.4, 21.6, 77.4, 79.5, 58.2, 56.1, 80.5, 84, 37.7, 31.9,

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' nu

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

[R] bi-directional bar chart with a central axis

2019-09-17 Thread Sabatier, Jennifer F. (CDC/DDPHSIS/CGH/DGHP) via R-help
Hi R-help, I have this data: my.dta <-data.frame(matrix(c( 26.3, 21.4, 20.1, 13.4, 7.9,3.9, 16.5, 14.6, 5.3,3.6, 38.6, 25.6, 34.4, 21.6, 77.4, 79.5, 58.2, 56.1, 80.5, 84, 37.7, 31.9, 19.9, 28.1, 6.2,5.9 ), nrow=13, ncol=2, byrow=T, dimnames=list(c('A','B'

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

[R] R wrong, Python rigth in calcution

2019-09-17 Thread Martin Møller Skarbiniks Pedersen
Hi, I don't understand why R computes this wrong. 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)

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 2:08 PM, David Winsemius wrote: On 9/17/19 1:35 PM, varin sacha wrote: Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 1:35 PM, varin sacha wrote: Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I do that ? The `replicate` function is desi

Re: [R] Not the same length

2019-09-17 Thread varin sacha via R-help
Many thanks Ana, it perfectly works. Le mardi 17 septembre 2019 à 22:12:35 UTC+2, Ana PGG a écrit : Dear Varin Sacha,   My guess to try to help you is the following:   I think you may want to change this: y_obs <- rnorm(n*0.9, y_model, 0.1) + rnorm(n*0.1, y_model, 0.5) for: y_obs <

Re: [R] Not the same length

2019-09-17 Thread varin sacha via R-help
Many thanks David, it perfectly works. Now, one last think. If I want my R code here below to run let's say B=500 times and at the end I want to get the average for the MSE_GAM and for the MSE_MARS. How can I do that ? library(mgcv) library(earth) n<-2000 x<-runif(n, 0, 5) z <- runif(n, 0,

Re: [R] Not the same length

2019-09-17 Thread peter dalgaard
It depends on what you want to do, which is likely not what you do do You might be looking for y_obs <- ifelse(runif(n) < .9, rnorm(n, y_model, 0.1), rnorm(n, y_model, 0.5)) -pd > On 17 Sep 2019, at 21:48 , varin sacha via R-help > wrote: > > Dear R-helpers, > > Doing dput(x) and dput

Re: [R] Not the same length

2019-09-17 Thread David Winsemius
On 9/17/19 12:48 PM, varin sacha via R-help wrote: Dear R-helpers, Doing dput(x) and dput(y_obs), the 2 vectors are not the same length (1800 for y_obs and 2000 for x) How can I solve the problem ? Here is the reproducible R code   #  #  #  #  #  #  #  #  #  # library(mgcv) library(earth

[R] Not the same length

2019-09-17 Thread varin sacha via R-help
Dear R-helpers, Doing dput(x) and dput(y_obs), the 2 vectors are not the same length (1800 for y_obs and 2000 for x) How can I solve the problem ?  Here is the reproducible R code   #  #  #  #  #  #  #  #  #  # library(mgcv) library(earth) n<-2000 x<-runif(n, 0, 5)   y_model<- 0.1*x^3 -

[R] tune segmented fit

2019-09-17 Thread PIKAL Petr
Dear all I am trying to find one breakpoint in my data. I use segmented package. Here is my data > dput(temp) temp <- structure(list(spotreba = 0:40, sqsp = c(0, 1, 1.4142135623731, 1.73205080756888, 2, 2.23606797749979, 2.44948974278318, 2.64575131106459, 2.82842712474619, 3, 3.16227766016838

Re: [R] regex

2019-09-17 Thread Bert Gunter
?regexp ## Search the text on "backreference" .(or websearch it: "regular expression backreference") -- Bert On Tue, Sep 17, 2019 at 7:52 AM Ivan Calandra wrote: > Thank you Bert. > That's more like what I was looking for. > > Could you please tell me where I can find information on the "\\1

Re: [R] regex

2019-09-17 Thread Ivan Calandra
Thank you Bert. That's more like what I was looking for. Could you please tell me where I can find information on the "\\1"? This is the part I still don't get. Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Mus

Re: [R] regex

2019-09-17 Thread Ivan Calandra
Thanks Jeff! It does indeed make sense that there is no "AND" corresponding to the "|". Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, German

Re: [R] regex

2019-09-17 Thread Bert Gunter
(For the units) Why not simply: sub(".*\\[(.+)\\]","\\1", headers) Cheers, Bert On Tue, Sep 17, 2019 at 6:40 AM Ivan Calandra wrote: > Thank you Ivan for your help! > > Your solution for the first problem is so simple I didn't even think > about it! > What I find weird is that "_w_|\\.csv$"

Re: [R] regex

2019-09-17 Thread Jeff Newmiller
https://stackoverflow.com/questions/3041320/regex-and-operator/37692545 On September 17, 2019 6:39:13 AM PDT, Ivan Calandra wrote: >Thank you Ivan for your help! > >Your solution for the first problem is so simple I didn't even think >about it! >What I find weird is that "_w_|\\.csv$" works as e

Re: [R] regex

2019-09-17 Thread Ivan Calandra
Thank you Ivan for your help! Your solution for the first problem is so simple I didn't even think about it! What I find weird is that "_w_|\\.csv$" works as expected ("OR"), but is there no way to combine two patterns with an "AND"? Your solution to the second problem is actually unfortunate

Re: [R] regex

2019-09-17 Thread Ivan Krylov
On Tue, 17 Sep 2019 10:14:24 +0300 Ivan Krylov wrote: > '\\[.*\\]' Sorry, I forgot to take it into account that you don't want the [] in your units, either. That's still doable, but requires so-called look-around assertions in the regular expression: '(?<=\\[).*(?=\\])' This should match any c

Re: [R] regex

2019-09-17 Thread Ivan Krylov
On Tue, 17 Sep 2019 08:48:43 +0200 Ivan Calandra wrote: > CSVs <- list.files(path=..., pattern="\\.csv$") > w.files <- CSVs[grep(pattern="_w_", CSVs)] > > Of course, what I would like to do is list only the interesting files > from the beginning, rather than subsetting the whole list of files.