Factor Models

Time Series

Department of Mathematical Sciences, Aalborg University

Factor Models and Principal Component Analysis

Big data

  • There has been a huge increase in the amount of data available.

  • This has led to the development of new techniques to analyze and extract information from data.

  • The dynamics of the data can be complex, but it is often the case that the data has some underlying structure.

  • Today, we will discuss some of these techniques: principal component analysis and factor models.

Principal Component Analysis

Principal component analysis

  • Principal component analysis (PCA) is a technique used to reduce the dimensionality of a dataset.

  • It is based on the idea of finding the directions in which the data has the largest variance.

  • These directions, called principal components, can be used to capture most of the information in the data with fewer variables.

Principal component analysis

  • Let \(X_1, X_2,\cdots, X_p\) be a set of variables centered at zero.

  • The first principal component is the normalized linear combination of the features \[Z_1 = \phi_{11}X_1 +\phi_{21}X_2 +\cdots+\phi_{p1}X_p,\] that has the largest variance.

  • That is, \(Z_1\) solves the optimization problem \[\max_{\phi_{11},\phi_{21},\cdots\phi_{p1}}Var(Z_1), \ \ \ \ \text{subject to}\ \ \ \ \sum_{j=1}^p\phi_{j,1}^2 =1.\]

Principal component analysis

  • In matrix form, \[\mathbb{X} = \begin{bmatrix}x_{1,1} &x_{1,2} &\cdots &x_{1,p}\\ x_{2,1} &x_{2,2} &\cdots &x_{2,p}\\\vdots &\vdots &\ddots &\vdots \\ x_{n,1} &x_{n,2} &\cdots &x_{n,p}\end{bmatrix}\ \ \ \ \Phi_1 = \begin{bmatrix} \phi_{1,1} \\ \phi_{2,1}\\\vdots\\\phi_{p,1} \end{bmatrix},\]

\(Z_1\) can be written as \(Z_1 = \mathbb{X}\Phi_1\).

  • Its variance is given by \[Var(Z_1) = \Phi_1'Var(\mathbb{X})\Phi_1.\]

Principal component analysis

  • The variance of the first principal component is given by \[Var(Z_1) = \frac{1}{n}\Phi_1'\mathbb{X}'\mathbb{X}\Phi_1.\]

  • Hence, the first principal component solves \[\max_{\Phi_1} \Phi_1'\mathbb{X}'\mathbb{X}\Phi_1,\ \ \ \text{subject to} \ \ \ \Phi_1'\Phi_1 = 1.\]

Principal component analysis

  • The Lagrangean of the problem is given by

\[\mathcal{L}(\Phi_1,\lambda_1) = \Phi_1'\mathbb{X}'\mathbb{X}\Phi_1 - \lambda_1(\Phi_1'\Phi_1-1).\]

  • The first order conditions are given by \[\begin{align} \frac{\partial \mathcal{L}}{\partial \Phi_1} &= 2\mathbb{X}'\mathbb{X}\Phi_1 - 2\lambda_1\Phi_1 = 0,\\ \frac{\partial \mathcal{L}}{\partial \lambda_1} &= \Phi_1'\Phi_1-1=0. \end{align}\]

  • From the first equation, the first principal component is the eigenvector of \(\mathbb{X}'\mathbb{X}\) with largest eigenvalue, \(\lambda_1\).

Principal component analysis

  • The second principal component is the normalized linear combination of the features that has the second largest variance and is uncorrelated with the first.
  • That is, the second principal component solves \[\max_{\Phi_2} \Phi_2'\mathbb{X}'\mathbb{X}\Phi_2,\ \ \text{subject to} \ \Phi_2'\Phi_2 = 1, \ \Phi_2'\Phi_1 = 0.\]

  • Similar derivations as before show that the second principal component is the eigenvector of \(\mathbb{X}'\mathbb{X}\) with the second largest eigenvalue, \(\lambda_2\).

  • Moreover, the eigenvectors of \(\mathbb{X}'\mathbb{X}\) are orthogonal.

Principal component analysis

Theorem (Eigenvectors of symmetrical matrices).

Let \(A\) be a symmetrical matrix. Then, the eigenvectors of \(A\) associated to different eigenvalues are orthogonal.

Principal component analysis

  • The \(k\)-th principal component is the normalized linear combination of the features that has the \(k\)-th largest variance and is uncorrelated with the previous \(k-1\) principal components.

  • The \(k\)-th principal component is the eigenvector of \(\mathbb{X}'\mathbb{X}\) with the \(k\)-th largest eigenvalue.

  • The eigenvectors of \(\mathbb{X}'\mathbb{X}\) are orthogonal.

  • The principal components are the eigenvectors of the covariance matrix of the data.

Principal component analysis

Code
set.seed(614)
many = 500
x = rnorm(many,0,1)
y = 3*x+rnorm(many,0,1)

X = scale(cbind(y,x))
plot(X,xlab="",ylab="",pch=1)
legend(-3, 2.5, c("Original data"),pch=c(1),col=c(1))

Principal component analysis

Code
pr.out = prcomp(X)
NX = X%*%pr.out$rotation[1:2,1]
NXY = NX%*%pr.out$rotation[1,1:2]
plot(X,xlab="",ylab="",pch=1)
points(NXY,pch=18,col=2,cex=1.2)
legend(-3, 2.5, c("Original data", "First Principal Component"),pch=c(1,18),col=c(1,2))

Principal component analysis

Scree plot

  • The scree plot shows the proportion of variance explained by each principal component.

  • It is used to determine the number of principal components needed to capture most of the information in the data.

  • It is defined as the proportion of variance explained by the \(k\)-th principal component, \[\frac{\lambda_k}{\sum_{j=1}^p\lambda_j}.\]

Principal component analysis

Scree plot

raw_data = read.csv2("Stocks_PCA_clean.csv",header=T,na.strings = "")
data = na.omit(raw_data)
time = as.Date(data[,1],"%d/%m/%Y")
stocks = as.ts(scale(data[,2:11]))
plot(stocks,main="",xlab="")

Principal component analysis

Scree plot

pr.out = prcomp(stocks)
pr.var = pr.out$sdev^2
pve = pr.var/sum(pr.var)
plot(pve,ylab="PVE", cex = 2)

Principal component analysis

Scree plot

plot(as.ts(-pr.out$x[,1:3]),plot.type="single",col=c(1,2,3),xaxt="n",
            ylab="PCA",xlab="",lty=c(1,2,3))
legend(0,8,c("First PC","Second PC","Third PC"),col=c(1,2,3),lty=c(1,2,3))
xat=seq(1,4725,by=500)
axis(1, at=xat, labels=time[xat])

Principal component analysis

Scree plot

plot(stocks,main="",xlab="")

plot(as.ts(-pr.out$x[,1:3]),plot.type="single",col=c(1,2,3),xaxt="n",
            ylab="PCA",xlab="",lty=c(1,2,3))
legend(0,8,c("First PC","Second PC","Third PC"),col=c(1,2,3),lty=c(1,2,3))
xat=seq(1,4725,by=500)
axis(1, at=xat, labels=time[xat])