How to menage decimals in order to obtain accurate estimates

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to menage decimals in order to obtain accurate estimates

mary
Hi,

I'm trying to calculate some functions loop, unfortunately my data are decimal numbers that not allow me to get an accurate estimate. I do not want to use neither "round "nor "signif" but I would prefer to have all the information available, (the function loop is generic so you should adapt to all data, not just those in particular). The approximation error is multiplied in subsequent operations (I calculate the median and then the mad and so on...) and so eg. instead of getting 1.000 I get 1.0003.

I saw that there is a package Rmpfr but I have problems loading the package gmp also I do not know how to use it.

thanks
Reply | Threaded
Open this post in threaded view
|

Re: How to menage decimals in order to obtain accurate estimates

Jim Lemon
On 02/06/2013 10:40 AM, mary wrote:

> Hi,
>
> I'm trying to calculate some functions loop, unfortunately my data are
> decimal numbers that not allow me to get an accurate estimate. I do not want
> to use neither "round "nor "signif" but I would prefer to have all the
> information available, (the function loop is generic so you should adapt to
> all data, not just those in particular). The approximation error is
> multiplied in subsequent operations (I calculate the median and then the mad
> and so on...) and so eg. instead of getting 1.000 I get 1.0003.
>
> I saw that there is a package Rmpfr but I have problems loading the package
> gmp also I do not know how to use it.
>
Hi mary,
It's a bit difficult to understand what you are trying to do. It looks
like the "machine precision" problem (FAQ 7.31), especially since you
have mentioned the gmp package. Installing the gmp package requires that
you have a compiler, is this the problem?

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to menage decimals in order to obtain accurate estimates

mary

I'm sorry,

I have a data set  contains numbers with more decimal places, the data are available in R "data (milk)".
I made a loop to get a robust correlation matrix but in  calculations, decimals cause me problems ( especially I do not know how R rounds numbers by default) so the diagonal should be equal to one is not.

I hope it's clearer.
Reply | Threaded
Open this post in threaded view
|

Re: How to menage decimals in order to obtain accurate estimates

Jim Lemon
On 02/06/2013 07:51 PM, mary wrote:

>
> I'm sorry,
>
> I have a data set  contains numbers with more decimal places, the data are
> available in R "data (milk)".
> I made a loop to get a robust correlation matrix but in  calculations,
> decimals cause me problems ( especially I do not know how R rounds numbers
> by default) so the diagonal should be equal to one is not.
>
> I hope it's clearer.
>
Hi mary,
That's okay, nearly everybody thinks that because they know what they
are talking about, everyone else does, too. I don't know which dataset
you are using as there seem to be several "milk" datasets. However,
unless you are doing a lot of sequential calculations, it is probably
not the machine precision that is causing your errors, as they would be
much smaller. What may be happening is that you are treating robust
estimates as exact parametric estimates, thus generating larger errors
in your calculations. The simplest way to check this is to run a small
example calculation and print out the successive results that you get.
You may see one result that is clearly wrong and can work out where the
error is being made.

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to menage decimals in order to obtain accurate estimates

mary
I've checked my iteration loop with other dataset, i've not problems with integer numbers or other dataset with decimals but not all decimals dataset. I would like it works with all type of data.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: How to menage decimals in order to obtain accurate estimates

Stephen Ellison
 
> I've checked my iteration loop with other dataset, i've not
> problems with integer numbers or other dataset with decimals
> but not all decimals dataset.
Any R data set that is 'not all decimals' will be represented internally as floating point* (eg c(1, 2, 3, 1.5) consists of four floating point numbers, not three integers and a float), and floating point operations on integer data will cause conversion to floating point as well. That makes it likely that _all_ the operations you are doing treat the data as decimal, whether you can see digits after the decimal point or not.

And R does not round by default until it prints, with the exception of the natural truncation of double precision floating point numbers at around 16 digits (see FAQ 7.31).

That implies to me that your problem is not in the decimal/integer question; rather, you have a problem (or unanticipated feature) in your code that is visible on some floating point data sets but not others and it happens that the problem data set contains visibly non-integer data.

So you're probably going to have to provide a reproducible example before anyone can help further.


*Unless it's a list or data frame, in which case different elements can be different types. But even then, internal floating point arithmetic will always be in floating point.

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
[hidden email] 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.