Nonlinear Dynamic Factor Analysis With a Transformer Network
Oliver Snellman
TL;DR
This paper introduces an Encoder-Encoder Transformer tailored for nonlinear dynamic factor analysis in macro time series, producing one latent factor per lag within a context window of $P=9$ with about $26{,}000$ parameters. A key innovation is a prior-information regularizer that pulls the Transformer toward a conventional linear factor model (e.g., Kalman filter), improving performance on small datasets while preserving nonlinear flexibility. The attention mechanism provides interpretable insights into which variables and lags drive the factor estimate, and it also enables analysis of regime switches via time-varying attention patterns. In Monte Carlo experiments, the Transformer often surpasses a linear Kalman filter when data deviate from linear-Gaussian assumptions, and it is applied to construct a coincident index of U.S. real activity that aligns with NBER recessions and responds to major crises. Overall, the study establishes a foundation for using Transformers in macroeconomic latent-state estimation with transparent attention-based diagnostics and a practicable pathway for small-sample applications.
Abstract
The paper develops a Transformer architecture for estimating dynamic factors from multivariate time series data under flexible identification assumptions. Performance on small datasets is improved substantially by using a conventional factor model as prior information via a regularization term in the training objective. The results are interpreted with Attention matrices that quantify the relative importance of variables and their lags for the factor estimate. Time variation in Attention patterns can help detect regime switches and evaluate narratives. Monte Carlo experiments suggest that the Transformer is more accurate than the linear factor model, when the data deviate from linear-Gaussian assumptions. An empirical application uses the Transformer to construct a coincident index of U.S. real economic activity.
