[R] plot representation of calculated value known to be 7.4

Troels Ring tring at gvdnet.dk
Tue Dec 26 08:49:50 CET 2017


Thanks a lot - formatting the ordinate as ylim=c(4,10) before plotting 
pH also removed the problem, and options(digits=10) confirmed that pH 
was not all exactly 7.4 - as I knew. Still I wonder just why R chooses 
to plot(ATOT,pH) as shown with repeated "7.4" instead of some more 
detailed representation. Thanks a gain and happy New Year!

Troels


Den 26-12-2017 kl. 01:03 skrev Bert Gunter:
> Note that ?all.equal clearly says that it tests for **approximate 
> equality only** with tolerance "close to 1.5 e-8.
>
> So..
>
> > all.equal(z,pH, tol = 1e-15)
> [1] "Mean relative difference: 6.732527e-11"
>
> and
>
> > print(pH, digits =15)
> ## output omitted
>
> Shows you what's going on.
>
> Cheers,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Dec 25, 2017 at 11:00 AM, Troels Ring <tring at gvdnet.dk 
> <mailto:tring at gvdnet.dk>> wrote:
>
>     Dear friends - copy paste missed
>
>     SID <- c() before the first loop - sorry
>
>     BW Troels
>
>
>
>     Den 25-12-2017 kl. 19:12 skrev Troels Ring:
>
>
>         Dear friends - merry Christmas and thanks a lot for much help
>         during the year!
>
>         In the example below I fail to understand how the calculated
>         value pH is represented in a simple plot - also included. The
>         calculations are useful in practice and likely to be right in
>         principle but I cannot see how this occurs: why a calculated
>         value of 7.4 known as numeric is not simply plotted as such.
>         It happened on Windows both 7 and 10 with R version 3.4.1.
>
>         All best wishes
>
>         Troels
>
>         ff <- function(H,SID,ATOT,ka)  H + SID - kw/H - ka*ATOT/(H+ka)
>          ka <- 1e-7
>          kw <- 1e-14
>          ATOT <- seq(0,0.3,length=100)*1e-3
>
>          for (i in 1:length(ATOT))  {
>          SID[i] <-
>         uniroot(ff,c(-1,1),tol=.Machine$double.eps,maxiter=100000,ka=ka,
>         ATOT=ATOT[i], H = 10^-7.4)$root}
>         ATOT
>
>         #confirm pH 0 7.4
>
>         H <- c()
>          for (i in 1:length(ATOT))  {
>          H[i] <-
>         uniroot(ff,c(1e-19,1),tol=.Machine$double.eps,maxiter=100000,ka=ka,
>         ATOT=ATOT[i], SID = SID[i])$root}
>
>         (pH <- -log10(H))
>         plot(pH)
>         str(pH)
>         # num [1:100] 7.4 7.4 7.4 7.4 7.4 ...
>         z <- rep(7.4,length(ATOT))
>         all.equal(z,pH)
>         #TRUE
>         points(z,col="red")
>
>
>     ______________________________________________
>     R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
>     To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     <https://stat.ethz.ch/mailman/listinfo/r-help>
>     PLEASE do read the posting guide
>     http://www.R-project.org/posting-guide.html
>     <http://www.R-project.org/posting-guide.html>
>     and provide commented, minimal, self-contained, reproducible code.
>
>


	[[alternative HTML version deleted]]



More information about the R-help mailing list