% Template for PLoS
% Version 3.1 February 2015
%
% To compile to pdf, run:
% latex plos.template
% bibtex plos.template
% latex plos.template
% latex plos.template
% dvipdf plos.template
%
% % % % % % % % % % % % % % % % % % % % % %
%
% -- IMPORTANT NOTE
%
% This template contains comments intended 
% to minimize problems and delays during our production 
% process. Please follow the template instructions
% whenever possible.
%
% % % % % % % % % % % % % % % % % % % % % % % 
%
% Once your paper is accepted for publication, 
% PLEASE REMOVE ALL TRACKED CHANGES in this file and leave only
% the final text of your manuscript.
%
% There are no restrictions on package use within the LaTeX files except that 
% no packages listed in the template may be deleted.
%
% Please do not include colors or graphics in the text.
%
% Please do not create a heading level below \subsection. For 3rd level headings, use \paragraph{}.
%
% % % % % % % % % % % % % % % % % % % % % % %
%
% -- FIGURES AND TABLES
%
% Please include tables/figure captions directly after the paragraph where they are first cited in the text.
%
% DO NOT INCLUDE GRAPHICS IN YOUR MANUSCRIPT
% - Figures should be uploaded separately from your manuscript file. 
% - Figures generated using LaTeX should be extracted and removed from the PDF before submission. 
% - Figures containing multiple panels/subfigures must be combined into one image file before submission.
% For figure citations, please use "Fig." instead of "Figure".
% See http://www.plosone.org/static/figureGuidelines for PLOS figure guidelines.
%
% Tables should be cell-based and may not contain:
% - tabs/spacing/line breaks within cells to alter layout or alignment
% - vertically-merged cells (no tabular environments within tabular environments, do not use \multirow)
% - colors, shading, or graphic objects
% See http://www.plosone.org/static/figureGuidelines#tables for table guidelines.
%
% For tables that exceed the width of the text column, use the adjustwidth environment as illustrated in the example table in text below.
%
% % % % % % % % % % % % % % % % % % % % % % % %
%
% -- EQUATIONS, MATH SYMBOLS, SUBSCRIPTS, AND SUPERSCRIPTS
%
% IMPORTANT
% Below are a few tips to help format your equations and other special characters according to our specifications. For more tips to help reduce the possibility of formatting errors during conversion, please see our LaTeX guidelines at http://www.plosone.org/static/latexGuidelines
%
% Please be sure to include all portions of an equation in the math environment.
%
% Do not include text that is not math in the math environment. For example, CO2 will be CO\textsubscript{2}.
%
% Please add line breaks to long display equations when possible in order to fit size of the column. 
%
% For inline equations, please do not include punctuation (commas, etc) within the math environment unless this is part of the equation.
%
% % % % % % % % % % % % % % % % % % % % % % % % 
%
% Please contact latex@plos.org with any questions.
%
% % % % % % % % % % % % % % % % % % % % % % % %

\documentclass[10pt,letterpaper]{article}
\usepackage[top=0.85in,left=2.75in,footskip=0.75in]{geometry}

% Use adjustwidth environment to exceed column width (see example table in text)
\usepackage{changepage}

% Use Unicode characters when possible
\usepackage[utf8]{inputenc}

% textcomp package and marvosym package for additional characters
\usepackage{textcomp,marvosym}

% fixltx2e package for \textsubscript
\usepackage{fixltx2e}

% amsmath and amssymb packages, useful for mathematical formulas and symbols
\usepackage{amsmath,amssymb}

% cite package, to clean up citations in the main text. Do not remove.
\usepackage{cite}

% Use nameref to cite supporting information files (see Supporting Information section for more info)
\usepackage{nameref,hyperref}

% line numbers
\usepackage[right]{lineno}

% ligatures disabled
\usepackage{microtype}
%\DisableLigatures[f]{encoding = *, family = * }

% rotating package for sideways tables
\usepackage{rotating}

\usepackage{tikz}
\usepackage{subfig}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{calc}
\usepackage{siunitx}
%\usepackage{graphics}


% Remove comment for double spacing
%\usepackage{setspace} 
%\doublespacing

% Text layout
\raggedright
\setlength{\parindent}{0.5cm}
\textwidth 5.25in 
\textheight 8.75in

% Bold the 'Figure #' in the caption and separate it from the title/caption with a period
% Captions will be left justified
\usepackage[aboveskip=1pt,labelfont=bf,labelsep=period,justification=raggedright,singlelinecheck=off]{caption}

% Use the PLoS provided BiBTeX style
\bibliographystyle{plos2015}

% Remove brackets from numbering in List of References
\makeatletter
\renewcommand{\@biblabel}[1]{\quad#1.}
\makeatother

% Leave date blank
\date{}

% Header and Footer with logo
\usepackage{lastpage,fancyhdr,graphicx}
\usepackage{epstopdf}
\pagestyle{myheadings}
\pagestyle{fancy}
\fancyhf{}
\lhead{\includegraphics[width=2.0in]{PLOS-submission.eps}}
\rfoot{\thepage/\pageref{LastPage}}
\renewcommand{\footrule}{\hrule height 2pt \vspace{2mm}}
\fancyheadoffset[L]{2.25in}
\fancyfootoffset[L]{2.25in}
\lfoot{\sf PLOS}

%% Include all macros below

\newcommand{\lorem}{{\bf LOREM}}
\newcommand{\ipsum}{{\bf IPSUM}}

% Generelt
\newcommand{\ud}{\mathrm{d}} % d
\newcommand{\R}{\mathbb{R}} % Real numbers
\newcommand{\T}{\mathscr{T}}

% Operatorer og funktionaler
\newcommand{\I}{\mathbb{I}} % I

\newcommand{\CE}[2]{\mathrm{E}\left[\,#1\,|\,#2\,\right]} % Conditional expectation

\newcommand{\by}{\boldsymbol{y}}
\newcommand{\bc}{\boldsymbol{c}}
\newcommand{\bd}{\boldsymbol{d}}
\newcommand{\bP}{\boldsymbol{\Phi}}
\newcommand{\bZ}{Z}%{\boldsymbol{Z}}
\newcommand{\bV}{V}%{\boldsymbol{V}}
\newcommand{\br}{\boldsymbol{r}}
\newcommand{\bt}{\boldsymbol{t}}
\newcommand{\btheta}{\boldsymbol{\vartheta}}
\newcommand{\bht}{\hat{\boldsymbol{\vartheta}}}
\newcommand{\bz}{\boldsymbol{z}}
\newcommand{\bx}{{\boldsymbol{x}}}
\newcommand{\bv}{v}
\newcommand{\bw}{\boldsymbol{w}}
\newcommand{\vv}{\boldsymbol{v}}
\newcommand{\bepsilon}{\boldsymbol{\varepsilon}}

%% END MACROS SECTION

\setcounter{secnumdepth}{3}
\begin{document}
\vspace*{0.35in}

% Title must be 250 characters or less.
% Please capitalize all terms in the title except conjunctions, prepositions, and articles.
\begin{flushleft}
{\Large
%\textbf\newline{A timing and movement separation model for statistical analysis of human movement}
\textbf\newline{Separating timing, movement conditions and individual differences in the analysis of human movement}
}
\newline
% Insert author names, affiliations and corresponding author email (do not include titles, positions, or degrees).
\\
Lars Lau Raket\textsuperscript{1,*},
Britta Grimme\textsuperscript{2},
Gregor Sch\"oner\textsuperscript{2},
Christian Igel\textsuperscript{3},
Bo Markussen\textsuperscript{1}
\\
\bigskip
\bf{1} Department of Mathematical Sciences, University of Copenhagen, Copenhagen, Denmark
\\
\bf{2} Institut f\"ur Neuroinformatik, Ruhr-Universit\"at Bochum, Bochum, Germany
\\
\bf{3} Department of Computer Science, University of Copenhagen, Copenhagen, Denmark
\\
\bigskip

% Insert additional author notes using the symbols described below. Insert symbol callouts after author names as necessary.
% 
% Remove or comment out the author notes below if they aren't used.
%
% Primary Equal Contribution Note
%\Yinyang These authors contributed equally to this work.

% Additional Equal Contribution Note
% Also use this double-dagger symbol for special authorship notes, such as senior authorship.
%\ddag These authors also contributed equally to this work.

% Current address notes
%\textcurrency Universitetsparken 5, 2100 Copenhagen, Denmark
% \textcurrency b Insert current address of second author with an address update
% \textcurrency c Insert current address of third author with an address update

% Deceased author note
%\dag Deceased

% Group/Consortium Author Note
%\textpilcrow Membership list can be found in the Acknowledgments section.

% Use the asterisk to denote corresponding authorship and provide email address in note below.
* larslau@math.ku.dk

\end{flushleft}
% Please keep the abstract below 300 words

\section*{Supporting Information}
{
\subsection*{A primer on model building for movement data}
%\begin{figure}[!th]
%\centering
%\includegraphics[width = 0.47\textwidth]{img/signa1.pdf}
%\caption{Twelve acceleration functions corresponding to repetitions of a signature being written.}\label{fig:signa1}
%\end{figure}

The two major types of variation in movement data are path variation (amplitude) and movement timing variation (time warping). From a statistical modeling perspective, it is natural to model these effects as realizations of random processes across repetitions of the task at hand, since this allows a data driven regularization of the predictions of these effects. We consider the class of models on the form
\begin{align}
y_i(t_k) = \theta(v(t_k, \bw_i)) + x_i(t_k) + \varepsilon_{ik}\label{eq:mod_primer}
\end{align}
where $\theta$ is the mean profile, $v$ is a warping function that depends on the random warping parameters $\bw_i\in\R^{n_w}$ that are assumed to be independent across $i$ and multivariate zero-mean Gaussian with covariance matrix $\sigma^2 C$, the $x_i$ terms are independent zero-mean Gaussian process with covariance function $\sigma^2 \mathcal{S}$, and the $\varepsilon_{ik}$-terms are independent zero-mean Gaussian noise with variance $\sigma^2$.

To use model~\eqref{eq:mod_primer} we need to choose the type of mean function $\theta$, the type of warping function $v$ as well as the covariance structures for $\bw_i$ and $x_i$. Below is a list of considerations of how to do these model choices based on the experiment at hand.
\begin{description}
\item[$\theta$:] A good allround choice is to model $\theta$ as a B-spline using a functional basis. For periodic movement sequences, a Fourier basis may sometimes be preferred. To choose the number of basis functions to use we need to consider the data at hand. For experiments with dense sampling and a clear systematic pattern in the trajectories the number of basis functions should be just be sufficiently high to model the mean pattern. If on the other hand the trajectories are sparsely observed in time or the common pattern is very unclear, one should choose a small number of basis functions to avoid local overfitting.
\item[$v$:] The behavior of the warping function should be driven by the random variables $\bw_i$. We will consider warping functions where $\bw_i$ models disparities from the identity mapping (corresponding to no warp), and $v$ is an interpolating function of these random disparities at a set of specified anchor points $\bt^{w}\in \R^{n_w}$. If one needs to predict derivatives such as velocity or acceleration of the observed profiles the interpolation should be smooth (e.g. a cubic spline). If no derivatives are needed, one should prefer simpler models such as linear interpolation as this reduces the nonlinear contribution of the derivative term in the linearization term $Z$ and thus reduces the complexity the estimation problem, see model~\eqref{model:linear}.
\item[$C$:] The covariance matrix of the random disparities $\bw_i$ should be chosen to respect the experimental setup. If movements are modeled in percentual time, and the beginning and end of the observed trajectories correspond to the same states across movement (e.g. beginning and end of movement), the model for $\bw_i$ should respect that. The simplest such model is to assume that $\bw_i$ is a Brownian bridge observed at the discrete anchor points $\bt^w$. For other types of data one may wish to include a random Gaussian time shift (add constant matrix to the covariance of the non-shift part of the model) or have an open end point which could be modeled using a Brownian motion model. If $n_w$ is low relative to the number of repetitions one may model $C$ as a completely free covariance matrix.
\item[$\mathcal{S}$:] A good allround choice for the covariance function of the amplitude variance is the Mat\'ern covariance function. The Mat\'ern covariance has three parameters, scale, range and smoothness. The scale parameter determines the variance of the process, the range parameter determines the strength of the correlation over time and the smoothness parameter determines the smoothness of the corresponding process. If one wants to simplify the optimization problem, one may fix the smoothness parameter at some value that represents sufficient smoothness, for example 2 corresponding to twice differentiable sample paths of the amplitude effect.  For experiments with fixed start and end values one may use a bridge process such as the Brownian bridge, however, it is often preferable to use a less specific model than an overly specific model. For additive effects such as $x_i$, even slight misspecification of a bridge covariance structure at the beginning and end of movement (where variance and covariance go from zero to non-zero) may result in considerable bias of the corresponding parameters. 
\end{description} 
Consider the handwriting signature data in percentual time in Figure~S1.%\ref{fig:signa1}
 The data consist of 12 acceleration magnitude profiles, each with 98 observations, corresponding to repetitions of a signature being written by a participant. This data has previously been used as an example in \cite{Srivastava}.  A reproducible pattern across repetitions is in the nature of the task, and we also see a strong consistent pattern across the samples, but the curves are both misaligned and vary systematically in amplitude. Using the considerations above, we choose a B-spline basis with 40 interior knots to have sufficient flexibility to model the mean, we choose $v$ to be a piecewise linear interpolation of the disparities $\bw_i$ that we model as discretely observed Brownian bridges over $n_w=20$ equidistant anchor points. For the amplitude covariance $\mathcal{S}$ we choose a Mat\'ern covariance with unknown scale, range and smoothness. 

The alignment of the proposed model is displayed in Figure~S2.%\ref{fig:signa2} 
 We see a neat alignment of the samples and a mean function that represents the mean pattern well, with no indications of local overfitting. Similarly for the warping functions, we only see small systematic deviations from the identity warp, despite of the high number of anchor points. The maximum likelihood estimates for the variance parameters were as follows: the warp scale estimate was 14.1, the variance scale estimate for the amplitude effect was 54.4, the range parameter estimate was $8.2\cdot 10^{-3}$, the smoothness parameter was 6.2, and the noise variance $\sigma^2$ was estimated to be $1.4\cdot 10^{-4}$. This suggests that the systematic part of the amplitude variation explains more than 99.9\% of the amplitude variation, which fits well with the smooth functional samples. 


To find the best among multiple models, one can compare different models using cross-vaildation, as was done in this paper, if such a setup is meaningful for the application at hand. In general one can do model selection based on the corrected conditional AIC of the linearized likelihoods \cite{greven2010behaviour}. 

%
%\begin{figure}[!ht]
%\centering
%%\subfloat[Aligned samples and mean (dashed)]{\includegraphics[width = 0.47\textwidth]{img/signa2.pdf}}
%%\subfloat[Warping functions compared to the identity (dashed)]{\includegraphics[width = 0.47\textwidth]{img/signa3.pdf}}
%\caption{The aligned acceleration functions from Figure~\ref{fig:signa1} (a), along with the predicted warping functions (b). }\label{fig:signa2}
%\end{figure}
%

\subsubsection*{R code for fitting the model to the signature data}
Suppose that \texttt{y} is a list containing the 12 acceleration trajectories and \texttt{t} is a list of the corresponding observation times. The model described above can be specified and fitted using the code given below. The methods in the \texttt{pavpop} R package are thoroughly documented with a wide array of examples in the package help pages and vignettes.
\begin{verbatim}
# Install and load pavpop R package
if (packageVersion("devtools") < 1.6) {
  install.packages("devtools")
}
devtools::install_github('larslau/pavpop')
library(pavpop)

# Set up basis function
kts <- seq(0, 1, length = 42)[2:41]
basis_fct <- make_basis_fct(kts = kts, intercept = TRUE, 
                            control = list(boundary = c(0, 1)))

# Set up warp function
tw <- seq(0, 1, length = 20)
warp_fct <- make_warp_fct('piecewise-linear', tw)

# Set up covariance functions and roughly initialize parameters
warp_cov_par <- c(tau = 10)
warp_cov <- make_cov_fct(Brownian, noise = FALSE, param = warp_cov_par, 
                         type = 'bridge')

amp_cov_par <- c(scale = 4, range = 1, smoothness = 2)
amp_cov <- make_cov_fct(Matern, noise = TRUE, param = amp_cov_par)

#
# Estimate in the model
#

# Rough bounds on parameters
lower <- c(1e-3, 1e-3, 1e-3, 1e-3)
upper <- c(1000, 10, 10, 10)

res <- pavpop(y, t, basis_fct, warp_fct, amp_cov, warp_cov, 
              iter = c(5, 20), homeomorphism = 'soft', 
              like_optim_control = list(lower = lower, upper = upper))
\end{verbatim}

\subsection*{Simulation study}
To evaluate the proposed algorithm for maximum likelihood estimation, we simulated data from the proposed model under the maximum likelihood estimates on the full data using a sampling setup identical to the central experiment ($d = 30.0$ cm, medium obstacle). We simulated 1000 outcomes and ran the estimation procedure as described in the section on modeling of effects and the algorithmic approach. The total runtime of the 1000 estimation procedures was approximately 6 hours on a 64-core machine. 

The densities of the integrated square estimation errors ($L^2$ error) for the estimated mean profiles (experiment and participant) are shown in the right panel of Figure~S3.%\ref{fig:fixed_simul}. 
For comparison, the experiment-specific and participant mean profiles have been estimated using ordinary least squares (OLS) estimation with the correctly specified spline model for the mean. The corresponding densities are shown in the left panel. We note that the densities are shown on squareroot scale to enable visual inspection of the differences. We see that the estimate for the experiment-specific mean profile is marginally more stable for the OLS estimation, but results are close-to perfect for both methods. For the participant-specific effects, however, we see that the proposed model that aligns samples within participant using a random warping function gives $L^2$ errors that are approximately an order of magnitude lower than simple OLS estimation. 

%\begin{figure}[!ht]
%\centering
%%\input{img/fixed.tex}
%\caption{Densities of the integrated square estimation errors ($L^2$ errors) for the common and participant-specific mean functions in the simulation study. The left panel shows results for ordinary least square (OLS) estimation and the right panel shows the results for the proposed model and estimation algorithm. Both models were fitted using the correctly specified spline model for the mean. Note that the density is displayed on squareroot scale. }\label{fig:fixed_simul}
%\end{figure}

Figure~S4 %\ref{fig:warp_fixed_simul} 
displays densities of the differences between the maximum likelihood estimates for the true participant-specific warping parameters across participants. The estimates generally seem unbiased with small variance around the true warping parameters.

%\begin{figure}[!ht]
%\centering
%%\input{img/warp_fixed.tex}
%\caption{Densities of the difference between the estimated and the true participant-specific warping parameters across participants.}\label{fig:warp_fixed_simul}
%\end{figure}

Figure~S5 %\ref{fig:variances_simul} 
displays densities for the parameter estimates in the simulated experimental setups. We see that the estimators for the noise scale $\sigma$ and the scales for the warp parameters $\sigma \gamma$ both seem to have a small upward bias. The scale $\sigma\tau$ of the serially correlated effects and the range parameter $1/\alpha$ both seem to be estimated with very little or no bias. Slightly biased variance-parameter estimates are to be expected in likelihood-based inference \cite{Harville}, in particular in nonlinear models where bias-reducing estimation methods such as restricted maximum likelihood (REML), that are inherently linear, are not available. 

%\begin{figure}[!ht]
%\centering
%%\input{img/variance_param.tex}
%\caption{Densities of the estimated variance parameters in the simulated experimental setups. Dashed red lines indicate the true values of the parameters. }\label{fig:variances_simul}
%\end{figure}

\subsection*{Cross-validation grids for motion classification}
Cross-validation was done over:
\begin{description}
\item[MBM] number of bands $J$ in $ \{1,2,3,4,5,6\}$.
\item[DTW] {degrees of freedom for B-spline basis $ \{8, 13, 18, 23, 28, 33, 38\}$. For DTW$_{\text{p}}$ $\{8, 9, \dots, 18\}$.}
\item[FR]  number of principal components in $\{1,2,3,4,5\}$.
\item[FR$_{\textrm{E}}$]  number of principal components in $ \{1,2,3,4,5\}$ and weighting between phase and amplitude distance in $\{0.0, 0.5, \dots, 5.0\}$.
\end{description}



\nolinenumbers

%\section*{References}
% Either type in your references using
% \begin{thebibliography}{}
% \bibitem{}
% Text
% \end{thebibliography}
%
% OR
%
% Compile your BiBTeX database using our plos2015.bst
% style file and paste the contents of your .bbl file
% here.
% 
%\bibliography{bib.bib}
\begin{thebibliography}{10}

\bibitem{Srivastava}
Srivastava A, Wu W, Kurtek S, Klassen E, Marron J.
\newblock Registration of functional data using {F}isher-{R}ao metric.
\newblock arXiv preprint arXiv:11033817. 2011;.

\bibitem{greven2010behaviour}
Greven S, Kneib T.
\newblock On the behaviour of marginal and conditional AIC in linear mixed
  models.
\newblock Biometrika. 2010;97(4):773--789.

\bibitem{Harville}
Harville DA.
\newblock Maximum likelihood approaches to variance component estimation and to
  related problems.
\newblock Journal of the American Statistical Association. 1977;72:320--340.

\end{thebibliography}


\end{document}

