Description Usage Arguments Details Value Author(s) References See Also Examples
The main functions of the ptw
package, performing
parametric time warping of one or more samples. Features in the
samples are optimally aligned with features in the reference(s). One
may align a single sample to a single reference, several samples to a
single reference, and several samples to several references. In the
latter case, the number of references and samples should be equal. One
may require that all samples are warped with the same warping
function, or one may allow individual warpings for all samples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ptw(ref, samp, selected.traces,
init.coef = c(0, 1, 0), try = FALSE,
warp.type = c("individual", "global"),
optim.crit = c("WCC", "RMS"),
mode = c("forward", "backward"),
smooth.param = ifelse(try, 0, 1e05),
trwdth = 20, trwdth.res = trwdth,
verbose = FALSE, ...)
stptw(ref, samp, init.coef = c(0, 1, 0),
trwdth = 20, trwdth.res = trwdth,
nGlobal = ifelse(length(init.coef) > 3, 5, 0),
...)
## S3 method for class 'ptw'
summary(object, ...)
## S3 method for class 'ptw'
print(x, ...)
|
ref |
reference. Either a vector (containing one reference signal) or a matrix (one reference per row). If more than one reference is specified, the number of reference signals must equal the number of sample signals. |
samp |
sample. A vector (containing one sample signal) or a matrix (one sample per row). |
selected.traces |
optional vector containing the row numbers to
use from |
init.coef |
starting coefficients. The first number is the
zeroth-order coefficient (i.e., a constant shift); further numbers
indicate linear, quadratic, ... stretches. The default is to start
from the identity warping using a quadratic function
( |
try |
if |
warp.type |
default is to treat samples and references as single
entities and align them individually and independently. Using the
argument |
optim.crit |
either |
mode |
either "forward" or "backward": the latter was the original implementation, basically for a point i in the original signal predicting the point j in the signal that would be in position i in the warped signal. The interpretation of the coefficients is counterintuitive. Therefore the default is "forward", simply predicting the location (time) in the warped signal of a particular point. Apart from possible numerical optimisation issues, both warpings should give the same net result. |
smooth.param |
smoothing parameter for smoothing the reference
and sample when |
trwdth |
the width of the triangle in the WCC criterion during the optimization, given as a number of data points. Default: 20 |
trwdth.res |
the width of the triangle in the WCC calculation in
the calculation of the quality of the final result. Default: equal
to |
verbose |
logical, default is |
... |
further arguments to optim |
nGlobal |
for stick optimisations with more than three
coefficients, a more powerful optimisation method is used
( |
x, object |
an object of class "ptw" |
Function ptw
and friends is meant for profile data,
where intensities have been recorded at regular time points; function
stptw
is meant for lists of peaks, for instance obtained after
peak-picking the profile data. The latter option is less flexible
(Euclidean distance and backward warping have not been implemented,
and only global alignment is possible)
but is much faster, especially for larger data sets.
In the optimization mode (try = FALSE
), the function
optimizes the warping coefficients using the chosen criterion (either
"WCC" or "RMS"). For "RMS", the data are smoothed before the
optimization, but the quality of the final warping is measured on the
unsmoothed data. For "WCC", the warping is performed using
trwdth
as the triangle width, but the quality of the final
solution is measured using trwdth.res
.
If try = TRUE
is used as an argument, the function does not
start an optimization, but just calculates the warping for the given
warp function (init.coef
); if smooth.param
is larger
than zero for the RMS criterion, the RMS of the smoothed patterns is
calculated. The WCC criterion uses trwidth.res
as the triangle
width in this case.
Five situations can be distinguished:
One sample and one reference: this obviously leads to one warping
function regardless of the setting of warp.type
.
Several samples, all warped to the same single reference, each with
its own warping function: this is the default behaviour
(warp.type = "individual"
)
Several samples, warped to an equal number of references
(pair-wise), with their own warping functions: this is the default
behaviour (warp.type = "individual"
)
Several samples, warped to one reference, with one warping function
(warp.type = "global"
)
Several samples, warped to an equal number of references
(pair-wise), with one warping function
(warp.type = "global"
)
A list of class "ptw" containing:
reference |
the reference(s) used as input |
sample |
the sample(s) used as input |
warped.sample |
the warped sample |
warp.coef |
the warping coefficients |
warp.fun |
the warped indices (not for |
crit.value |
the value of the chosen criterion, either "WCC" or "RMS" |
optim.crit |
the chosen criterion, either "WCC" or "RMS" |
warp.type |
the chosen type of warping, either "individual" or "global" |
Jan Gerretzen, Ron Wehrens
Eilers, P.H.C. (2004) "Parametric Time Warping", Analytical Chemistry, 76 (2), 404 – 411.
Bloemberg, T.G., et al. (2010) "Improved parametric time warping for Proteomics", Chemometrics and Intelligent Laboratory Systems, 104 (1), 65 – 74.
WCC
, RMS
, select.traces
,
gaschrom
, lcms
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | data(gaschrom)
ref <- gaschrom[1,]
samp <- gaschrom[16,]
gaschrom.ptw <- ptw(ref, samp)
summary(gaschrom.ptw)
## same with sticks (peak lists)
refst <- gaschrom.st[1]
sampst <- gaschrom.st[16]
gaschrom.st.ptw <- stptw(refst, sampst, trwdth = 100)
summary(gaschrom.st.ptw)
## Not run:
## comparison between backward and forward warping
gaschrom.ptw <- ptw(ref, samp, init.coef = c(0, 1, 0, 0), mode = "backward")
summary(gaschrom.ptw)
gaschrom.ptw <- ptw(ref, samp, init.coef = c(-10, 1, 0, 0), mode = "forward")
summary(gaschrom.ptw)
## #############################
## many samples warped on one reference
ref <- gaschrom[1,]
samp <- gaschrom[2:16,]
gaschrom.ptw <-
ptw(ref, samp, warp.type = "individual", verbose = TRUE,
optim.crit = "WCC", trwdth = 100, init.coef = c(0, 1, 0))
summary(gaschrom.ptw)
## "individual" warping not implemented for sticks; do separate warpings
## instead
refst <- gaschrom.st[1]
sampst <- gaschrom.st[2:16]
gaschrom.st.ptw.list <-
lapply(sampst,
function(smpl)
stptw(refst, list(smpl), trwdth = 100, init.coef = c(0, 1, 0)))
t(sapply(gaschrom.st.ptw.list, "[[", "warp.coef"))
t(sapply(gaschrom.st.ptw.list, "[[", "crit.value"))
## #############################
## several samples on several references individually
ref <- gaschrom[1:8,]
samp <- gaschrom[9:16,]
gaschrom.ptw <-
ptw(ref, samp, warp.type = "individual",
optim.crit = "WCC", trwdth = 100, init.coef = c(0, 1, 0))
summary(gaschrom.ptw)
## stick version
gaschrom.st.ptw.list <-
mapply(function(x, y)
stptw(list(x), list(y), trwdth = 100, init.coef = c(0, 1, 0)),
gaschrom.st[1:8], gaschrom.st[9:16],
SIMPLIFY = FALSE)
t(sapply(gaschrom.st.ptw.list, coef))
## #############################
## several samples on several references: one, global warping
gaschrom.ptw <- ptw(ref, samp, warp.type = "global",
optim.crit = "WCC", init.coef = c(0, 1, 0))
summary(gaschrom.ptw)
refst <- gaschrom.st[1:8]
sampst <- gaschrom.st[9:16]
gaschrom.st.ptw <- stptw(refst, sampst, trwdth=100, init.coef = c(0, 1, 0))
summary(gaschrom.st.ptw)
## #################################################################
## Example of a three-way data set#
## #################################################################
## first bring all samples to the same scale
data(lcms)
lcms.scaled <- aperm(apply(lcms, c(1,3),
function(x) x/mean(x) ), c(2,1,3))
## add zeros to the start and end of the chromatograms
lcms.s.z <- aperm(apply(lcms.scaled, c(1,3),
function(x) padzeros(x, 250) ), c(2,1,3))
## define a global 2nd degree warping
warp1 <- ptw(lcms.s.z[,,2], lcms.s.z[,,3], warp.type="global")
warp.samp <- warp1$warped.sample
warp.samp[is.na(warp.samp)] <- 0
## refine by adding 5th degree warpings for individual chromatograms
warp2 <- ptw(lcms.s.z[,,2], warp.samp, init.coef=c(0,1,0,0,0,0))
warp.samp2 <- warp2$warped.sample
warp.samp2[is.na(warp.samp2)] <- 0
## compare TICs
layout(matrix(1:2,2,1, byrow=TRUE))
plot(colSums(lcms.s.z[,,2]), type="l", ylab = "",
main = "TIC: original data")
lines(colSums(lcms.s.z[,,3]), col=2, lty=2)
plot(colSums(lcms.s.z[,,2]), type="l", ylab = "",
main = "TIC: warped data")
lines(colSums(warp.samp2), lty=2, col=2)
## ###########################
## stick version of this warping - note that the peaks have been picked
## from the scaled profiles. Note that here we need to take list
## elements: every sample is a list of mz channels.
warp1.st <- stptw(lcms.pks[[2]], lcms.pks[[3]], trwdth = 100)
summary(warp1.st)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.