[Bioc-sig-seq] IRanges runmean Arithmetic Precision

Aboyoun, Patrick E paboyoun at fhcrc.org
Mon Feb 14 23:17:03 CET 2011

As Martin mentioned Rle methods for runsum, runwtsum, runmean, viewSums, and viewMeans could be more numerically precise, perhaps by following base R's lead and use long doubles, when available. However, since floating point arithmetic has only finite precision, this will only make the problem less pervasive, not remove it entirely.

Here are some tricks you can employ to get around this issue:

1) If your metric has a handful of significant digits, create integers out of your decimal values and operate on those integers. For example,

x <- Rle(seq(0.9999, 1, length = 100) * pi, 1:100)
shiftDecPlaces <- 5
runValue(x) <- as.integer(round((10^shiftDecPlaces) * runValue(x), shiftDecPlaces))
means <- round(runmean(x, 21, endrule = "constant")/(10^shiftDecPlaces), shiftDecPlaces)

2) If you want to focus on forcing small numbers (in absolute terms) to be zero, use zapsmall on the run values

x <- Rle(c(-1, seq(-1e-16, 1e-16, length = 98), 1), 1:100)
runValue(x) <- zapsmall(runValue(x), digits = 7)

These techniques can be extended to RleList objects as well, so you might want to experiment with your data to see what might suit your needs best.


----- Original Message -----
From: "Dario Strbenac" <D.Strbenac at garvan.org.au>
To: "Martin Morgan" <mtmorgan at fhcrc.org>, "D Strbenac" <D.Strbenac at garvan.org.au>
Cc: bioc-sig-sequencing at r-project.org
Sent: Monday, February 14, 2011 2:00:26 PM
Subject: Re: [Bioc-sig-seq] IRanges runmean Arithmetic Precision

Ah, thanks for the pointer to the section of the FAQ. This cleared it up for me.

Dario Strbenac
Research Assistant
Cancer Epigenetics
Garvan Institute of Medical Research
Darlinghurst NSW 2010

Bioc-sig-sequencing mailing list
Bioc-sig-sequencing at r-project.org

More information about the Bioc-sig-sequencing mailing list