A statistical perspective on transformers for small longitudinal cohort data
Authors: Kiana Farhadyar, Maren Hackenberg, Kira Ahrens, Charlotte Schenk, Bianca Kollmann, Oliver Tüscher, Klaus Lieb, Michael M. Plichta, Andreas Reif, Raffael Kalisch, Martin Wolkewitz, Moritz Hess, Harald Binder
Organizations: Institute of Medical Biometry and Statistics (IMBI), University of Freiburg, Freiburg, Germany · Freiburg Center for Data Analysis, Modeling and AI, University of Freiburg, Freiburg, Germany · Department of Psychiatry, Psychosomatic Medicine and Psychotherapy, University Hospital Frankfurt, Frankfurt, Germany · Department of Neuropsychology and Psychological Resilience Research, Central Institute of Mental Health (ZI), Mannheim, Germany · Leibniz Institute for Resilience Research (LIR), Mainz, Germany · Department of Psychiatry and Psychotherapy, Johannes Gutenberg University Medical Center Mainz, Mainz, Germany · Department of Psychiatry, Psychotherapy and Psychosomatic Medicine, University Medicine Halle, Martin-Luther University Halle-Wittenberg, Halle, Germany · German Center for Mental Health (DZPG), partner site Halle-Jena-Magdeburg, Halle, Germany · Neuroimaging Center (NIC), Focus Program Translational Neuroscience (FTN), Johannes Gutenberg University Medical Center, Mainz, Germany
Modeling of longitudinal cohort data typically involves complex temporal dependencies between multiple variables. There, the transformer architecture, which has been highly successful in language and vision applications, allows us to account for the fact that the most recently observed time points in an individual's history may not always be the most important for the immediate future. This is achieved by assigning attention weights to observations of an individual based on a transformation of their values. One reason why these ideas have not yet been fully leveraged for longitudinal cohort data is that typically, large datasets are required. Therefore, we present a simplified transformer architecture that retains the core attention mechanism while reducing the number of parameters to be estimated, to be more suitable for small datasets with few time points. Guided by a statistical perspective on transformers, we use an autoregressive model as a starting point and incorporate attention as a kernel-based operation with temporal decay, where aggregation of multiple transformer heads, i.e. different candidate weighting schemes, is expressed as accumulating evidence on different types of underlying characteristics of individuals. This also enables a permutation-based statistical testing procedure for identifying contextual patterns. In a simulation study, the approach is shown to recover contextual dependencies even with a small number of individuals and time points. In an application to data from a resilience study, we identify temporal patterns in the dynamics of stress and mental health. This indicates that properly adapted transformers can not only achieve competitive predictive performance, but also uncover complex context dependencies in small data settings.
Figures & tables
Approach
Metric
ntrain=100
ntrain=200
ntrain=500
ntrain=1000
Average
MSE
0.209±0.002
0.21±0.002
0.209±0.002
0.209±0.002
MSE j3
0.218±0.007
0.217±0.009
0.214±0.01
0.211±0.007
Regression
MSE
0.209±0.003
0.206±0.002
0.204±0.002
0.204±0.002
MSE j3
0.155±0.005
0.153±0.006
0.152±0.005
0.151±0.004
Informed
MSE
0.204±0.002
0.204±0.002
0.204±0.002
0.204±0.002
MSE j3
0.163±0.008
0.163±0.008
0.161±0.008
0.159±0.005
Table 1: Prediction performance of the MiniTransformer for simulated data with p=10 variables in training datasets with different numbers of sequences ntrain , compared to a simple averaging approach, regression models, and an approach informed by the true structure. Mean squared error is considered across all variables (MSE) and specifically for the variable that is affected by the true pattern (MSE j3 ), together with standard deviations. Smallest values are indicated by boldface.
Figure 1: Individual simulated and fitted trajectories for a random selection of individuals, with true underlying structure zt , observed target xt,j3 , predicted target x^t,j3 , and learned cumulants ( 3 ).
Variable
V=8
V=12
V=16
1
0.084±0.13
0.01±0.02
<0.001
2
0.2±0.29
0.049±0.06
0.002
3
0.084±0.16
0.01±0.02
0.007
4
0.607±0.24
0.633±0.18
0.635
Table 2: Average p-values (and standard deviations from 10 repetitions) resulting from the permutation testing approach when using sampling, with either V=8 or V=12 patterns of xvvisit sampled, contrasted with the full permutation approach with V=16 , in a setting with p=4 variables (where variables 1-3 are part of the true pattern) and 50 sequences.
Approach
Metric
Dataset 1
Dataset 2
Average
MSE
0.170±0.008
0.149±0.006
MSE tar
0.229±0.027
0.208±0.018
Carry forward
MSE
0.220±0.013
0.212±0.020
MSE tar
0.304±0.013
0.298±0.020
Regression
MSE
0.147±0.009
0.135±0.008
MSE tar
0.199±0.024
0.190±0.023
Table 3: Prediction performance of the MiniTransformer for two resilience datasets, each with p=10 , compared to a simple averaging approach, regression models, and a carry forward approach. Mean squared error is considered across all variables (MSE) and for a specific target variable (MSE tar ), together with standard deviations. Smallest values are indicated by boldface.
Rank
Dataset 1
Dataset 2
Variable
pval
Variable
pval
1
dh_38
0.0131±0.02
dh_38
0.0001±0.00
2
dh_53
0.0720±0.08
dh_37
0.0346±0.05
3
le_8
0.1321±0.16
dh_46
0.0850±0.05
4
dh_37
0.1559±0.08
dh_11
0.0996±0.03
5
dh_45
0.2240±0.11
le_17
0.3613±0.10
Table 4: Results of the permutation testing approach for the two resilience application datasets. Average p-values are reported together with standard deviations. Variables are ranked in ascending order of p-values, with rank 1 corresponding to the most important variable.
Figure 2: Context-target effects for resilience dataset 1 (left) and dataset 2 (right). Dark blue indicates smaller values of the visualized test statistic sj(r) (i.e., the context has a smaller effect), while dark red indicates larger values.