[R] baseline fitters
Thaden, John J
ThadenJohnJ at uams.edu
Tue Feb 20 19:23:02 CET 2007
I am pretty pleased with baselines I fit to chromatograms using the
runquantile() function in caTools(v1.6) when its probs parameter is
set to 0.2 and its k parameter to ~1/20th of n (e.g., k ~ 225 for n ~
4500, where n is time series length). This ignores occasional low-
side outliers, and, after baseline subtraction, I can re-adjust any
negative values to zero.
But runquantile's computation time proves exceedingly long for my large
datasets, particularly if I set the endrule parameter to 'func'. Here is
what caTools author Jarek Tuszynski says about relative speeds of various
running-window functions:
- runmin, runmax, runmean run at O(n)
- runmean(..., alg="exact") can have worst case speed of O(n^2) for
some small data vectors, but average case is still close to O(n).
- runquantile and runmad run at O(n*k)
- runmed - related R function runs at O(n*log(k))
The obvious alternative runmin() performs poorly due to dropout (zero-
and low-value 'reverse-spikes') in the data. And runmed fits a baseline that,
upon subtraction, obviously will send half the values into the negative, not
suitable for my application. I jimmied something together
with runmin and runmedian that is considerably faster; unfortunately,
the fit seems less good, at least by eye, due still to the bad runmin
behavior.
I'd be interested in other baseline fitting suggestions implemented
or implementable in R (I'm using v. 2.4.1pat under WinXP). Why, for
instance, can I not find a running trimmean function? Because it
offers no computational savings over runquantile?
Also, the 'func' setting for the caTools endrule parameter--which adjusts the
value of k as ends are approached--is said not to be optimized (using
this option does add further time to computations). Is there an alter-
native that would be speedier, e.g., setting endrule = "keep" and then
subsequently treating ends with R's smoothEnds() function?
-John Thaden
Little Rock, Arkansas USA
Confidentiality Notice: This e-mail message, including any a...{{dropped}}
More information about the R-help
mailing list