dynfactoR package is aimed at researchers dealing with economic modelling. In particular, it is useful at extracting underlying trends from a potentially large number of economic time series.

Dynamic factor model is a special case of a state space equation. In its general form it can be written as

$$ \begin{equation} \label{eq:statespace} \begin{array}{ll} \mathbf{X}{t} = \mathbf{C}\mathbf{f}{t} + \boldsymbol{\varepsilon}{t}, & \boldsymbol{\varepsilon}{t} \sim \mathcal{N} \left(\mathbf{0}, \mathbf{R} \right) \ \mathbf{f}{t} = \mathbf{A}\mathbf{f}{t-1} + \mathbf{u}{t}, & u{t} \sim \mathcal{N} \left(\mathbf{0}, \mathbf{Q} \right) \end{array} \end{equation} $$

where $\mathbf{X}{t}$ is a vector of observable data which might contain missing data. It is assumed that observable data is linearly driven by a low-dimensional unobservable process $\mathbf{f}{t}$.

Use case

A typical use case for such a model is nowcasting gross domestic product (GDP). GDP data is published every $3$ months, so that economic growth from January to March would only be known in early April. However, many business and consumer surveys are published monthly and are often correlated with GDP growth. Therefore, predictions of economic growth for first quarter should be different depending on whether they are done in December or in February (hence the term \textit{nowcasting}). Dynamic factor model is one way to do that by extracting an underlying trend which often follows economic growth pattern. Besides, if restrictions are imposed on $\mathbf{C}$, economic growth can be modelled explicitly by factors.

State space equations

It is assumed that $\mathbf{A}(L)\mathbf{f}{t} = \mathbf{u}{t}$ where $\mathbf{u}{t} \sim N \left( \mathbf{0}, \operatorname{Id}{r} \right)$ and $\mathbf{A}(L)$ is a lag polynomial with roots inside the unit circle, that is $\mathbf{f}_{t}$ is a covariance-stationary process.

Let $\mathbf{f}{t}$ follow a $p$-th order autoregressive process, so that \begin{equation}\label{eq:factorvar} \mathbf{f}{t} = \mathbf{A}{1}\mathbf{f}{t-1} + \cdots + \mathbf{A}{p}\mathbf{f}{t-p} + \mathbf{u}{t} \end{equation} Suppose that there are $r$-factors, that is $\mathbf{f}{t}$ and $\mathbf{u}{t}$ are $r$-variate processes. If $\mathbf{f}{t}$ were observed, it would be easy to estimate $\left\lbrace \mathbf{A}{1}, \dots, \mathbf{A}{p} \right\rbrace$ with a simple OLS procedure in the context of VAR($p$) model. This estimator would also be a maximum likelihood estimator.

Let $\mathbf{f}{t} = \left(f{1,t}, \dots, f_{r,t}\right)$ and $\mathbf{u}{t} = \left(u{1,t}, \dots, u_{r,t}\right)$. Then \eqref{eq:factorvar} can be rewritten in state space equation form of \eqref{eq:statespace} as

$$ \begin{equation} \begin{pmatrix} f_{1,t} \ f_{2,t} \ \cdots \ f_{r, t} \ f_{1,t-1} \ \dots \ f_{r,t-p+1} \end{pmatrix} = \begin{bmatrix} \mathbf{A}{1} & \cdots & \cdots & \mathbf{A}{p} \ \operatorname{Id}{r} & 0 & 0 \ \dots & \dots & \dots & \dots\ \dots & 0 & \operatorname{Id}{r} & 0 \end{bmatrix} \begin{pmatrix} f_{1,t-1} \ f_{2,t-1} \ \dots \ f_{r,t-1} \ f_{1,t-2} \ \dots \ f_{r,t-p} \end{pmatrix} + \begin{pmatrix} u_{1,t} \ \cdots \ u_{r,t} \ 0 \ \dots \ 0 \end{pmatrix} \end{equation} $$ Evidently, state space covariance matrix has to be extended by zeroes. With this in mind, measurement equation then becomes $$ \begin{equation} \mathbf{X}{t} = \begin{bmatrix} \mathbf{C} & \mathbf{0}{n \times r} & \dots & \mathbf{0}{n \times r} \end{bmatrix} \begin{pmatrix} f{1,t} \ f_{2,t} \ \cdots \ f_{r, t} \ f_{1,t-1} \ \dots \ f_{r,t-p+1} \end{pmatrix} + \boldsymbol{\varepsilon}{t} \end{equation} $$ where $\mathbf{0}{n \times r}$ is zero-matrix with $n$ rows and $r$ columns.

Estimators

Forecasting

Once a dynamic factor model is estimated, $\left(\mathbf{X}{1:T}, \hat{\mathbf{A}}, \hat{\mathbf{C}}\right)$ are available. Predicting $\left(\mathbf{X}{f, T+h}, \mathbf{f}_{T+h}\right)$ for some horizon $h \in \left\lbrace1, \dots \right\rbrace$ consists in three steps:

Future and ongoing work

Some of the ideas for dynamic factor modelling are not yet implemented completely or even at all. This section gathers future ideas for the package.



SebKrantz/dynfacto_R documentation built on Dec. 31, 2020, 4:30 p.m.