Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged...

103
Lecture 2: Covariance and correlation Shane Elipot The Rosenstiel School of Marine and Atmospheric Science, University of Miami Created with {Remark.js} using {Markdown} + {MathJax} Processing math: 99%

Transcript of Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged...

Page 1: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Lecture2:

Covarianceandcorrelation

ShaneElipotTheRosenstielSchoolofMarineandAtmosphericScience,

UniversityofMiami

Createdwith{Remark.js}using{Markdown}+{MathJax}

Processingmath:99%

Page 2: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

References

[1]Bendat,J.S.,&Piersol,A.G.(2011).Randomdata:analysisandmeasurementprocedures(Vol.729).JohnWiley&Sons.

[2]Thomson,R.E.,&Emery,W.J.(2014).Dataanalysismethodsinphysicaloceanography.Newnes.dx.doi.org/10.1016/B978-0-12-387782-6.00003-X

[3]Taylor,J.(1997).Introductiontoerroranalysis,thestudyofuncertaintiesinphysicalmeasurements.

[4]Press,W.H.etal.(2007).Numericalrecipes3rdedition:Theartofscientificcomputing.Cambridgeuniversitypress.

[5]Kanji,G.K.(2006).100statisticaltests.Sage.

[6]vonStorch,H.andZwiers,F.W.(1999).StatisticalAnalysisinClimateResearch,CambridgeUniversityPress

Processingmath:100%

Page 3: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Lecture2:Outline1. Covariance&correlation2. Laggedcovariance&correlation3. Aquicklookat"Aleisurelylookatthebootstrap,thejackknife,

andcross-validation"4. Covarianceandcorrelationofbivariatevariables

Page 4: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

1.Covariance&Correlation

Page 5: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Covariance(definitions)

Whereaswepreviouslydealtwithasingler.v.x,wenowdealwithtwor.vs.,xandy.Inparticular,weareinterestedinevaluatinghowmuchtheycovary,possiblytomakesomestatementaboutacausationfromonevariabletotheother,perhapsexplainedbyadynamicalrelationship.

Perhapsthefirstquantitytoconsideristhecovarianceofxandy:

Cov(x, y) = Cxy ≡ E[(x − μx)(y − μy)]

Thevarianceofxisaparticularcaseofcovariancewhenyandxarethesamer.v.:

Cov(x, x) = Cxx ≡ E[(x − μx)(x − μx)] = E[(x − μx)2] = Var(x) = σ2x

Page 6: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Covariance(definitions)

iscalledthejointprobabilitydensityfunctionorjointPDF.

If where and arethePDFsof and ,respectively,thenitissaidthat and areindependent.

Justlikewewereabletobuildhistogramsfromsamples ofasingler.v. ,wecanalsobuild2Dhistogramsfrompairsofsamples

inordertoestimatethejointPDF.

Cxy =

=

E[(x− )(y− )] = E[xy] −μx μy μxμy

(x− )(y− )p(x, y) dxdy∫ +∞

−∞μx μy

p(x, y)

p(x, y) = p(x)p(y) p(x) p(y) x yx y

Xnx

( , )Xn Yn

Page 7: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation

Sincether.v. and canbeofdifferentnatureormagnitude,wecanconsiderthenormalizedcovariance,thatisthecorrelationbetween and

Sincewehavethepropertythat ,thecorrelationisanumberbetween and .

If itissaidthatthevariable and areuncorrelated.

Iftwor.vs.areindependent thentheyarealsouncorrelated,butiftwor.vs.areuncorrelated,theyarenotnecessarilyindependent(i.e.maybe )

x y

x y

= = =ρxyCxy

CxxCyy− −−−−−

Cxy

σxσy

E[(x− )(y− )]μx μy

{E[(x− ]E[(y− ]}μx)2 μy)21/2

| | ≤Cxy σxσy−1 1

= 0ρxy x y

[p(x, y) = p(x)p(y)]

p(x, y) ≠ p(x)p(y)

Page 8: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Covariance&Correlation:estimation

Justlike isanunbiasedestimateof ,anunbiasedestimateofthecovarianceis

andanestimateof is

iscalledthePearson'scorrelationcoefficient.Itmeasurestherelativestrengthofalinearrelationshipbetween and (seeLecture3).Anonlinearrelationshipornoisewillmake tendstozero.

s2x σ2x

= = ( − )( − )sxy Cxy1

N − 1∑n=1

N

Xn X¯ ¯¯

Yn Y¯ ¯¯

ρxy

rxy = = =ρxysxy

s2xs2y

− −−−√( − )( − )∑N

n=1 Xn X¯ ¯¯

Yn Y¯ ¯¯

[ ( − ( − ]∑Nn=1 Xn X

¯ ¯¯ )2 ∑Nn=1 Yn Y

¯ ¯¯ )21/2

rxyx y

rxy

Page 9: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation:significance

Since and arer.vs., isalsoar.v.withagivendistribution.

Typically,onewantstotestif isdifferentfromzero.Kanji(2006),reference[5]recommendstocalculatethefollowingteststatistic(test12)

whichfollowstheStudent'st-distributionwith degreesoffreedom.

x y rxy

rxy

t = ∼ t(0,N − 2)rxy

1 − r2xy− −−−−−√

N − 2− −−−−√

N − 2

Page 10: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation:confidenceinterval

Alternatively,onemaywanttoderiveCIsfor byusingtheFishertransformedvariable:

Since ,theCIderivedfor canbeusedtocalculateCIsfor .

Theteststatistic

canbeusedtotestthenullhypothesesthat ,seetest13ofKanji(2006),reference[5].

rxy

w = = ln( ) ∼ N [ ln( ), ]tanh−1 rxy12

1 + rxy1 − rxy

12

1 + rxy1 − rxy

1N − 3− −−−−√

= tanhwrxy wrxy

z = ∼ N (0, 1)w− w0

1/ N − 3− −−−−√

= tanhρxy w0

Page 11: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation:effectivedegreesoffreedom

Acrucialaspectoftestingforthesignificanceof istousetherightvaluefor ,whichisthesizeofyoursampleifyourdatapointsareindependent.Otherwise,alowervalueof ,knownastheeffectivedegreeoffreedom,needstobeconsidered.Wewillexploretheseaspectslaterandduringthepracticalthisafternoon.

ρxyN

N

Page 12: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Serialcorrelation:example

Let'sconsiderarealization ofatimeseries ,andcalculatethecorrelations :

Since , and arecorrelated,hencetheyarenotindependentsamples.Itissaidthat isseriallycorrelated,thusthenumberofdegreesoffreedomislessthan .Thevarianceandbiasofcorrelationestimatesinvolving arelikelytobeaffected.

, ,… ,X1 X2 XN x(t)ρ( , )Xn Xn+1

≠ 0rxy Xn Xn+1x

Nx

Page 13: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Spearmancorrelation

ThePearson'scorrelationcoefficientisnottheonlycorrelationcoefficient.TherankcorrelationcoefficientorSpearmancorrelationcoefficientis

where istherankofthedatasample .

= 1 −rs6 ( −∑N

n=1 Rx;n Ry;n)2

N ( − 1)N 2

Rx;n Xn

Page 14: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Spearmancorrelation

ThePearson'scorrelationcoefficientisnottheonlycorrelationcoefficient.TherankcorrelationcoefficientorSpearmancorrelationcoefficientis

where istherankofthedatasample .Asanexample,with

= 1 −rs6 ( −∑N

n=1 Rx;n Ry;n)2

N ( − 1)N 2

Rx;n XnN = 3

Xn

4−13

Rx;n

312

Yn

1123

Ry;n

132

−Rx;n Ry;n

2− 20

Page 15: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Spearmancorrelation

ThePearson'scorrelationcoefficientisnottheonlycorrelationcoefficient.TherankcorrelationcoefficientorSpearmancorrelationcoefficientis

where istherankofthedatasample .Asanexample,with

measuresiftherelationshipbetween and ismonotonicallyincreasing( >0)ordecreasing( ).Forlarge ,

under .

= 1 −rs6 ( −∑N

n=1 Rx;n Ry;n)2

N ( − 1)N 2

Rx;n XnN = 3

Xn

4−13

Rx;n

312

Yn

1123

Ry;n

132

−Rx;n Ry;n

2− 20

rs x yrs < 0rs N

≈ N (0, 1/ )rs N − 1− −−−−

√ : = 0H0 rs

Page 16: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

PearsonvsSpearman

Page 17: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Covariance:multivariatecase

Ifyouaredealingwithmorethantwor.vs.,let'ssay variablesforwhichyouhave samples,you

needtobuildthecovariancematrix

orthecorrelationmatrix

Methodstostudythesematriceswillbecoveredinlecture5(Eigentechniques).

P, ,… ,x1 x2 xP n = 1, 2,… ,N

≡Cxx

⎣⎢⎢⎢⎢⎢Cx1x1

Cx2x1

⋮CxP x1

Cx1x2

Cx2x2

⋮CxP x2

⋯…

Cx1xP

Cx2xP

⋮CxP xP

⎦⎥⎥⎥⎥⎥

≡ρxx

⎣⎢⎢⎢⎢⎢ρx1x1

ρx2x1

⋮ρxP x1

ρx1x2

ρx2x2

⋮ρxP x2

⋯…

ρx1xP

ρx2xP

⋮ρxP xP

⎦⎥⎥⎥⎥⎥

Page 18: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Covariance:multivariatecase;estimate

Ifyouhave r.vs. forwhichyouhavesamples,typicallyarrangedina datamatrix

Theestimateofthecovariancematrixis

P , ,… ,x1 x2 xPn = 1, 2,… ,N N × P

X = [ , , ⋯ , ] =X1 X2 XP

⎣⎢⎢⎢⎢⎢

(1)X1

(2)X1

⋮(N )X1

(1)X2

(2)X2

⋮(N )X2

…⋯

⋯⋯

(1)XP

(2)XP

⋮(N )XP

⎦⎥⎥⎥⎥⎥

= X =Cxx1

N−1 XT

⎣⎢⎢⎢⎢⎢⎢

Cx1x1

Cx2x1

CxP x1

Cx1x2

Cx2x2

CxP x2

Cx1xP

Cx2xP

CxP xP

⎦⎥⎥⎥⎥⎥⎥

Page 19: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation:beware!

Itisnotbecauseyoufindazeroornonsignificantcorrelationbetweentwor.vs.thatthereisnoformalordynamicalrelationshipbetweenthetwo!

Page 20: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Correlation:beware!

ThisanimationshowsthecorrelationcoefficientbetweentwosinusoidsignalsFandGasafunctionofphaselag.

GifbyDivergentdata-Ownwork,CCBY-SA4.0,Link

Page 21: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

2.LaggedCovariance&Correlation

Page 22: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Wenowgeneralizetheconceptofcovariancebyconsideringtwor.vs.forwhichthesamplesareordered,maybeasafunctionoftime(orofspace).Inthiscase,thesamplesarerealizationsoftime

series.t

Page 23: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Wenowgeneralizetheconceptofcovariancebyconsideringtwor.vs.forwhichthesamplesareordered,maybeasafunctionoftime(orofspace).Inthiscase,thesamplesarerealizationsoftime

series.

Thecovariancestatisticpresentedearlierisaspecialcaseofthe(cross-)covariancefunction,functionoflag

If , iscalledtheauto-covariancefunctionof .

t

τ

(τ) = E{[x(t) − ][y(t+ τ) − ]}Cxy μx μy

y ≡ x (τ)Cxx x

Page 24: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Wenowgeneralizetheconceptofcovariancebyconsideringtwor.vs.forwhichthesamplesareordered,maybeasafunctionoftime(orofspace).Inthiscase,thesamplesarerealizationsoftime

series.

Thecovariancestatisticpresentedearlierisaspecialcaseofthe(cross-)covariancefunction,functionoflag

If , iscalledtheauto-covariancefunctionof .

Notethatherewehaveassumedthatthepopulationmeans andareconstantwithtime,inwhichcaseitissaidthat and

arestationarytimeseries.

t

τ

(τ) = E{[x(t) − ][y(t+ τ) − ]}Cxy μx μy

y ≡ x (τ)Cxx x

μxμy x(t) y(t)

Page 25: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Instatisticsandengineeringsciencesthenamescanbedifferent.Inparticular,inMatlab,thefollowingfunctioniscalledthecross-correlationfunction

whichissimilartothecovariancefunctionbutwithoutsubtractingthemeans.Assuch

(τ) = E{x(t)y(t+ τ)}Rxy

(τ) = (τ) −Cxy Rxy μxμy

Page 26: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Instatisticsandengineeringsciencesthenamescanbedifferent.Inparticular,inMatlab,thefollowingfunctioniscalledthecross-correlationfunction

whichissimilartothecovariancefunctionbutwithoutsubtractingthemeans.Assuch

Withsuchnamingconvention, istheauto-correlationfunction.

(τ) = E{x(t)y(t+ τ)}Rxy

(τ) = (τ) −Cxy Rxy μxμy

(τ)Rxx

Page 27: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Theauto-covarianceandauto-correlationfunctionsareevenfunctionsof (i.e.symmetricaround ):

Thecross-covarianceandcross-correlationfunctionsareneitheroddnoreven,butsatisfies

τ 0

(−τ)Cxx

(−τ)Rxx

==

(τ)Cxx

(τ)Rxx

(−τ)Cxy

(−τ)Rxy

==

(τ)Cyx

(τ)Ryx

Page 28: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariance&correlationfunctions

Theauto-covarianceandauto-correlationfunctionsareevenfunctionsof (i.e.symmetricaround ):

Thecross-covarianceandcross-correlationfunctionsareneitheroddnoreven,butsatisfies

Beware!Checktheconventionsofthesoftwaresyouuse!InMatlab,thecross-correlationfunctionisdefinedas

.

τ 0

(−τ)Cxx

(−τ)Rxx

==

(τ)Cxx

(τ)Rxx

(−τ)Cxy

(−τ)Rxy

==

(τ)Cyx

(τ)Ryx

E[x(t+ τ)y(t)] = (−τ) = (τ)Rxy Ryx

Page 29: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationcoefficient

Thelaggedcorrelationcoefficientis

(τ) = =ρxy(τ)Cxy

(0) (0)Cxx Cyy− −−−−−−−−−√

(τ)Cxy

σxσy

Page 30: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationcoefficient

Thelaggedcorrelationcoefficientis

Itcanbechallengingbutlet'strynottoconfusecorrelationfunctionandlaggedcorrelation.

(τ) = =ρxy(τ)Cxy

(0) (0)Cxx Cyy− −−−−−−−−−√

(τ)Cxy

σxσy

Page 31: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationcoefficient

Thelaggedcorrelationcoefficientis

Itcanbechallengingbutlet'strynottoconfusecorrelationfunctionandlaggedcorrelation.

Youmaywanttocall thelaggedauto-correlationcoefficient,butitisusuallycalledtheautocorrelationfunction(whichshouldbeusedfor ).

(τ) = =ρxy(τ)Cxy

(0) (0)Cxx Cyy− −−−−−−−−−√

(τ)Cxy

σxσy

(τ) =ρxx(τ)Cxx

(0)Cxx

(τ)Rxx

Page 32: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationcoefficient

Thelaggedcorrelationcoefficientis

Itcanbechallengingbutlet'strynottoconfusecorrelationfunctionandlaggedcorrelation.

Youmaywanttocall thelaggedauto-correlationcoefficient,butitisusuallycalledtheautocorrelationfunction(whichshouldbeusedfor ).

Distributionsundernullhypothesesfor or aredifficulttocomebyandrequiretomakeseveralassumptions(seepracticalthisafternoon).

(τ) = =ρxy(τ)Cxy

(0) (0)Cxx Cyy− −−−−−−−−−√

(τ)Cxy

σxσy

(τ) =ρxx(τ)Cxx

(0)Cxx

(τ)Rxx

(τ)ρxy (τ)ρxx

Page 33: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariancefunctionestimates

Considertwor.vs. and forwhichwehave samplesseparatedbyconstantintervals .Oneestimateofthecross-covariancefunctionatlags is

where arethepossiblelags.Itcanbeshownthatthisestimatorisunbiased(ifthepopulationmeansareknownratherthanestimated).

x y NΔt

= kΔtτk

(kΔt) = ( − )( − )C(1)xy

1N − |k|

∑n=1

N−|k|

Xn X¯ ¯¯

Yn+k Y¯ ¯¯

k = 0,±1,±2,…,±(N − 1)

Page 34: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcovariancefunctionestimates

Considertwor.vs. and forwhichwehave samplesseparatedbyconstantintervals .Oneestimateofthecross-covariancefunctionatlags is

where arethepossiblelags.Itcanbeshownthatthisestimatorisunbiased(ifthepopulationmeansareknownratherthanestimated).Thereexistsanotherestimatorof

whichis

whichistypicallycalledthe"biased"estimatorbuthasasmaller

randomerrorcomparedto .Seepracticalthisafternoon.

x y NΔt

= kΔtτk

(kΔt) = ( − )( − )C(1)xy

1N − |k|

∑n=1

N−|k|

Xn X¯ ¯¯

Yn+k Y¯ ¯¯

k = 0,±1,±2,…,±(N − 1)

(τ)Cxy

(kΔt) = ( − )( − )C(2)xy

1N

∑n=1

N−|k|

Xn X¯ ¯¯

Yn+k Y¯ ¯¯

C(1)xy

Page 35: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationestimate

Anestimateofthelaggedcorrelationcoefficientis

wheretheuseof cancelsoutthefactor intheformulasforthevariances.ThisestimatorisaccessedinMatlabusingthescaleoption asin

[rhox,lags] = xcov(Y,X,'coeff');

or

[rhox,lags] = xcorr(Y-mean(Y),X-mean(X),'coeff');

(kΔt) = =ρxy(kΔt)C

(2)xy

[ ]C(2)xx C

(2)yy

1/2

( − )( − )∑N−|k|n=1 Xn X

¯ ¯¯Yn+k Y

¯ ¯¯

[ ( − ( − ]∑Nn=1 Xn X

¯ ¯¯ )2 ∑Nn=1 Yn Y

¯ ¯¯ )21/2

C(2)xy N

'coeff'

Page 36: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationasameasureofmemory

Lag scatterplotsandcor.coeff. forAgulhas

transport

m ρ( , )Xn Xn+m

Page 37: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationasameasureofmemory

LaggedautocorrelationcoefficientforAgulhastransporttimeseries.With ,possiblelagsareN = 808 τ = −807,…,807

Page 38: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationasameasureofmemory

LaggedautocorrelationcoefficientforAgulhastransporttimeseries.With ,possiblelagsareN = 808 τ = −807,…,807

Page 39: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationfortimedelay

Thelaggedcorrelationorcovariancefunctioncanbeusedtodetermineatimedelaybetweentwosignals.Let'sassumethatatransmittedsignal(atimeseries) isreceivedas

where isanattenuationfactor, isaconstanttimedelayequaltolet'ssayadistance dividedbyapropagationvelocity ,and isanaddednoiseuncorrelatedwith .

x(t)

y(t) = αx(t− ) + n(t)τ0

α = d/cτ0d c

n(t) x(t)

Page 40: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationfortimedelay

Thelaggedcorrelationorcovariancefunctioncanbeusedtodetermineatimedelaybetweentwosignals.Let'sassumethatatransmittedsignal(atimeseries) isreceivedas

where isanattenuationfactor, isaconstanttimedelayequaltolet'ssayadistance dividedbyapropagationvelocity ,and isanaddednoiseuncorrelatedwith .Itiseasilyshownthat

x(t)

y(t) = αx(t− ) + n(t)τ0

α = d/cτ0d c

n(t) x(t)

(τ) = α (τ − )Rxy Rxx τ0

Page 41: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationfortimedelay

Thelaggedcorrelationorcovariancefunctioncanbeusedtodetermineatimedelaybetweentwosignals.Let'sassumethatatransmittedsignal(atimeseries) isreceivedas

where isanattenuationfactor, isaconstanttimedelayequaltolet'ssayadistance dividedbyapropagationvelocity ,and isanaddednoiseuncorrelatedwith .Itiseasilyshownthat

Sincethemaximumof isfor ,thepeakvalueofoccurswhen whichallowsustodeterminethe

constanttimedelay.

x(t)

y(t) = αx(t− ) + n(t)τ0

α = d/cτ0d c

n(t) x(t)

(τ) = α (τ − )Rxy Rxx τ0

(τ)Rxx τ = 0(τ)Rxy τ = τ0

Page 42: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Laggedcorrelationfortimedelay

Page 43: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

ExamplefromDiNezioetal.2009investigatingtherelationshipbetweenGulfStreamtransportthroughtheFloridaStraitandwindstresscurl.

Laggedcorrelationfortimedelay

Page 44: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationandeffectivedegreesoffreedom

Theconceptofeffectivedegreesoffreedomand(de)correlationtimescaleareintimatelylinked.If isthenumberofevenlydistributedsamplesatinterval ,thenthenumberofeffectivedegreesoffreedomis

where isthelengthofyourtimeseriesand isthedecorrelationtimescale,alsoreferredtoasanintegraltimescale. givesyouthenumberofeffectivelyindependentsamplesinyourdata.

NΔt

= =NeffNΔtT0

T

T0

T T0Neff

Page 45: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationandeffectivedegreesoffreedom

Theconceptofeffectivedegreesoffreedomand(de)correlationtimescaleareintimatelylinked.If isthenumberofevenlydistributedsamplesatinterval ,thenthenumberofeffectivedegreesoffreedomis

where isthelengthofyourtimeseriesand isthedecorrelationtimescale,alsoreferredtoasanintegraltimescale. givesyouthenumberofeffectivelyindependentsamplesinyourdata.

Ifyoursamplesareindependent,thedecorrelationtimescaleisthetimestepofyourtimeseries and .Thereisnotonlyonewayofcomputing orestimating .Infact,itdependsonthestatisticsforwhichthesewillbeused.

NΔt

= =NeffNΔtT0

T

T0

T T0Neff

Δt = NNeffNeff T0

Page 46: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Decorrelationtimescale

Onecommondefinitionofthedecorrelationorintegraltimescaleforther.v. is(e.g.ThompsonandEmery(2014),section3.15.2)

Agraphicalinterpretationof isgiveninFigure3.13ofEmeryandThompson(2014):

x

= (τ) dτ = (τ) dτT01(0)Cxx

∫ +∞

−∞Cxx

2(0)Cxx

∫ +∞

0Cxx

T0× (0) = (τ) dτT0 Cxx ∫ +∞

−∞ Cxx

Page 47: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Decorrelationtimescale

Anestimateof isobtainedbyapplyingthetrapezoidalintegrationformulafortheintegral,i.e.

where isthesamplevarianceestimateof and istheindexwherethesummationisstopped.

T0

= ΔtT02s2x

∑n=0

M−1 [(n+ 1)Δt] + [nΔt]Cxx Cxx

2

= (0)s2x Cxx x M

Page 48: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Decorrelationtimescale

Anestimateof isobtainedbyapplyingthetrapezoidalintegrationformulafortheintegral,i.e.

where isthesamplevarianceestimateof and istheindexwherethesummationisstopped.

NotethatThompsonandEmery(2014),section5.3.5,giveanalternateformula

wheretheyomittedthefactor andessentiallyintegratedonlyonesideoftheauto-covariancefunction.ThisisalsotheformulatypicallyusedinLagrangianstudies.(AndthisiswhatIuse).

T0

= ΔtT02s2x

∑n=0

M−1 [(n+ 1)Δt] + [nΔt]Cxx Cxx

2

= (0)s2x Cxx x M

= ΔtT01s2x

∑n=0

M−1 [(n+ 1)Δt] + [nΔt]Cxx Cxx

2

2

Page 49: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Decorrelationtimescale

Thereareseveralsourcesoferrorenteringformulasfor :estimateofthevariance,estimateoftheautocovariance,andtruncationofthetrapezoidalintegration.Thetruncationoftheintegrationmaybewheretheestimatedautocovariancefunctionreachesaconstantvaluebutthismaynothappeninpractice.Anotherpossibilityistointegrateuptothefirstzerocrossingoruptowheretheautocorrelationisinsignificant.Seepracticalsessionthisafternoon.

T0

Page 50: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationandeffectivedegreesoffreedom

Onceyouhaveobtainedanintegraltimescale andcalculatedtheeffectivedegreesoffreedom ,youmayusethisparametertocalculateCIsforsamplemeans.

T0Neff

Page 51: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-correlationandeffectivedegreesoffreedom

Onceyouhaveobtainedanintegraltimescale andcalculatedtheeffectivedegreesoffreedom ,youmayusethisparametertocalculateCIsforsamplemeans.

Theformulasgivenpreviouslydonotseemtobeappropriatewhenisneededtoassessestimatorsofauto-covariance/correlation

orcross-covariance/correlation.Inthesecases,VonStorchandZwiers(1999),reference[6],givestherespectivetwoformulas

assumingyouhaveaconstanttimestep foryourtimeseries.

T0Neff

Neff

T0

Δt

T0

Δt

=

=

1 + 2 (kΔt)∑k=1

+∞

ρ2xx

1 + 2 (kΔt) (kΔt)∑k=1

+∞

ρxx ρyy

Δt

Page 52: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

3.Aquicklookat"Aleisurelylookatthebootstrap,thejackknife,andcross-validation"byEfronandGong(1983)

Page 53: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrapandthejackknife

Sofar,wehaveusedtheoreticalorassumeddistributionsofourdatainordertoderivestandarderrorsandCIsofourparameterestimates.However,inmanycases,likeforthecorrelationcoefficient,itisimpossibletoexpressthevarianceinclosedform.Inaddition,weareoftenstuckwithonesamplefromoneexperimentinordertoinvestigatethe population.Ontopofthis,oursamplesmaynotbeindependentandwerunintotheissueofestimatingtheeffectivedegreesoffreedom.

( , ,… , )X1 X2 Xnx

Page 54: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrapandthejackknife

Sofar,wehaveusedtheoreticalorassumeddistributionsofourdatainordertoderivestandarderrorsandCIsofourparameterestimates.However,inmanycases,likeforthecorrelationcoefficient,itisimpossibletoexpressthevarianceinclosedform.Inaddition,weareoftenstuckwithonesamplefromoneexperimentinordertoinvestigatethe population.Ontopofthis,oursamplesmaynotbeindependentandwerunintotheissueofestimatingtheeffectivedegreesoffreedom.

Theideaofthebootstrapandjackknife,combinedwithMonteCarlomethods,istoresampleyouroriginalsamplewithreplacementsforthebootstrap,andwithdeletionsforthejackknife.Thesemethodsarerelativelyeasytoimplementwithourfastandmoderncomputers.

( , ,… , )X1 X2 Xnx

Page 55: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(1)

Let'sassumeyouareinvestigatingaunivariateormultivariater.v.forwhichyouwanttoestimateastatistic withestimator ,usingasample .

x

ϕ ϕ( , ,… , )X1 X2 Xn

Page 56: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(1)

Let'sassumeyouareinvestigatingaunivariateormultivariater.v.forwhichyouwanttoestimateastatistic withestimator ,usingasample .

First,youdrawrandomlyabootstrapsample ofthesamesizeasyouroriginalsample.Asanexample,ifyouroriginalsampleifofsize ,i.e. ,abootstrapsamplewithreplacementmaybe .

x

ϕ ϕ( , ,… , )X1 X2 Xn

( , ,… , )X∗1 X

∗2 X∗

N

N = 3 ( , , )X1 X2 X3( , , ) = ( , , )X∗

1 X∗2 X

∗3 X1 X2 X1

Page 57: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(1)

Let'sassumeyouareinvestigatingaunivariateormultivariater.v.forwhichyouwanttoestimateastatistic withestimator ,usingasample .

First,youdrawrandomlyabootstrapsample ofthesamesizeasyouroriginalsample.Asanexample,ifyouroriginalsampleifofsize ,i.e. ,abootstrapsamplewithreplacementmaybe .

Fromthebootstrapsample,youcalculateabootstrapreplicationestimateofyourstatistic .

x

ϕ ϕ( , ,… , )X1 X2 Xn

( , ,… , )X∗1 X

∗2 X∗

N

N = 3 ( , , )X1 X2 X3( , , ) = ( , , )X∗

1 X∗2 X

∗3 X1 X2 X1

ϕ∗

Page 58: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(1)

Let'sassumeyouareinvestigatingaunivariateormultivariater.v.forwhichyouwanttoestimateastatistic withestimator ,usingasample .

First,youdrawrandomlyabootstrapsample ofthesamesizeasyouroriginalsample.Asanexample,ifyouroriginalsampleifofsize ,i.e. ,abootstrapsamplewithreplacementmaybe .

Fromthebootstrapsample,youcalculateabootstrapreplicationestimateofyourstatistic .Yourepeatthisoperation timesto

obtain bootstrapreplications .

x

ϕ ϕ( , ,… , )X1 X2 Xn

( , ,… , )X∗1 X

∗2 X∗

N

N = 3 ( , , )X1 X2 X3( , , ) = ( , , )X∗

1 X∗2 X

∗3 X1 X2 X1

ϕ∗

B

B , ,… ,ϕ∗(1)

ϕ∗(2)

ϕ∗(B)

Page 59: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(1)

Let'sassumeyouareinvestigatingaunivariateormultivariater.v.forwhichyouwanttoestimateastatistic withestimator ,usingasample .

First,youdrawrandomlyabootstrapsample ofthesamesizeasyouroriginalsample.Asanexample,ifyouroriginalsampleifofsize ,i.e. ,abootstrapsamplewithreplacementmaybe .

Fromthebootstrapsample,youcalculateabootstrapreplicationestimateofyourstatistic .Yourepeatthisoperation timesto

obtain bootstrapreplications .

Youfinallycalculate(estimate)thevarianceofyourreplicationsas

x

ϕ ϕ( , ,… , )X1 X2 Xn

( , ,… , )X∗1 X

∗2 X∗

N

N = 3 ( , , )X1 X2 X3( , , ) = ( , , )X∗

1 X∗2 X

∗3 X1 X2 X1

ϕ∗

B

B , ,… ,ϕ∗(1)

ϕ∗(2)

ϕ∗(B)

Var[ ] = ( − where =ϕ∗ 1

B− 1∑b=1

B

ϕ∗(b)

ϕ∗(.)

)2 ϕ∗(.) ∑b ϕ

∗(b)

B

Page 60: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thebootstrap:principle(2)

Youcannowuse toderiveastandarderrorofyourestimate

as orusetheestimateddistributionofyourbootstrap

replications tocalculateCIs.

Example:BootstrapcorrelationsbetweenbetweenAgulhasjetandboundarytransportswith .

Var[ ]ϕ∗

Var[ ]ϕ∗− −−−−−√

, ,… ,ϕ∗(1)

ϕ∗(2)

ϕ∗(B)

B = 1000

Page 61: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thejackknife:principle(1)

Let'sassumeagainthatyouareinvestigatingaunivariateormultivariater.v. forwhichyouwanttoestimateastatistic withestimator ,usingasample .

x ϕ

ϕ ( , ,… , )X1 X2 Xn

Page 62: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thejackknife:principle(1)

Let'sassumeagainthatyouareinvestigatingaunivariateormultivariater.v. forwhichyouwanttoestimateastatistic withestimator ,usingasample .Ajackknifesampleisobtainedbydeleting datapointsfromyouroriginalsampleof

points.Thenumberofsuchsamplethatcanbeobtainedisthenumberofpermutationsof objectstaken atatimewhichis

.Ifyouhave datapointsthereare permutationsforthe"delete-1"jackknife.Thenumberofofpossiblejackknifesamplescanbecomeverylargesothatasubsetneedtobechoosen.

x ϕ

ϕ ( , ,… , )X1 X2 XnJ

NN J

N !/(N − J)! N N

Page 63: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thejackknife:principle(1)

Let'sassumeagainthatyouareinvestigatingaunivariateormultivariater.v. forwhichyouwanttoestimateastatistic withestimator ,usingasample .Ajackknifesampleisobtainedbydeleting datapointsfromyouroriginalsampleof

points.Thenumberofsuchsamplethatcanbeobtainedisthenumberofpermutationsof objectstaken atatimewhichis

.Ifyouhave datapointsthereare permutationsforthe"delete-1"jackknife.Thenumberofofpossiblejackknifesamplescanbecomeverylargesothatasubsetneedtobechoosen.

Theformulaforthe"delete-1"jackknifevarianceofyourstatisticestimateis

x ϕ

ϕ ( , ,… , )X1 X2 XnJ

NN J

N !/(N − J)! N N

Var[ ] = ( − where =ϕJ N − 1

N∑j=1

N

ϕ∗(j)

ϕ∗(.)

)2 ϕ∗(.) ∑j ϕ

∗(j)

N

Page 64: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thejackknife:principle(2)

Thejackknifemethodcanbealsousedtoestimatethebiasofyourestimatoras

sothatthejackknifeestimateofyourstatisticis

[ ] = (N − 1)( − )bJ ϕ ϕ∗(.)

ϕ

= N − (N − 1)ϕJ ϕ ϕ∗(.)

Page 65: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thejackknife:principle(2)

Thejackknifemethodcanbealsousedtoestimatethebiasofyourestimatoras

sothatthejackknifeestimateofyourstatisticis

Therearesomeimportantdetailstothebootstrapandthejackknifemethods.PleaseseeThompsonandEmery,TichelaarandRuff(1989)andEfronandGong(1983).

[ ] = (N − 1)( − )bJ ϕ ϕ∗(.)

ϕ

= N − (N − 1)ϕJ ϕ ϕ∗(.)

Page 66: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

4.Covarianceandcorrelationofbivariate

variables

Page 67: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Bivariaterandomvariable

Whatifyourprocessofinterest,oryourdata,isa"vectorvariable"?Itcouldbeanoceancurrent,anatmosphericwind,thepositionofadrifteretc.Suchvariablesarecalledbivariatevariablesinthestatisticslitterature,andarealsotreatedasr.vs.

Page 68: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Bivariaterandomvariable

Whatifyourprocessofinterest,oryourdata,isa"vectorvariable"?Itcouldbeanoceancurrent,anatmosphericwind,thepositionofadrifteretc.Suchvariablesarecalledbivariatevariablesinthestatisticslitterature,andarealsotreatedasr.vs.Herewewillusetheformalismoftimeseries,thatisweassumethatwehavesamplesindexedalonganaxis thatrepresentstime.t

Page 69: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Bivariaterandomvariable

Whatifyourprocessofinterest,oryourdata,isa"vectorvariable"?Itcouldbeanoceancurrent,anatmosphericwind,thepositionofadrifteretc.Suchvariablesarecalledbivariatevariablesinthestatisticslitterature,andarealsotreatedasr.vs.Herewewillusetheformalismoftimeseries,thatisweassumethatwehavesamplesindexedalonganaxis thatrepresentstime.

Let'sconsiderafirstbivariatevariable withCartesiancomponents and (east-westandnorth-south).

t

z(t)x(t) y(t)

Page 70: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Bivariaterandomvariable

Whatifyourprocessofinterest,oryourdata,isa"vectorvariable"?Itcouldbeanoceancurrent,anatmosphericwind,thepositionofadrifteretc.Suchvariablesarecalledbivariatevariablesinthestatisticslitterature,andarealsotreatedasr.vs.Herewewillusetheformalismoftimeseries,thatisweassumethatwehavesamplesindexedalonganaxis thatrepresentstime.

Let'sconsiderafirstbivariatevariable withCartesiancomponents and (east-westandnorth-south).

Wecanarrangethecomponentsintoa vectorfunctionoftime

oralternativelyuseacomplex-valuednotation

where and isthecomplexargument(orpolarangle)of intheinterval .

t

z(t)x(t) y(t)

1 × 2

z(t) = [ ] or = [ ]x(t) y(t) zn xn yn

z(t) = x(t) + iy(t) = |z(t)| ,ei arg (z)

i = −1−−−

√ arg (z)z [−π,+π]

Page 71: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

ThemeanofbivariateData

Thesamplemeanofthevectortimeseries isalsoavector,

thatconsistsofthesamplemeansofthe and componentsof .

z(t)

μz =

=

≡ = [ ]z1N

∑n=1

N

zn 1N

∑Nn=1 xn

1N

∑Nn=1 yn

[ ] = [ ]x y μx μy

x y z

Page 72: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

ThemeanofbivariateData

Thesamplemeanofthevectortimeseries isalsoavector,

thatconsistsofthesamplemeansofthe and componentsof .

Usingthecomplexnotation,thesamplemeanis

whichiscomplexnumber.

z(t)

μz =

=

≡ = [ ]z1N

∑n=1

N

zn 1N

∑Nn=1 xn

1N

∑Nn=1 yn

[ ] = [ ]x y μx μy

x y z

= + iz x y

Page 73: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thevarianceofbivariatevariable

Thevarianceofthevector-valuedtimesseries isnotascalaroravector,itisa matrix

where“ ”isthematrixtranspose, , .

Carryingoutthematrixmultiplicationleadsto

Thediagonalelementsof arethesamplevariances,whiletheoff-diagonalgivesthesamplecovariancebetween and .Notethatthetwooff-diagonalelementsareidentical, .

zn2 × 2

≡ ( − )Σz1

N − 1∑n=1

N

( − )zn z T zn z

T = [ ]zn xn yn = [ ]zTnxn

yn

= [ ] = [ ]Σz

1N − 1

∑n=1

N ( − )xn x2

( − ) ( − )yn y xn x

( − ) ( − )xn x yn y

( − )yn y2

s2x

syx

sxy

s2y

Σz

xn yn=syx sxy

Page 74: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thevarianceofbivariatevariable

Thevarianceofacomplexr.v., ,needsadefinition:

where meansthecomplexconjuguate,i.e. .

z = x+ iy

Var[z] = E[(z− (z− )]μz)∗ μz

(. )∗ = x− iyz∗

Page 75: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thevarianceofbivariatevariable

Thevarianceofacomplexr.v., ,needsadefinition:

where meansthecomplexconjuguate,i.e. .

Substitutingandexpandingthepreviousexpressiongives

Thevarianceofa"physicalvector"writtenasacomplexr.v.isasinglerealnumberwhichisthesumofthevarianceofitscomponents.Itisdifferentfromthe matrixofvariancesandcovariancesofitscomponentsseeninthepreviousslide.

z = x+ iy

Var[z] = E[(z− (z− )]μz)∗ μz

(. )∗ = x− iyz∗

Var[z] ==E[(x− ] + E[(y− ]μx)2 μy)2

Var[x] + Var[y]

2 × 2

Page 76: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thevarianceofbivariatevariable

Thevarianceofacomplexr.v., ,needsadefinition:

where meansthecomplexconjuguate,i.e. .

Substitutingandexpandingthepreviousexpressiongives

Thevarianceofa"physicalvector"writtenasacomplexr.v.isasinglerealnumberwhichisthesumofthevarianceofitscomponents.Itisdifferentfromthe matrixofvariancesandcovariancesofitscomponentsseeninthepreviousslide.Ifrepresentsanoceancurrent, isproportionaltotheaverageeddykineticenergy(density)

z = x+ iy

Var[z] = E[(z− (z− )]μz)∗ μz

(. )∗ = x− iyz∗

Var[z] ==E[(x− ] + E[(y− ]μx)2 μy)2

Var[x] + Var[y]

2 × 2z

Var[z]KE = (< > + < >)/2x′2 y ′2

Page 77: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Inadditionto ,let'sconsiderasecondbivariatevariablewithCartesiancomponents and .

z(t) w(t)g(t) h(t)

Page 78: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Inadditionto ,let'sconsiderasecondbivariatevariablewithCartesiancomponents and .Thecrosscovariancefunctionatzerolag,orsimplythecovariancebetweenthecomponentsof and canbeformedas

z(t) w(t)g(t) h(t)

z w

E{ w}zT =

=

E{[ ]}(x− )(g− )μx μg

(y− )(g− )μy μg

(x− )(h− )μx μh

(y− )(h− )μy μh

[ ]Cxg

Cyg

Cxh

Cyh

Page 79: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Inadditionto ,let'sconsiderasecondbivariatevariablewithCartesiancomponents and .Thecrosscovariancefunctionatzerolag,orsimplythecovariancebetweenthecomponentsof and canbeformedas

Themeaningofeachindividualentryofthismatrixisobviousbuttheinterpretationofallofthematoncemaybelessso.

z(t) w(t)g(t) h(t)

z w

E{ w}zT =

=

E{[ ]}(x− )(g− )μx μg

(y− )(g− )μy μg

(x− )(h− )μx μh

(y− )(h− )μy μh

[ ]Cxg

Cyg

Cxh

Cyh

Page 80: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Alternatively,let'susethecomplexrepresentationsof and

butassumeforsimplicitythat .

z w

z

w

==x+ iyg+ ih

= = 0μz μw

Page 81: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Alternatively,let'susethecomplexrepresentationsof and

butassumeforsimplicitythat .

Adefinitionofthecovariancebetweenthesetwocomplexr.v.is

z w

z

w

==x+ iyg+ ih

= = 0μz μw

Czw ===

E[ w]z∗

E[(x− iy)(g+ ih)]E[xg] + E[yh] + i(E[xh] + E[−yg]).

Page 82: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Alternatively,let'susethecomplexrepresentationsof and

butassumeforsimplicitythat .

Adefinitionofthecovariancebetweenthesetwocomplexr.v.is

Bewarethatthedefinitionofthecovariancebetweencomplexr.v.maydiffer.Sometimesitisdefinedas .OurconventionhereisthesameasMatlab.

z w

z

w

==x+ iyg+ ih

= = 0μz μw

Czw ===

E[ w]z∗

E[(x− iy)(g+ ih)]E[xg] + E[yh] + i(E[xh] + E[−yg]).

E[z ]w∗

Page 83: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Simplegeometryrevealsthattherealpartofthecomplexcovarianceistheexpectationofthedotproduct[orinnerproduct,noted ]whiletheimaginarypartistheexpectationofthemagnitudeofthevectorcrossproduct[orouterproduct,noted

]:

where istheinstantaneousgeometricangleintheCartesianplanebetween and ,measuredpositivelycounterclockwiserelativetothegeometricangleof .

(⋅)

(×)

Czw ===

E[xg] + E[yh] + i(E[xh] + E[−yg])E[z ⋅ w] + iE[||z × w||]E[|z||w| cos θ] + iE[|z||w| sin θ]

θz w

z

Page 84: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

= E[|z||w| cos θ] + iE[|z||w| sin θ]Czw

Page 85: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Thecovarianceof and isacomplexnumberwhichargument,orphase,is

= E[|z||w| cos θ] + iE[|z||w| sin θ]Czw

z w

Arg[ ] = atan{ } ≠ E[θ].CzwE[|z||w| sin θ]E[|z||w| cos θ]

Page 86: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Thecovarianceof and isacomplexnumberwhichargument,orphase,is

Theabsolutevalueof isclearlyameasureofthecovariancebetweenthetwobivariatevariables,butitsphaseisnot :itisnottheexpectation,ormean,ofthegeometricanglebetween and

.

= E[|z||w| cos θ] + iE[|z||w| sin θ]Czw

z w

Arg[ ] = atan{ } ≠ E[θ].CzwE[|z||w| sin θ]E[|z||w| cos θ]

CzwE[θ(t)]

zw

Page 87: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecovarianceofbivariatevariables

Thecovarianceof and isacomplexnumberwhichargument,orphase,is

Theabsolutevalueof isclearlyameasureofthecovariancebetweenthetwobivariatevariables,butitsphaseisnot :itisnottheexpectation,ormean,ofthegeometricanglebetween and

.

However, canstillbeseenasanindicationoftherelativeangleofcovariance.If thisindicatesthatthecovarianceoccurswith and alignedandpointinginthesamedirection,andif thisindicatesthatthecovarianceoccurswith atrightanglecounterclockwisefrom .

= E[|z||w| cos θ] + iE[|z||w| sin θ]Czw

z w

Arg[ ] = atan{ } ≠ E[θ].CzwE[|z||w| sin θ]E[|z||w| cos θ]

CzwE[θ(t)]

zw

Arg[ ]CzwArg[ ] = 0Czwz w

Arg[ ] = π/2Czww z

Page 88: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecorrelationofbivariatevariables

Fromthecomplexcovariance,wecandefinethecomplexcorrelationbetween and as

Since and arerealnumbers,thephaseof isthesamephaseasthephaseof :

z w

≡ = | |ρzwCzw

CzzCww− −−−−−√

ρzw eiArg[ ]ρzw

Czz Cww ρzwCzw Arg[ ] = Arg[ ]ρzw Czw

Page 89: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecorrelationofbivariatevariables

Fromthecomplexcovariance,wecandefinethecomplexcorrelationbetween and as

Since and arerealnumbers,thephaseof isthesamephaseasthephaseof :

Notethatthe"vector"regressionmodelfor basedonthecovariancebetween and is(seeLecture3)

whichshowsthattheregressedvector isrotatedcounterclockwiseby fromthedirectionof .Thisisvalidafterremovingthemeans.

z w

≡ = | |ρzwCzw

CzzCww− −−−−−√

ρzw eiArg[ ]ρzw

Czz Cww ρzwCzw Arg[ ] = Arg[ ]ρzw Czw

wz w

(t) = z(t) = z(t)wmCzwCzz

| |Czw

CzzeiArg[ ]Czw

(t)wmArg[ ]Czw z(t)

Page 90: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Panelcisthecorrelationbetweenthe10-mwindat170E,0Nand10-mwindsatallotherlocationsfromECMWFreanalyses.Therealpartof isshowninpanelaandtheimaginarypartisshowninpanelbasapureimaginarynumbersothatc=a+b.

Thecorrelationofbivariatevariables

ρ

ρ

Page 91: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecomplementaryofavector

Thecomplementaryofavector ,noted ,is,usingcomplexnotation

z zc

≡ = x− iyzc z∗

Page 92: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecomplementaryofavector

Thecomplementaryofavector ,noted ,is,usingcomplexnotation

Geometrically,itisthevector flippedwithrespecttotherealaxis.Ifabivariatetimeseriesrepresentsavectorrotatinginonedirection,thenitscomplementaryisrotatingintheoppositedirection.

z zc

≡ = x− iyzc z∗

z

Page 93: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Thecomplementarycorrelationofbivariatevariables

Thecomplementarycovariancebetween and is

Thecomplementaryorreflectionalcorrelationis

where

z w

C wz c ===

E[( w]z∗)∗

E[(x+ iy)(g+ ih)]E[xg] − E[yh] + i(E[xh] + E[yg]

≡ρ wzcC wzc

Cz cz cCww− −−−−−−√

=Cz cz c Czz

Page 94: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-covarianceandvarianceellipses

Thespecialcasesofstandardandcomplementaryautocovariancesofaphysicalvectorwithitselfcanberelatedtotheconceptofvarianceorstandarddeviationellipses.

Page 95: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-covarianceandvarianceellipses

Thespecialcasesofstandardandcomplementaryautocovariancesofaphysicalvectorwithitselfcanberelatedtotheconceptofvarianceorstandarddeviationellipses.

Forabivariater.v. ,thefixedangle betweentherealaxispositivedirectionandtheso-calledmajoraxisofthestandarddeviationellipseis

while definesthedirectionoftheso-calledminoraxis.

z θM

= Arg [ ] = arctan [ ] ,θM12

C zz c12

2E[xy]E[ ] − E[ ]x2 y2

+ π/2θM

Page 96: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-covarianceandvarianceellipses

Thevariances and ofthebivariatevariablealongthemajorandminoraxes,respectively,aregivenby

AnticipatingLecture5, and arethe2eigenvaluesofthecrosscovariancematrixoftheCartesiancomponent,whiletheassociatedeigenvectorsare and

.

a2v b2v

a2v =

=

[ + | |]12Czz C zz c

{E[ ] + E[ ] + } ,12

x2 y2 (E[ ] − E[ ] + 4(E[xy]x2 y2 )2 )2− −−−−−−−−−−−−−−−−−−−−−−√

b2v =

=

[ − | |]12Czz C zz c

{E[ ] + E[ ] − } .12

x2 y2 (E[ ] − E + 4(E[xy]x2 y2)2 )2− −−−−−−−−−−−−−−−−−−−−−√

a2v b2v 2 × 2

[cos , sin ]θM θM[− sin , cos ]θM θM

Page 97: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Auto-covarianceandvarianceellipses

Theratiooftheabsolutevalueofthecomplementaryautocorrelationtotheabsolutevalueoftheautocorrelationisameasureoftheabsolutelinearityofthestandarddeviationellipse

If theellipseisflatandif theellipseisacircle. isarelativeofthemorecommonlyknowneccentricityparameteroftheellipsewhichis

SeeLillyandGascard(2006)andLillyJ,OlhedeS.(2010).

|λ| = = .C zz c

| |Czz

−a2v b2v

+a2v b2v

|λ| = 1 |λ| = 0 λ

e = .1 −b2v

a2v

− −−−−−√

Page 98: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Standarddeviationorvarianceellipses

Ifyourcomplexsignalis whichrepresentsanellipse,thenthemajoraxisandminorsemi-axisofthestandarddeviationellipseare and

.

z(t) = [a cos(t) + i sin(t)]eiθ

= < aav /2a2− −−−

√= < bbv /2b2

− −−−√

Page 99: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Standarddeviationorvarianceellipses

Example:Meancurrents(blue)andstandarddeviationellipses(lightblue)ofnearbottomcurrentsfromtheRAPIDWAVEexperiment.Orangeaxesshowtopographygradient.SeeHughesetal.2013

Page 100: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Standarddeviationorvarianceellipses

Example:Complementaryautocorrelationof10-mwindsatalllocationsfromECMWFreanalyses.

Page 101: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Standarddeviationorvarianceellipses

Thestandardellipseisastatisticaldescriptionofthevarianceofabivariatevariableanddoesnotmeanthatanyunderlyingvariabilityisactuallyellipticalintime.StandarddeviationellipsescanbecomputedfromanumberofindividualpairsofCartesiancomponentsofabivariatequantitywithoutthesepointsactuallyformingconsecutivetimeseries.

Page 102: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Standarddeviationorvarianceellipses

Thestandardellipseisastatisticaldescriptionofthevarianceofabivariatevariableanddoesnotmeanthatanyunderlyingvariabilityisactuallyellipticalintime.StandarddeviationellipsescanbecomputedfromanumberofindividualpairsofCartesiancomponentsofabivariatequantitywithoutthesepointsactuallyformingconsecutivetimeseries.

Example:VarianceellipsesfromdriftersfromLumpkinandJohnson2013

Page 103: Lecture 2: Covariance and correlation · Lecture 2: Outline 1. Covariance & correlation 2. Lagged covariance & correlation 3. A quick look at "A leisurely look at the bootstrap, the

Practicalsession

Pleasedownloaddataatthefollowinglink:

PleasedownloadtheMatlabcodeatthefollowinglink:

MakesureyouhaveinstalledandtestedthefreejLabMatlabtoolboxfromJonathanLillyatwww.jmlilly.net/jmlsoft.html