Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time...

13
The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics / Analytical Chemistry www.ru.nl/imm

Transcript of Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time...

Page 1: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

The PTW packageGlobal Parametric Time Warping in RTom Bloemberg

Institute for Molecules and Materials

Dept. Chemometrics / Analytical Chemistry

www.ru.nl/imm

Page 2: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Chromatographic example

The PTW packageGlobal Parametric Time Warping in R

Page 3: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Alignment

• Also: – ‘Synchronization’

– ‘(Time) Warping’

• Shift, stretch, compress• Applications in:

– Speech analysis

– Chromatography– NMR

– …

The PTW packageGlobal Parametric Time Warping in R

Page 4: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Parametric Time Warping1

• Before warping:

• After warping:

• Polynomial model of warping function:

• Minimize:

...)( 2210 +++= tataatw

The PTW packageGlobal Parametric Time Warping in R

1 Eilers, P.H.C. Analytical Chemistry 76 (2) 404-411 2004

∑=

=Q

q

qqtatw

0

)(

)Sample()Reference( tt ↔

))(Sample()Reference( twt ↔

( )∑ −i

ii twt 2))((Sample)(Reference

Page 5: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

A single alignment

> library(ptw)

> data(chromatograms)

> chromatograms <- basel.off(chromatograms)

> C.warped <- ptw(chromatograms[1, ], chromatograms[1 6, ])

> plot(C.warped, plot.orig=TRUE, plot.wf=TRUE)

The PTW packageGlobal Parametric Time Warping in R

Page 6: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

> library(ptw)

> data(chromatograms)

> chromatograms <- basel.off(chromatograms)

> C.warped <- ptw(chromatograms[1:8, ], chromatograms [9:16, ])

> plot(C.warped, plot.orig=TRUE, plot.wf=TRUE)

Multiple alignments

The PTW packageGlobal Parametric Time Warping in R

> library(ptw)

> data(chromatograms)

> chromatograms <- basel.off(chromatograms)

> C.warped <- ptw(chromatograms[1, ], chromatograms[2 :16, ])

> plot(C.warped, plot.orig=TRUE, plot.wf=TRUE)

Page 7: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

LC-MS data

The PTW packageGlobal Parametric Time Warping in R

m/z

T

T

m/z

Page 8: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Tm/z

LC-MS data

The PTW packageGlobal Parametric Time Warping in R

m/z

T

Sig

nal

Page 9: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Global Alignment

The PTW packageGlobal Parametric Time Warping in R

• Choose ‘High Quality’ traces using CODA2,3

2Windig, W. Analytical Chemistry 68 (20) 3602-3606 1996

3Christin, C. Analytical Chemistry 80 (18) 7012-7021 2008

m/z

Time> library(ptw)

> data(LCMS)

> HQ <- coda(LCMS, combine=c(1,2), windows=c(3,1), n Chroms=5)

> LCMS.Warped <- ptw(LCMS[1, , ], LCMS[2, , ], HQ=HQ, align.method=“global”)

Page 10: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Global Alignment

The PTW packageGlobal Parametric Time Warping in R

> library(ptw)

> data(LCMS)

> HQ <- coda(LCMS, combine=c(1,2), windows=c(3,1), n Chroms=5)

> LCMS.Warped <- ptw(LCMS[1,,], LCMS[2,,], HQ=HQ, align.method = “global”)

> library(ptw)

> data(LCMS)

> HQ <- coda(LCMS, combine=c(1,2), windows=c(3,1), n Chroms=5)

> LCMS.Warped <- ptw(colSums(LCMS[1, , HQ]), colSums(LCMS[2, , HQ]), align.method = “individual”)

Page 11: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Discussion

The PTW packageGlobal Parametric Time Warping in R

• Second alignment package for R (next to dtw)

• Individual, multiple and global warpings• Trace selection (CODA)• Baseline removal (asymmetric LS)• Smoothing (Whittaker)

Page 12: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Planning

The PTW packageGlobal Parametric Time Warping in R

• Implement semi-PTW

• Implement other distance measures• Connect with dtw-package• Release on 1 September 2009

Page 13: Global Parametric Time Warping in R The PTW package · The PTW package Global Parametric Time Warping in R Tom Bloemberg Institute for Molecules and Materials Dept. Chemometrics

Acknowledgements

Jan Gerretzen

Hans WoutersRon WehrensLutgarde Buydens

Paul Eilers

Jolein GloerichHans WesselsBert van der Heuvel

The PTW packageGlobal Parametric Time Warping in R