Re: [R] Problem with <= (less than or equal): not giving the expected result

2016-04-07 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of S Ellison
> Sent: Wednesday, April 6, 2016 12:35 PM
> To: Rainer Johannes ; r-help@r-project.org
> Subject: Re: [R] Problem with <= (less than or equal): not giving the expected
> result
>
> > Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however
> > quite disturbing.
>
> It's normal.* See R FAQ 7.31 in the html help system.
>
> S Ellison
>
> *... and common to all computers that use binary.

The main issue is that when using Excel you do not experience normally such 
issues, probably because Excel silently decide how to express precision of 
decimal values.

=+ABS(1-0.995) is equal to 0.005, however
=+ABS(1-0.9995) is not equal to 0.0005

So it when Excel (Excel 2016) users do not use numbers smaller than 0.005 they 
do not find this behaviour.

Cheers
Petr



>
>
>
> **
> *
> This email and any attachments are confidential. Any use, copying or
> disclosure other than by the intended recipient is unauthorised. If you have
> received this message in error, please notify the sender immediately via
> +44(0)20 8943 7000 or notify postmas...@lgcgroup.com and delete this
> message and any copies from your computer and network.
> LGC Limited. Registered in England 2991879.
> Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
> __
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
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, 

Re: [R] Problem with <= (less than or equal): not giving the expected result

2016-04-06 Thread S Ellison
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.

It's normal.* See R FAQ 7.31 in the html help system.

S Ellison

*... and common to all computers that use binary. 



***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread PIKAL Petr
Hi

Or some rounding when comparing results with threshold exactly.

> round(abs(0.95 - 1),2) > 0.05
[1] FALSE
> round(abs(0.95 - 1),2) < 0.05
[1] FALSE
>
Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rainer
> Johannes
> Sent: Tuesday, April 5, 2016 4:33 PM
> To: Thierry Onkelinx 
> Cc: r-help@r-project.org; Adrian Dușa 
> Subject: Re: [R] Problem with <= (less than or equal): not giving the expected
> result
>
> Thanks!
>
> On 05 Apr 2016, at 16:07, Thierry Onkelinx
> > wrote:
>
> You could use something like this
>
> x <- abs(0.95 - 1)
> treshold <- 0.05
> x < treshold | abs(x - treshold) < 1e-6
>
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality
> Assurance Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no more than
> asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of
> anecdote is not data. ~ Roger Brinner The combination of some data and an
> aching desire for an answer does not ensure that a reasonable answer can be
> extracted from a given body of data. ~ John Tukey
>
> 2016-04-05 14:46 GMT+02:00 Rainer Johannes
> >:
> Thanks Adrian and Thierry (from the previous answer).
>
> I was aware of the all.equal function, but there is nothing similar for <= 
> (e.g.
> all.smallerEqual)?
>
> cheers, jo
>
> On 05 Apr 2016, at 14:31, Adrian Dușa
>  n...@unibuc.ro>> wrote:
>
> Yes, that does have to do with floating point representation.
> I use this function for these types of comparisons (works with values as well
> as with vectors):
>
> check.equal <- function(x, y) {
> check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
> check.vector[is.na(check.vector)] <- FALSE
> return(check.vector)
> }
>
> See:
> ?all.equal
>
> Hth,
> Adrian
>
> On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes
>  johannes.rai...@eurac.edu>> wrote:
> Dear All,
>
> I have the following problem:
>
> I have a function in which I check if the difference between values is smaller
> or equal to a certain threshold. I however realized that I might get there
> some unexpected results:
>
> > abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.
>
> Along these lines:
> > abs(0.95 - 1) > 0.05
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> I guess that has to do with the floating point representation of the data?
>
> Is there something I miss or is there any solution to this?
> Thanks for any help!
>
> cheers, jo
>
>
>
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The R-
> version I used for the code above is:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> R-help@r-project.org 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 project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>
>
> [[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.
>
>
>
>   [[alternative HTML version deleted]]
>
> 

Re: [R] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread David Winsemius

> On Apr 5, 2016, at 5:46 AM, Rainer Johannes  wrote:
> 
> Thanks Adrian and Thierry (from the previous answer).
> 
> I was aware of the all.equal function, but there is nothing similar for <= 
> (e.g. all.smallerEqual)?

Perhaps you will gain understanding by looking at this:

> abs(1 - 0.95) - 0.05
[1] 4.163336e-17

Perhaps you want to make your own `all.<=`

> '%all.<=%'   <- function (e1,e2){ e1 < e2 | abs(e1-e2) < 
> .Machine$double.eps^0.5 }
> abs(1 - 0.95) %all.<=% 0.05
[1] TRUE


-- 
David.
> 
> cheers, jo
> 
> On 05 Apr 2016, at 14:31, Adrian Dușa 
> > wrote:
> 
> Yes, that does have to do with floating point representation.
> I use this function for these types of comparisons (works with values as well 
> as with vectors):
> 
> check.equal <- function(x, y) {
>check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
>check.vector[is.na(check.vector)] <- FALSE
>return(check.vector)
> }
> 
> See:
> ?all.equal
> 
> Hth,
> Adrian
> 
> On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes 
> > wrote:
> Dear All,
> 
> I have the following problem:
> 
> I have a function in which I check if the difference between values is 
> smaller or equal to a certain threshold. I however realized that I might get 
> there some unexpected results:
> 
>> abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
>> abs(1 - 0.95) <= 0.05
> [1] FALSE
> 
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite 
> disturbing.
> 
> Along these lines:
>> abs(0.95 - 1) > 0.05
> [1] TRUE
>> abs(0.95 - 1) < 0.05
> [1] FALSE
> 
> I guess that has to do with the floating point representation of the data?
> 
> Is there something I miss or is there any solution to this?
> Thanks for any help!
> 
> cheers, jo
> 
> 
> 
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The 
> R-version I used for the code above is:
> 
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> 
> locale:
> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> 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.
> 
> 
> 
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
> 
> 
>   [[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.

David Winsemius
Alameda, CA, USA

__
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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Rainer Johannes
Thanks!

On 05 Apr 2016, at 16:07, Thierry Onkelinx 
> wrote:

You could use something like this

x <- abs(0.95 - 1)
treshold <- 0.05
x < treshold | abs(x - treshold) < 1e-6


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data. ~ John 
Tukey

2016-04-05 14:46 GMT+02:00 Rainer Johannes 
>:
Thanks Adrian and Thierry (from the previous answer).

I was aware of the all.equal function, but there is nothing similar for <= 
(e.g. all.smallerEqual)?

cheers, jo

On 05 Apr 2016, at 14:31, Adrian Dușa 
>>
 wrote:

Yes, that does have to do with floating point representation.
I use this function for these types of comparisons (works with values as well 
as with vectors):

check.equal <- function(x, y) {
check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
check.vector[is.na(check.vector)] <- FALSE
return(check.vector)
}

See:
?all.equal

Hth,
Adrian

On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes 
>>
 wrote:
Dear All,

I have the following problem:

I have a function in which I check if the difference between values is smaller 
or equal to a certain threshold. I however realized that I might get there some 
unexpected results:

> abs(1 - 0.95) >= 0.05
[1] TRUE
## So that’s fine, but:
> abs(1 - 0.95) <= 0.05
[1] FALSE

Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite 
disturbing.

Along these lines:
> abs(0.95 - 1) > 0.05
[1] TRUE
> abs(0.95 - 1) < 0.05
[1] FALSE

I guess that has to do with the floating point representation of the data?

Is there something I miss or is there any solution to this?
Thanks for any help!

cheers, jo



I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The 
R-version I used for the code above is:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
__
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.



--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania


[[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.



[[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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Thierry Onkelinx
You could use something like this

x <- abs(0.95 - 1)
treshold <- 0.05
x < treshold | abs(x - treshold) < 1e-6


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-04-05 14:46 GMT+02:00 Rainer Johannes :

> Thanks Adrian and Thierry (from the previous answer).
>
> I was aware of the all.equal function, but there is nothing similar for <=
> (e.g. all.smallerEqual)?
>
> cheers, jo
>
> On 05 Apr 2016, at 14:31, Adrian Dușa > wrote:
>
> Yes, that does have to do with floating point representation.
> I use this function for these types of comparisons (works with values as
> well as with vectors):
>
> check.equal <- function(x, y) {
> check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
> check.vector[is.na(check.vector)] <- FALSE
> return(check.vector)
> }
>
> See:
> ?all.equal
>
> Hth,
> Adrian
>
> On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes  > wrote:
> Dear All,
>
> I have the following problem:
>
> I have a function in which I check if the difference between values is
> smaller or equal to a certain threshold. I however realized that I might
> get there some unexpected results:
>
> > abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.
>
> Along these lines:
> > abs(0.95 - 1) > 0.05
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> I guess that has to do with the floating point representation of the data?
>
> Is there something I miss or is there any solution to this?
> Thanks for any help!
>
> cheers, jo
>
>
>
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The
> R-version I used for the code above is:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> 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<
> http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania
>
>
> [[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.

[[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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Rainer Johannes
Thanks Adrian and Thierry (from the previous answer).

I was aware of the all.equal function, but there is nothing similar for <= 
(e.g. all.smallerEqual)?

cheers, jo

On 05 Apr 2016, at 14:31, Adrian Dușa 
> wrote:

Yes, that does have to do with floating point representation.
I use this function for these types of comparisons (works with values as well 
as with vectors):

check.equal <- function(x, y) {
check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
check.vector[is.na(check.vector)] <- FALSE
return(check.vector)
}

See:
?all.equal

Hth,
Adrian

On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes 
> wrote:
Dear All,

I have the following problem:

I have a function in which I check if the difference between values is smaller 
or equal to a certain threshold. I however realized that I might get there some 
unexpected results:

> abs(1 - 0.95) >= 0.05
[1] TRUE
## So that’s fine, but:
> abs(1 - 0.95) <= 0.05
[1] FALSE

Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite 
disturbing.

Along these lines:
> abs(0.95 - 1) > 0.05
[1] TRUE
> abs(0.95 - 1) < 0.05
[1] FALSE

I guess that has to do with the floating point representation of the data?

Is there something I miss or is there any solution to this?
Thanks for any help!

cheers, jo



I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The 
R-version I used for the code above is:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
__
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.



--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania


[[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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Adrian Dușa
Yes, that does have to do with floating point representation.
I use this function for these types of comparisons (works with values as
well as with vectors):

check.equal <- function(x, y) {
check.vector <- as.logical(unlist(lapply(x, all.equal, y)))
check.vector[is.na(check.vector)] <- FALSE
return(check.vector)
}

See:
?all.equal

Hth,
Adrian

On Tue, Apr 5, 2016 at 2:34 PM, Rainer Johannes 
wrote:

> Dear All,
>
> I have the following problem:
>
> I have a function in which I check if the difference between values is
> smaller or equal to a certain threshold. I however realized that I might
> get there some unexpected results:
>
> > abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.
>
> Along these lines:
> > abs(0.95 - 1) > 0.05
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> I guess that has to do with the floating point representation of the data?
>
> Is there something I miss or is there any solution to this?
> Thanks for any help!
>
> cheers, jo
>
>
>
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The
> R-version I used for the code above is:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> 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.




-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[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] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Thierry Onkelinx
FAQ 7.31

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-04-05 13:34 GMT+02:00 Rainer Johannes :

> Dear All,
>
> I have the following problem:
>
> I have a function in which I check if the difference between values is
> smaller or equal to a certain threshold. I however realized that I might
> get there some unexpected results:
>
> > abs(1 - 0.95) >= 0.05
> [1] TRUE
> ## So that’s fine, but:
> > abs(1 - 0.95) <= 0.05
> [1] FALSE
>
> Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite
> disturbing.
>
> Along these lines:
> > abs(0.95 - 1) > 0.05
> [1] TRUE
> > abs(0.95 - 1) < 0.05
> [1] FALSE
>
> I guess that has to do with the floating point representation of the data?
>
> Is there something I miss or is there any solution to this?
> Thanks for any help!
>
> cheers, jo
>
>
>
> I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The
> R-version I used for the code above is:
>
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> __
> 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.

[R] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Rainer Johannes
Dear All,

I have the following problem:

I have a function in which I check if the difference between values is smaller 
or equal to a certain threshold. I however realized that I might get there some 
unexpected results:

> abs(1 - 0.95) >= 0.05
[1] TRUE
## So that’s fine, but:
> abs(1 - 0.95) <= 0.05
[1] FALSE

Apparently, abs(1 - 0.95) is not equal to 0.05, which I find however quite 
disturbing.

Along these lines:
> abs(0.95 - 1) > 0.05
[1] TRUE
> abs(0.95 - 1) < 0.05
[1] FALSE

I guess that has to do with the floating point representation of the data?

Is there something I miss or is there any solution to this?
Thanks for any help!

cheers, jo



I tried this on different R-version (including 3.2.3 and 3.3.0 alpha); The 
R-version I used for the code above is:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base   
__
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.