36
Time series analysis of activity and temperature data of four healthy individuals B.Hadj-Amar N.Cunningham S.Ip March 11, 2016 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 1 / 26

Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Embed Size (px)

Citation preview

Page 1: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Time series analysis of activity and temperature data offour healthy individuals

B.Hadj-Amar N.Cunningham S.Ip

March 11, 2016

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 1 / 26

Page 2: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Aims

Fit time series models to activity data

Identify periodicity in the data

Produce a 24-hr ahead forecast for activity and temperature

Medical applications

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 2 / 26

Page 3: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Data

Healthy individuals wore devices recording physical activity and skintemperature

Four individuals recorded for approximately four days

Physical activity recorded minutely, skin temperature every tenminutes — hourly median taken

Missing data

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 3 / 26

Page 4: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Data

0

20

40

60

2013−10−04 2013−10−05 2013−10−06 2013−10−07

Res

t Act

ivity

33

34

35

36

37

2013−10−04 2013−10−05 2013−10−06 2013−10−07

Tem

pera

ture

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 4 / 26

Page 5: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Autocorrelation function

0 10 20 30 40 50 60 70

−0.

50.

00.

51.

0

Lag

AC

F

Activity

0 10 20 30 40 50 60 70

−0.

40.

00.

20.

40.

60.

81.

0Lag

Temperature

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 5 / 26

Page 6: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

ARMA

{Y1,Y2, ···,YT} is a time series with zero mean.εt is some noise with zero mean and variance σ2.

ARMA

ARMA(p, q) model has the form

Yt =

p∑i=1

φiYt−i + εt −q∑

j=1

θjεt−j (1)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 6 / 26

Page 7: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

ARMA

{Y1,Y2, ···,YT} is a time series with zero mean.εt is some noise with zero mean and variance σ2.

ARMA

ARMA(p, q) model has the form

Yt =

p∑i=1

φiYt−i + εt −q∑

j=1

θjεt−j (1)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 6 / 26

Page 8: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Backshift

Backshift Operator

B̂kYt = Yt−k (2)

B̂kεt = εt−k (3)

Yt =

p∑i=1

φi B̂iYt + εt −

q∑j=1

θj B̂jεt

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 7 / 26

Page 9: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Backshift

Backshift Operator

B̂kYt = Yt−k (2)

B̂kεt = εt−k (3)

Yt =

p∑i=1

φi B̂iYt + εt −

q∑j=1

θj B̂jεt

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 7 / 26

Page 10: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

ARMA Characteristic Equations

Yt =

p∑i=1

φi B̂iYt + εt −

q∑j=1

θj B̂jεt

φ(B̂)Yt = θ

(B̂)εt (4)

ARMA Characteristic Equations

φ(x) = 1−p∑

i=1

φixi (5)

θ(x) = 1−q∑

j=1

θjxj (6)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26

Page 11: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

ARMA Characteristic Equations

Yt =

p∑i=1

φi B̂iYt + εt −

q∑j=1

θj B̂jεt

φ(B̂)Yt = θ

(B̂)εt (4)

ARMA Characteristic Equations

φ(x) = 1−p∑

i=1

φixi (5)

θ(x) = 1−q∑

j=1

θjxj (6)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26

Page 12: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

ARMA Characteristic Equations

Yt =

p∑i=1

φi B̂iYt + εt −

q∑j=1

θj B̂jεt

φ(B̂)Yt = θ

(B̂)εt (4)

ARMA Characteristic Equations

φ(x) = 1−p∑

i=1

φixi (5)

θ(x) = 1−q∑

j=1

θjxj (6)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26

Page 13: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

SARMA Characteristic Equations

Introduce seasonality of lag s.

SARMA Characteristic Equations

Φ(x) = 1−P∑i=1

Φixis (7)

Θ(x) = 1−Q∑j=1

Θjxjs (8)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 9 / 26

Page 14: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

SARMA Characteristic Equations

Introduce seasonality of lag s.

SARMA Characteristic Equations

Φ(x) = 1−P∑i=1

Φixis (7)

Θ(x) = 1−Q∑j=1

Θjxjs (8)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 9 / 26

Page 15: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

SARMA

SARMA

SARMA(p, q)× (P,Q)s model has the form

φ(B̂)

Φ(B̂)Yt = θ

(B̂)

Θ(B̂)εt (9)

Assume Normal noise, parameters can be estimated using maximum loglikelihood.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 10 / 26

Page 16: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

SARMA

SARMA

SARMA(p, q)× (P,Q)s model has the form

φ(B̂)

Φ(B̂)Yt = θ

(B̂)

Θ(B̂)εt (9)

Assume Normal noise, parameters can be estimated using maximum loglikelihood.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 10 / 26

Page 17: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Information Criterions

AIC and BIC can be used to select what p, q,P,Q, s to use.

AIC and BIC

Select p, q,P,Q, s which minimizes one of these

AIC = T ln σ̂2 + (p + q + P + Q)2 (10)

BIC = T ln σ̂2 + (p + q + P + Q) lnT (11)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 11 / 26

Page 18: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Information Criterions

AIC and BIC can be used to select what p, q,P,Q, s to use.

AIC and BIC

Select p, q,P,Q, s which minimizes one of these

AIC = T ln σ̂2 + (p + q + P + Q)2 (10)

BIC = T ln σ̂2 + (p + q + P + Q) lnT (11)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 11 / 26

Page 19: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Experiment

3 day fit, 1 day forecast

Select s = 24 hours.

Fit ARMA(p, q) and select the best p, q pair.

Fix p, q, fit SARMA(p, q)× (P,Q)24 and select the best P,Q pair.

Fit and then assess 24 hour forecast

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 12 / 26

Page 20: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Results

Figure: Fit SARMA on activity time series

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 13 / 26

Page 21: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Results

Figure: Fit SARMA on temperature time series

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 14 / 26

Page 22: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Results

AICData p q P Q MSE (◦C2)

Temp2 2 4 2 0 1.71± 0.09Temp8 2 1 2 0 1.4± 0.1

Temp24 4 4 1 1 0.43± 0.04Temp26 5 2 2 0 0.7± 0.1

BICData p q P Q MSE (◦C2)

Temp2 0 2 2 0 1.72± 0.08Temp8 2 1 2 0 1.4± 0.1

Temp24 2 4 1 1 0.36± 0.03Temp26 2 0 2 0 0.69± 0.06

Table: Selected SARMA models for temperature with mean squared error

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 15 / 26

Page 23: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression

Let us consider the periodic model:

Xt = Acos(2πωt + φ) + Zt ,

where A amplitude, φ phase shift, ω fixed frequency, Zt ∼WN(0, σ2)

Using, trigonometric identities we re-write:

Xt = β1cos(2πωt) + β2sin(2πωt) + Zt

where β1 = Acos(φ) and β2 = −Asin(φ).

Linear in β1 and β2 ⇒ Linear regression

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 16 / 26

Page 24: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression

Let us consider the periodic model:

Xt = Acos(2πωt + φ) + Zt ,

where A amplitude, φ phase shift, ω fixed frequency, Zt ∼WN(0, σ2)

Using, trigonometric identities we re-write:

Xt = β1cos(2πωt) + β2sin(2πωt) + Zt

where β1 = Acos(φ) and β2 = −Asin(φ).

Linear in β1 and β2 ⇒ Linear regression

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 16 / 26

Page 25: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression

Let us consider the periodic model:

Xt = Acos(2πωt + φ) + Zt ,

where A amplitude, φ phase shift, ω fixed frequency, Zt ∼WN(0, σ2)

Using, trigonometric identities we re-write:

Xt = β1cos(2πωt) + β2sin(2πωt) + Zt

where β1 = Acos(φ) and β2 = −Asin(φ).

Linear in β1 and β2 ⇒ Linear regression

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 16 / 26

Page 26: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression

Spectral Representation Theorem states that any (weakly) stationary timeseries can be approximated:

Xt = µ+K∑

k=1

{βk1cos(2πωkt) + βk2sin(2πωkt)

}

Issue: Find this collection of frequencies {ωk}Kk=1 that drive the data

Therefore, we use the periodogram I (ωj), estimator of thefrequency spectrum f (ωj)

E[I (ωj)] = f (ωj)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 17 / 26

Page 27: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression

Spectral Representation Theorem states that any (weakly) stationary timeseries can be approximated:

Xt = µ+K∑

k=1

{βk1cos(2πωkt) + βk2sin(2πωkt)

}

Issue: Find this collection of frequencies {ωk}Kk=1 that drive the data

Therefore, we use the periodogram I (ωj), estimator of thefrequency spectrum f (ωj)

E[I (ωj)] = f (ωj)

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 17 / 26

Page 28: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Periodogram

However, the periodogram is not a consistent estimator.

Generating periodogram of AR(1), for different values of T :

Figure: Showing not consistency of the periodogram: black line is theperiodogram, red line is the true spectrum.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 18 / 26

Page 29: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Smoothed Periodogram

The smoothed periodogram is instead a consistent estimator of thefrequency spectrum:

f̂ (ωj) =1

2M + 1

M∑k=−M

hk I (ωj +k

T)

Figure: Showing not consistency of the periodogram: black line is theperiodogram, red line is the true spectrum.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 19 / 26

Page 30: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Temperature: Finding the frequencies that drive the data

Figure: Periodogram and smoothed periodograms (uniform and Daniell weights)for temperature of patient 8. This figure is best viewed in colours.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 20 / 26

Page 31: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Periodogram and Spectrum: AR(p) approach

The spectrum of any (weakly) stationary time series can be approximatedby the spectrum of an AR(p) process.

(a) AIC and BIC (b) Spectrum AR(2), AR(9)

Figure: AR(p) approach to obtain the correct frequency representation. Mainfrequencies that drive the data are around 1/24, and 1/8

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 21 / 26

Page 32: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression: Temperature

Figure: Harmonic regression for temperature of patient 8, using 5 differentharmonics. Dotted lines represent the fitting for single harmonics; thick red line isthe superposition of the dotted harmonics, which is the final fit

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 22 / 26

Page 33: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Forecasting: Temperature

Figure: 24 hour forecast for temperature of patient 8, given by averaging thefitted model of 4 days.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 23 / 26

Page 34: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Harmonic Regression: Rest Activity

Figure: Harmonic regression for rest activity of patient 8, using 5 harmonics. Ontop it is shown the classic harmonic fitting, whereas on the bottom the alternativemodel, where negative values are taken to be zero.

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 24 / 26

Page 35: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

Conclusions and future work

Harmonic regression provided a better fit for the data

In both cases skin temperature was more accurately modeled

Further work

Examine larger datasetsConsider weekday vs weekend effectsModel dependence structure between skin temperature and activitylevels

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 25 / 26

Page 36: Time series analysis of activity and temperature data of ...sip/work/presentation_timeSeries.pdf · Time series analysis of activity and temperature data of four healthy individuals

References

Mark Fiecas - Spectral Analysis of Time Series Data

University of Warwick - ST414

2015

Jenkins, GM and Reinsel, GC - Time series analysis: forecasting and control

Holden-Day, San Francisco

1976

Shumway, Robert H and Stoffer, David S - Time series analysis and its applications

Springer Science & Business Media

2013

B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 26 / 26