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
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
Data Healthy individuals wore devices recording physical activity and skin temperature Four individuals recorded for approximately four days Physical activity recorded minutely, skin temperature every ten minutes hourly median taken Missing data B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 3 / 26
Data 60 Rest Activity 40 20 0 2013 10 04 2013 10 05 2013 10 06 2013 10 07 37 Temperature 36 35 34 33 2013 10 04 2013 10 05 2013 10 06 2013 10 07 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 4 / 26
Autocorrelation function Activity Temperature ACF 0.5 0.0 0.5 1.0 0.4 0.0 0.2 0.4 0.6 0.8 1.0 0 10 20 30 40 50 60 70 Lag 0 10 20 30 40 50 60 70 Lag B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 5 / 26
ARMA {Y 1, Y 2,, Y T } is a time series with zero mean. ɛ t is some noise with zero mean and variance σ 2. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 6 / 26
ARMA {Y 1, Y 2,, Y T } 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 Y t = p q φ i Y t i + ɛ t θ j ɛ t j (1) i=1 j=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 6 / 26
Backshift Backshift Operator B k Y t = Y t k (2) B k ɛ t = ɛ t k (3) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 7 / 26
Backshift Backshift Operator B k Y t = Y t k (2) B k ɛ t = ɛ t k (3) Y t = p q φ Bi i Y t + ɛ t θ Bj j ɛ t i=1 j=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 7 / 26
ARMA Characteristic Equations Y t = p q φ Bi i Y t + ɛ t θ Bj j ɛ t i=1 j=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26
ARMA Characteristic Equations Y t = p φ Bi i Y t + ɛ t i=1 φ ( B q θ Bj j ɛ t j=1 ) ( ) Y t = θ B ɛ t (4) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26
ARMA Characteristic Equations Y t = p φ Bi i Y t + ɛ t i=1 φ ( B q θ Bj j ɛ t j=1 ) ( ) Y t = θ B ɛ t (4) ARMA Characteristic Equations φ(x) = 1 θ(x) = 1 p φ i x i (5) i=1 q θ j x j (6) j=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 8 / 26
SARMA Characteristic Equations Introduce seasonality of lag s. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 9 / 26
SARMA Characteristic Equations Introduce seasonality of lag s. SARMA Characteristic Equations Φ(x) = 1 Θ(x) = 1 P Φ i x is (7) i=1 Q Θ j x js (8) j=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 9 / 26
SARMA SARMA SARMA(p, q) (P, Q) s model has the form ( ) ( ) ( φ B Φ B Y t = θ B ) Θ ( B ) ɛ t (9) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 10 / 26
SARMA SARMA SARMA(p, q) (P, Q) s model has the form ( ) ( ) ( φ B Φ B Y t = θ B ) Θ ( B ) ɛ t (9) Assume Normal noise, parameters can be estimated using maximum log likelihood. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 10 / 26
Information Criterions AIC and BIC can be used to select what p, q, P, Q, s to use. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 11 / 26
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) ln T (11) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 11 / 26
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
Results Figure: Fit SARMA on activity time series B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 13 / 26
Results Figure: Fit SARMA on temperature time series B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 14 / 26
Results AIC Data p q P Q MSE ( C 2 ) Temp2 2 4 2 0 1.71 ± 0.09 Temp8 2 1 2 0 1.4 ± 0.1 Temp24 4 4 1 1 0.43 ± 0.04 Temp26 5 2 2 0 0.7 ± 0.1 BIC Data p q P Q MSE ( C 2 ) Temp2 0 2 2 0 1.72 ± 0.08 Temp8 2 1 2 0 1.4 ± 0.1 Temp24 2 4 1 1 0.36 ± 0.03 Temp26 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
Harmonic Regression Let us consider the periodic model: X t = Acos(2πωt + φ) + Z t, where A amplitude, φ phase shift, ω fixed frequency, Z t WN(0, σ 2 ) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 16 / 26
Harmonic Regression Let us consider the periodic model: X t = Acos(2πωt + φ) + Z t, where A amplitude, φ phase shift, ω fixed frequency, Z t WN(0, σ 2 ) Using, trigonometric identities we re-write: X t = β 1 cos(2πωt) + β 2 sin(2πωt) + Z t where β 1 = Acos(φ) and β 2 = Asin(φ). B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 16 / 26
Harmonic Regression Let us consider the periodic model: X t = Acos(2πωt + φ) + Z t, where A amplitude, φ phase shift, ω fixed frequency, Z t WN(0, σ 2 ) Using, trigonometric identities we re-write: X t = β 1 cos(2πωt) + β 2 sin(2πωt) + Z t 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
Harmonic Regression Spectral Representation Theorem states that any (weakly) stationary time series can be approximated: X t = µ + K { βk1 cos(2πω k t) + β k2 sin(2πω k t) } k=1 B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 17 / 26
Harmonic Regression Spectral Representation Theorem states that any (weakly) stationary time series can be approximated: X t = µ + K { βk1 cos(2πω k t) + β k2 sin(2πω k t) } k=1 Issue: Find this collection of frequencies {ω k } K k=1 that drive the data Therefore, we use the periodogram I (ω j ), estimator of the frequency spectrum f (ω j ) E[I (ω j )] = f (ω j ) B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 17 / 26
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 the periodogram, red line is the true spectrum. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 18 / 26
Smoothed Periodogram The smoothed periodogram is instead a consistent estimator of the frequency spectrum: 1 M ˆf (ω j ) = h k I (ω j + k 2M + 1 T ) k= M B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 19 / 26
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
Periodogram and Spectrum: AR(p) approach The spectrum of any (weakly) stationary time series can be approximated by 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. Main frequencies 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
Harmonic Regression: Temperature Figure: Harmonic regression for temperature of patient 8, using 5 different harmonics. Dotted lines represent the fitting for single harmonics; thick red line is the 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
Forecasting: Temperature Figure: 24 hour forecast for temperature of patient 8, given by averaging the fitted model of 4 days. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 23 / 26
Harmonic Regression: Rest Activity Figure: Harmonic regression for rest activity of patient 8, using 5 harmonics. On top it is shown the classic harmonic fitting, whereas on the bottom the alternative model, where negative values are taken to be zero. B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 24 / 26
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 datasets Consider weekday vs weekend effects Model dependence structure between skin temperature and activity levels B.Hadj-Amar, N.Cunningham, S.Ip Time Series Analysis March 11, 2016 25 / 26
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