# Time Series Analysis In R

Using Hidden Markov Models
For Unsupervised Learning

Agoston Torok
@torokagoston

data scientist @SynetiqLab

## Time series:

A series of datapoints in time order

## Methods of time series analysis:

• Season trend decomposition (e.g. STL)
• Autoregressive modeling (AR, ARMA, ARIMA)
• State space models (e.g. HMM)

### A (very) short intro to hidden Markov models

We hypothesize latent states/regimes in the time series (for example past flow and tree rings [1])

$\begin{array} & X_{1}\overset{P_T}{\longrightarrow} & X_{2}\overset{P_T}{\longrightarrow} & \dots \overset{P_T}{\longrightarrow} & X_N\\ \downarrow P_O & \downarrow P_O & & \downarrow P_O \\ O_1 & O_2 & \dots & O_N\end{array}$

• We cannot directly observe the $$X$$ time series, but we can infer it
• We have a series of $$O$$ observations resulting from $$X$$ latent states
• Based on the $$P_T$$ transition probability matrix, and $$P_O$$ probability matrix
• Passes between $$O$$, $$X$$, and $$Model$$

## Has been used to find patterns in:

• EEG (sleep cycles) [3, 4]
• Eye movements (face recognition) [5]
• Heart rate (cardiac events) [6]

### Can we use it to recognise emotional states?

• Results show that emotions have different physiological correlates [7]
• It is reasonable to say that the transition probabilities are not uniform
• Some emotions lasts longer (fear), others fade rather fast (surprise)

“Emotions are just as easy to access as any Higgs boson.”