Dimension Reduction for Time Series in a Blind Source Separation Context Using R
Full text
This is a self-archived version of an original article. This version may differ from the original in pagination and typographic details. Author(s): Title: Year: Version: Copyright: Rights: Rights url: Please cite the original version: CC BY 3.0 https://creativecommons.org/licenses/by/3.0/ Dimension Reduction for Time Series in a Blind Source Separation Context Using R © Authors, 2021 Published version Nordhausen, Klaus; Matilainen, Markus; Miettinen, Jari; Virta, Joni; Taskinen, Sara Nordhausen, K., Matilainen, M., Miettinen, J., Virta, J., & Taskinen, S. (2021). Dimension Reduction for Time Series in a Blind Source Separation Context Using R. Journal of Statistical Software, 98, Article 15. https://doi.org/10.18637/jss.v098.i15 2021
JSS Journal of Statistical Software July 2021, Volume 98, Issue 15. doi: 10.18637/jss.v098.i15 Dimension Reduction for Time Series in a Blind Source Separation Context Using R Klaus Nordhausen Vienna University of Technology Markus Matilainen Turku PET Centre Jari Miettinen Aalto University Joni Virta Aalto University University of Turku Sara Taskinen University of Jyväskylä Abstract Multivariate time series observations are increasingly common in multiple fields of science but the complex dependencies of such data often translate into intractable models with large number of parameters. An alternative is given by first reducing the dimension of the series and then modelling the resulting uncorrelated signals univariately, avoiding the need for any covariance parameters. A popular and effective framework for this is blind source separation. In this paper we review the dimension reduction tools for time series available in the Rpackage tsBSS. These include methods for estimating the signal dimension of second-order stationary time series, dimension reduction techniques for stochastic volatility models and supervised dimension reduction tools for time series regression. Several examples are provided to illustrate the functionality of the package. Keywords: blind source separation, supervised dimension reduction, R. 1. Dimension reduction and BSS for time series In many fields of applied science multivariate time series, xt= (xt,1, . . . , xt,p)>,t= 1,...T, are collected. Examples include geophysical time series, telecommunications data, financial time series and biomedical time series, e.g., EEG, MEG and fMRI. Such data are often characterized by two main features, which both pose problems for multivariate time series modelling. First, the pcomponents in multivariate time series data are often correlated and therefore individual time series cannot be modelled using univariate time series models. Models such as multivariate autoregressive moving average (ARMA) and multivariate generalized autore-
2Dimension Reduction for Time Series in a BSS Context gressive conditional heteroskedasticity (GARCH) include huge numbers of parameters and model fitting becomes computationally impractical unless the models are noticeably simplified. Second, the data can be high-dimensional and might contain a high unknown number of noise components. As an example, consider current biomedical datasets where the number of time series components vary from hundreds to millions, and the main aim of the analysis is to separate the signals of interest from noise. For such high-dimensional data, fitting multivariate time series models might become impossible, and at the very least unreasonable as it is not sensible to assign a huge number of model parameters for noise components. These two features often encountered in multivariate time series data motivate us to consider dimension reduction methods suitable for time series. In this paper we illustrate how blind source separation (BSS) methods (see for example Comon and Jutten 2010;Nordhausen and Oja 2018) can be used for dimension reduction in a time series context. Recall first that a (linear) BSS model assumes that the observable p-variate time series x= (xt)t=0,±1,±2,... satisfy xt=µ+Ωzt, t = 0,±1,±2,..., (1) where µ∈Rpis a p-variate location vector, Ω∈Rp×pis a full-rank mixing matrix and z= (zt)t=0,±1,±2,... is a p-variate latent time series satisfying E(zt) = 0,Cov(zt) = Ipand Covτ(zt) = E(ztz> t+τ) = Λτis a diagonal matrix for all τ= 1,2,.... The ptime series in zare thus weakly stationary and uncorrelated, and the model is often referred to as a second-order source separation model (SOS). If we make the stronger assumption on the independence of the ptime series in z, then the model is called the independent time series model. The BSS approach for dimension reduction is often preferred since the obtained components can be treated as independent, allowing univariate fitting and prediction methods. For example Van der Weide (2002) and Broda and Paolella (2009) have used this idea for multivariate GARCH modelling. Furthermore, with BSS one can also decide componentwise whether an estimated component is relevant or not. For related research on this, see Matteson and Tsay (2011). There are two different approaches to define signal and noise in BSS. One commonly used noisy BSS model is the one where an additive external noise vector is included in model (1), that is, we assume that xt=µ+Ωzt+t,t= 0,±1,±2, . . . , where t∈Rpis a vector of white noise (Comon and Jutten 2010). The other approach, and the one we prefer, differs from the noisy BSS model in that it assumes that qof the psources are signal and p−q are internal noise components. In particular, we assume that the source vector ztcan be partitioned into two parts, zt= (s> t,w> t)>, so that the first part st∈Rqincludes the sources of interest while wt∈Rp−qrepresents the noise components. To be more specific, we assume the following BSS model xt=µ+Ωzt=µ+Ω1st+Ω2wt, t = 0,±1,±2,..., (2) where µ∈Rpis a location vector, Ω= (Ω1,Ω2)∈Rp×pis a full-rank mixing matrix, Ω1∈Rp×qand Ω2∈Rp×(p−q), and the p-variate latent time series zt= (s> t,w> t)>satisfy (A1) E(zt) = 0and Cov(zt) = Ip, (A2) st∈Rqand wt∈Rp−qare independent.
Journal of Statistical Software 3 (A3) Covτ(zt) = Λτ0 0 0!, where Λτ∈Rq×qis a diagonal matrix for all τ= 1,2, . . . Notice that in model (2) no distributional assumptions are made for the noise components wt, we simply require that they do not show any linear autocorrelations. Examples of such noise components include white noise as well as components exhibiting volatility clustering. The latter components have zero linear autocorrelations but non-zero quadratic autocorrelations. Notice also that in the BSS model (2) the components in stcan be identified at most up to signs and permutations of its components, and Ω1at most up to the signs and permutation of its columns. Matrix Ω2is identifiable only up to post-multiplication with an orthogonal (p−q)×(p−q)matrix. We note that other approaches besides BSS are frequently used for the dimension reduction of multivariate time series data. We next list some of the most well-known of these and discuss the benefits of BSS over them. The simplest options are arguably the classical principal component analysis (PCA) and factor analysis, which however treat the data as independent observations. As the ability to use temporal information is crucial in analyzing time series, a number of extensions of the two methods that allow for this have been suggested in the literature. The most prominent example is given by dynamic factor models, see Stock and Watson (2010); Ensor (2013) and the references therein, where the latent factors are most often assumed to obey a vector autoregressive structure. This is in strict contrast to the BSS model (1) where no structural assumptions on the latent variables are made (beyond temporal uncorrelatedness). As an example of this versatility, consider the methods SOBI and vSOBI discussed in Section 2and Section 3, respectively, which both comply with the BSS framework but the former assumes the sources to be standard linear processes and the latter that they are series exhibiting stochastic volatility. For a more recent extension of PCA, see the time series PCA (Chang, Guo, and Yao 2018) which is actually based on a slight modification of the model (1) and thus constitutes a form of BSS. Other contenders include, e.g., non-negative matrix factorizations (Cheung, Devarajan, Severini, Turolla, and Bonato 2015;Févotte, Smaragdis, Mohammadiha, and Mysore 2018) and autoencoders (Bianchi, Livi, Mikalsen, Kampffmeyer, and Jenssen 2019). The involved complicated constraints and structures make such models difficult to analyze theoretically, whereas the relatively straightforward form of the BSS model makes it possible to obtain convergence rates and other theoretical guarantees (Miettinen, Illner, Nordhausen, Oja, Taskinen, and Theis 2016). To summarize, the advantages of BSS over its competitors lie in its ability to model temporal data while making minimal assumptions on the latent variables and in the BSS model which is simultaneously complicated enough to be useful and simple enough to study theoretically. This paper is organized as follows. In Section 2we recall two classical second-order source separation methods and show how they can be used to estimate the dimension of the interesting source components in model (2). In Section 3we consider dimension reduction in a case where the time series exhibit stochastic volatility and our main interest is finding out whether some of the components lack stochastic volatility features. In Section 4several supervised dimension reduction methods for multivariate time series are discussed. Section 5reviews the existing packages available in R(RCore Team 2021) for multivariate time series and BSS as well as describes the functionality of the Rpackage tsBSS (Matilainen, Croux, Miettinen, Nordhausen, Oja, and Taskinen 2021). In Section 6several examples are given to illustrate the functionality of the tsBSS package. The package tsBSS is available from the Comprehensive R Archive Network (CRAN) at https://CRAN.R-project.org/package=tsBSS.
4Dimension Reduction for Time Series in a BSS Context 2. Dimension estimation using AMUSE and SOBI In this section we illustrate how two classical second-order source separation methods, AMUSE (algorithm for multiple unknown signals extraction) by Tong, Soon, Huang, and Liu (1990) and SOBI (second-order blind identification) by Belouchrani, Abed-Meraim, Cardoso, and Moulines (1997), can be used to estimate the dimension of important components in the BSS model. Let us start by recalling the two methods. Hence, assume for a moment that xt follows a BSS model (2) with q=p, that is, there are no noise components included in the model. Assume also, without loss of generality, that µ=0. The aim of second-order source separation is to find an unmixing matrix W∈Rp×psuch that the component time series in W xtare standardized and mutually uncorrelated, that is, W xt=ztup to location shifts, sign changes and permutations of the components. Write now xst t=Cov(xt)−1/2xtfor a standardized time series. Cardoso and Souloumiac (1993) showed that the standardized series then satisfy xst t=Uzt, where U∈Rp×pis an unknown orthogonal matrix. The standardization thus solves the BSS problem up to rotation, that is, the unmixing matrix is given by W=U>Cov(xt)−1/2. In AMUSE, the rotation matrix Uis found simply using the eigendecomposition of the autocovariance matrix with given lag τ, as by assumption, Covτ(xst t) = UCovτ(zt)U>=UΛτU>for any lag τ. For the statistical properties of AMUSE estimators, see Miettinen, Nordhausen, Oja, and Taskinen (2012). The drawback of the AMUSE procedure is that, in order to separate all psource components, we need to assume that for a chosen lag τ, the eigenvalues in Λτare distinct. As this may not hold in practice, it is often better to use approximate joint diagonalization of several autocovariance matrices as suggested in Belouchrani et al. (1997). Their SOBI method is a natural extension of AMUSE as the solution is given by W=U>Cov(xt)−1/2where the orthogonal U= (u1,...,up)∈Rp×pmaximizes X τ∈T p X i=1 (u> iCovτ(xst t)ui)2, that is, we find a rotation that makes the autocovariance matrices defined by a set of lags T={τ1, . . . , τK}“as diagonal as possible”. Different algorithms for approximate joint diagonalization yield naturally different SOBI solutions. The statistical properties of various SOBI estimators are discussed in Miettinen, Nordhausen, Oja, and Taskinen (2014); Illner et al. (2015); Miettinen et al. (2016) where the performances of the estimators are also compared. In most cases, the SOBI method outperforms the AMUSE method. For more details about joint diagonalization in general and especially in R, see Miettinen, Nordhausen, and Taskinen (2017) and the references therein. In the following, joint diagonalization will be a reoccuring theme in most discussed methods and we will always use for this purpose an algorithm based on Given’s (or Jacobi) rotations as suggested by Clarkson (1988) and implemented in R, for example, in the package JADE (Miettinen et al. 2017). The joint diagonalization of Ksymmetric matrices of size p×pis an operation of complexity O(Kp3)(whereas the ordinary eigendecomposition has K= 1 and the complexity O(p3)), and as such some care has to be taken when applying the methods to data sets where the number of variables is measured in hundreds rather than in tens. Moreover, as is common with eigendecomposition-type algorithms, the possibility of numerical issues should be taken into account when working with data sets having pin the high hundreds.
Journal of Statistical Software 5 Consider then the BSS model (2) with q < p, that is, the model consists of mutually uncorrelated and stationary components as well as of noise components which are not of interest. When using AMUSE, the eigendecomposition of an autocovariance matrix of the standardized vectors xst t=Cov(xt)−1/2xtis now by assumption Covτ(xst t) = U˜ ΛτU>= (U1,U2) Λτ0 0 0! U> 1 U> 2!, where U1∈Rp×q,U2∈Rp×(p−q), and Λτ∈Rq×qis a diagonal matrix consisting of the q marginal τ-th autocovariances of the latent series. As noise components do not show any linear autocorrelations, the last p−qdiagonal values in ˜ Λτare equal to zero. The aim is thus to find a rotation matrix U1so that the latent source components are given by st=U> 1xst t up to sign changes and permutation. In Matilainen, Nordhausen, and Virta (2018), the noise components are identified simply by investigating the diagonal elements of ˜ Λ2 τ, where the squaring is used for ordering the sources in decreasing order of interestingness. The noise components are then the last p−qcomponents having zero eigenvalues. For finite samples, the eigenvalues are naturally never equal to zero, and we look for p−qcomponents having “small enough” eigenvalues. In Matilainen et al. (2018) a bootstrap-based test for testing the null hypothesis H0k:q=kis proposed, and in Virta and Nordhausen (2021) an asymptotic test is given. The signal dimension can then be estimated by testing successively H0kfor all possible dimensions k= 0, . . . , p −1and using the resulting chain of p-values to pin-point the correct dimension. To avoid testing all phypotheses, one can also use, e.g., a divide-and- conquer approach, see Matilainen et al. (2018) for details. Previously similar approaches have been used in the context of independent component analysis (ICA) in Nordhausen, Oja, and Tyler (2017a) and Nordhausen, Oja, Tyler, and Virta (2017b). The AMUSE method based dimension reduction suffers again from one major drawback. The qcomponents of interest must have non-zero autocovariances with the given lag so that they can be separated from noise components. To overcome this problem, the AMUSE method can be replaced with the SOBI method, which uses Kautocovariance matrices in estimation. In order to find all latent source components, it is only required that for each source its autocovariance with one of the lags τ∈ T must be non-zero. In Matilainen et al. (2018) and Virta and Nordhausen (2021), bootstrap and asymptotic tests based on the sum of squared “eigenvalue matrices” Pτ∈T ˜ Λ2 τare used. Notice that as the SOBI procedure is based on joint diagonalization, matrices ˜ Λτare not exact eigenvalue matrices, but obtained as ˜ Λ=diag(U>Covτ(xst t)U). Nevertheless, the testing procedure is similar to that used in the case of AMUSE. For a comparison of different approaches for testing the dimension of source subspace, see Matilainen et al. (2018) and Virta and Nordhausen (2021). As already stated, the choice of the lag set Tis of prime importance in the SOBI-based tests as they only recognize signals having autocorrelation on at least one lag in T. As such, T should be chosen to contain enough lags to identify all the signals, but at the same time be kept small enough, as including too many unnecessary lags can lead into slower computations and noisy estimation in practice. The default set {1,...,12}used in tsBSS exhibits this compromise. The previous naturally holds even stronger for AMUSE which allows only for a single lag τ(yielding faster performance in return) and unless expert knowledge on an appropriate lag is available, SOBI should be used instead of AMUSE. The choice of lags for SOBI is for example also discussed in Tang, Liu, and Sutherland (2005); Taskinen, Miettinen, and Nordhausen (2016).
6Dimension Reduction for Time Series in a BSS Context The above idea to use the magnitude of “eigenvalues” to determine which of the components are noise components and which are interesting source components, can also be visually investigated with a scree plot. In such a plot it is however often difficult to decide when an “eigenvalue” is small enough to be related to a noise component. Recently, Luo and Li (2016) extended the scree plot into the ladle plot where, in addition to the information contained in the eigenvalues, also information from the corresponding eigenvectors is used. The main idea in the ladle plot is that the eigenvectors related to noise components span a space and are not well-defined as compared to the eigenvectors related to components with unique signal eigenvalues. Thus measuring this variability using bootstrap sampling and combining it with the information from the eigenvalues gives us a better picture of the number of noise components. The ladle plot based on AMUSE and SOBI was introduced recently in Nordhausen and Virta (2018). The plots are constructed using stationary time series bootstrapping ideas as follows. Let λ2 0, λ2 1, . . . , λ2 p−1be the (re-indexed) “eigenvalues” in decreasing order and define the normalized function φ:{0, . . . , p −1} → Ras φn(k) = λ2 k(1 + p−1 X l=0 λ2 l)−1. Next, let ˆ Bkcontain the first kcorresponding columns of the (joint) diagonalizer of AMUSE (SOBI) computed for the original data sample and denote by B∗ k,j,j= 1, . . . , m, the corresponding quantity for the j-th bootstrap sample. The average variation (around ˆ Bk) of the space spanned by the first kvectors can then be measured as fn(k) = 1 m m X j=1 {1− |det( ˆ B> kB∗ k,j)|}, for k= 1, . . . , p −1with fn(0) := 0. The ladle function gn(k)is now obtained simply by summing the functions φnand fn, gn(k) = fn(k) + φn(k), and visualizing the ladle function then yields the ladle plot. The ladle estimator for the source subspace dimension is the value of kfor which gn(k)is minimal. For further details, the interested reader is referred to Luo and Li (2016) and Nordhausen and Virta (2018). 3. Dimension reduction in the context of volatility clustering As discussed earlier, AMUSE and SOBI use linear autocovariances in estimation and have proven to be powerful methods when separating uncorrelated linear processes from noise. However, as these two methods treat also components exhibiting volatility clustering as noise, they cannot be used for estimating such time series. If this is our main interest, then extensions of second-order source separation methods are needed. Matilainen, Nordhausen, and Oja (2015) considered the independent component model for time series (which assumes that the component series in ztare independent) and proposed two methods which use fourth-order cumulants in estimation: In gFOBI (generalized FOBI),
Journal of Statistical Software 7 the matrices of fourth cross-moments Bτ(xt) = E[xt+τx> txtx> t+τ]are approximately jointly diagonalized, that is, we find an orthogonal matrix U∈Rp×psuch that it maximizes X τ∈T p X i=1 (u> iBτ(xst t)ui)2. The gFOBI estimator is then given by W=U>Cov(xst t)−1/2. Notice that by using τ= 0 we obtain the classical FOBI (fourth-order blind identification) method which was proposed already in Cardoso (1989) for solving the independent component analysis problem. The gJADE (generalized JADE) method, in turn, extends the classical JADE (joint approximate diagonalization of eigenmatrices) method by Cardoso and Souloumiac (1993) to a time series context by using a larger class of fourth-order cumulants in estimation. Write the cross-cumulant matrices as Cjk τ(xt) = E[xt+τx> tEjkxtx> t+τ]−Covτ(xt)(Ejk +Ekj)Covτ(xt)>−trace(Ejk)Ip, where Ejk =eje> k,j, k = 1, . . . , p with eidenoting the vector with a 1 in the i-th coordinate and 0’s elsewhere. Then the gJADE solution is given by W=U>Cov(xt)−1/2, where orthogonal U∈Rp×pmaximizes X τ∈T p X i=1 p X j=1 p X k=1 (u> iCjk τ(xst t)ui)2. Again, the choice τ= 0 reduces to the classical JADE solution. Another branch of methods designed for separating independent time series exhibiting volatility clustering is based on the use of nonlinearity functions in the estimation. An extension of classical SOBI method was proposed in Matilainen, Miettinen, Nordhausen, Oja, and Taskinen (2017b). Their vSOBI (variant of SOBI) estimate is given by W=U>Cov(xst t)−1/2, where U∈Rp×pmaximizes X τ∈T p X i=1 (E[G(u> ixst t)G(u> ixst t+τ)] −E[G(u> ixst t)]E[G(u> ixst t+τ)])2, and Gcan be any twice continuously differentiable function. Commonly used choices for Gare G(y) = y2and G(y) = log(cosh(y)). The vSOBI method also extends the two FixNA (Fixedpoint algorithms for maximizing nonlinear autocorrelation) methods proposed by Hyvärinen (2001) and Shi, Jiang, and Zhou (2009). For the comparisons of gFOBI, gJADE, FixNA and vSOBI, see Matilainen et al. (2017b). The methods recalled above are designed for separating time series which do not show any linear autocorrelations. However, if our interest is in separating uncorrelated stationary time series from components exhibiting volatility clustering, that is, we consider the BSS model (2) with the p−qnoise sources actually being components with volatility clustering, the above methods are not applicable. Miettinen, Matilainen, Nordhausen, and Taskinen (2019) combined a second-order source separation method (SOBI) with vSOBI using G(x) = x2. Their gSOBI (generalized SOBI) solution is given as W=U>Cov(xst t)−1/2, where U∈Rp×psolves bX τ1∈T1 p X i=1 (uiCovτ1(xst t)u> i)2+ (1 −b)X τ2∈T2 p X i=1 (E[(u> ixst t)2(u> ixst t+τ2)2]−1)2.
8Dimension Reduction for Time Series in a BSS Context Here T1and T2are the lag sets for the linear and the quadratic parts, respectively, and b∈[0,1] assigns the weights for the two parts. The first part of the objective function is designed to find components which are linear processes and the second part components with volatility clustering. In Miettinen et al. (2019) the statistical properties of the gSOBI estimator are given, and its performance under different values for bis studied using simulation studies. The value of bshould be larger than 0.5 and b= 0.9is suggested for general use. Miettinen et al. (2019) also propose a test for identifying whether there is volatility clustering in the components or not. In order to do this, possible linear autocorrelation of a component needs to be removed first. The presence of linear autocorrelation is measured using a modified version of Ljung-Box test. For the components exhibiting linear autocorrelation, volatility clustering test is performed on ARMA residuals. Finally, the components are ordered according to the value of the test statistic of the volatility clustering test. The research in Miettinen et al. (2019) was motivated by Hu and Tsay (2014) who proposed principal volatility component (PVC) analysis for identifying and ordering components with volatility clustering. With a slight modification, the PVC method can also be seen as a BSS method as it simultaneously diagonalizes two scatter matrices (see Miettinen et al. 2019, for more details). 4. Supervised dimension reduction for time series The methods described above can be considered as unsupervised dimension reduction methods as no specific response, which should be modelled based on xt, was assumed. In supervised dimension reduction it is assumed that we have observed a univariate response time series ytand that the dimension of xtshould be reduced without losing information about yt and without knowing the functional relationship between ytand xt. Supervised dimension reduction methods are well established for iid data, the most popular methods being sliced inverse regression (SIR) (Li 1991) and sliced average variance estimation (SAVE) (Cook 2000). These and other iid supervised dimension reduction methods are implemented, for example, in Rin the package dr (Weisberg 2002). Supervised dimension reduction in case of time series data is however much more difficult as the dependence between ytand xtmay also lag in time. To address this problem Matilainen, Croux, Nordhausen, and Oja (2017a) and Matilainen, Croux, Nordhausen, and Oja (2019) suggested time series versions of SIR and SAVE as well as a weighted linear combination of the two methods. The three approaches are denoted TSIR, TSAVE and TSSH (time series SIR SAVE hybrid), respectively, and recalled in the following. Let now y= (yt)t=0,±1,±2,... and x= (xt)t=0,±1,±2,... be (weakly and jointly) stationary univariate and p-variate time series, respectively. We then assume that yt=f(xt,xt−1, . . . ;t, t−1, . . .), where function fis unspecified, = (t)t=0,±1,±2,... is an unspecified stationary noise process independent from xt, and the explaining time series xtfollow the BSS model xt=Ωzt+µ, where again µ∈Rpis a location vector and Ω∈Rp×pis a full rank mixing matrix. The stationary p-variate source time series ztcan be partitioned into zt= (z(1)> t,z(2)> t)>, where
Journal of Statistical Software 15 SL component gn 0.0 0.1 0.2 0.3 0.4 0 1 2 3 4 5 6 7 8 9 10 11 12 Figure 1: Ladle plot for the sound example data. The plot is then obtained as R> ladleplot(SL) and shown in Figure 1where the position of the minimum again verifies that there are three signals in this time series. To see the three signals one can use R> plot(SL, which = "k") where which = "k" specifies that one does not want to plot all sources but only those corresponding to the estimated number of signals. The time courses of the three signals are shown in Figure 2. 6.2. Dimension reduction in the context of stochastic volatility In financial time series the second order correlations are often not of interest and the focus is on the stochastic volatility features of the data. Our preferred method in this context is gSOBI and we will demonstrate its functionality using the exchange rate dataset from stochvol package (Kastner 2016), which contains daily bilateral prices of one Euro in 23 currencies. The daily measurements are from January 3, 2000, until April 4, 2012. In addition to the tsBSS package we use for this example also the packages stochvol (Kastner 2016) and zoo (Zeileis and Grothendieck 2005). For reproducibility purposes for this example also a seed is set.
16 Dimension Reduction for Time Series in a BSS Context −4 0 2 4 Series1 −10 0 5 Series2 −4 0 4 0123456 Series3 Time S Figure 2: The estimated signals from sound example data based on the ladle estimate using SOBI. R> library("tsBSS") R> library("zoo") R> library("stochvol") R> data("exrates", package = "stochvol") R> set.seed(1234) We apply the gSOBI method to the logarithmic returns of the original variables using the preferred weight b = 0.9 for the “SOBI” part. The resulting sources will be ordered according to their volatility clustering level which we evaluate using quadratic autocorrelations after removing componentwise second order autocorrelations by fitting automatically ARMA to those components which exhibit linear autocorrelation. The argument acfk = 1:5 specifies that the first five lags should be used to test for linear and quadratic autocorrelation, respectively. R> exrlogr <- zoo(apply(exrates[, -(ncol(exrates))], 2, logret)) R> attr(exrlogr, "index") <- as.Date(rownames(exrlogr)) R> gSOBIwrd <- gSOBI(exrlogr, b = 0.9, ordered = TRUE, acfk = 1:5, + original = FALSE) The 23 raw sources can be plotted as follows R> plot(gSOBIwrd$Sraw, main = "The raw sources", xlab = "Time") However, due to the dimensionality of the data the figure is not included here. To evaluate which components exhibit serial autocorrelations we look at the linP object which returns the marginal pvalues based on the modified Ljung-Box test. The armaeff object is a binary indicator indicating which source components exhibit serial autocorrelation. R> round(gSOBIwrd$linP, 4)
Journal of Statistical Software 17 [1] 0.4991 0.1480 0.0818 0.7412 0.5197 0.3284 0.3159 0.7355 0.0816 [10] 0.0546 0.3886 0.0740 0.0231 0.1486 0.0618 0.0292 0.2741 0.4634 [19] 0.1543 0.0146 0.1054 0.8372 0.2959 R> gSOBIwrd$armaeff [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [12] FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE [23] FALSE In our example, there are three components that exhibit significant serial linear autocorrelation. The sources of interest, in which the linear autocorrelation has been removed, can then be plotted with the command R> plot(bss.components(gSOBIwrd), main = "The sources", xlab = "Time") However, for space reasons we again refrain from showing the figure here. The next step in the analysis is typically to study volatility at each time point. To estimate these quantites, assuming a stochastic volatility (SV) model, the package stochvol offers the function svsample. This function uses Markov chain Monte Carlo (MCMC) for the estimation making this quite time consuming. Therefore for demonstration purpose we focus on the three components which are considered to have the most volatility clustering and the three components considered to have the least volatility clustering. For convenience we write a wrapper around svsample to extract only the quantity of interest. R> svsample_exph <- function(x) { + svsample(x)$summary$latent[, 6] + } R> #estimating the volatilities using MCMC sampling R> ExpH_gSOBI <- apply(bss.components(gSOBIwrd)[, c(1:3, 21:23)], 2, + svsample_exph) R> ExpH_gSOBI <- zoo(ExpH_gSOBI, order.by = as.Date(rownames(exrlogr))) R> plot(ExpH_gSOBI, ylim = c(0, 8), main = "Volatility series of components + with the most and the least volatility clustering") Figure 3shows that the last components have clearly much less volatility clustering compared to the first components. To see if the components have significant marginal volatility clustering, the corresponding pvalues based on a modified Ljung-Box test are available via R> round(gSOBIwrd$volP, 4) [1]00000000000000000000000 Based on these results all the components seem to have significant volatility clustering. It is however obvious that the degree of volatility clustering differs considerable between the components and that the first components are much more interesting that the last components. As a comparison, we perform the same analysis using the (modified) principal volatility component (PVC) analysis. We first look at the pvalues for the linear and quadratic autocorrelations.
18 Dimension Reduction for Time Series in a BSS Context 0 2 4 6 8 Series 1 0 2 4 6 8 Series 2 2000 2004 2008 2012 Index 02468 Series 3 0 2 4 6 8 Series 21 0 2 4 6 8 Series 22 2000 2004 2008 2012 Index 02468 Series 23 Volatility series of components with the most and the least volatility clustering Figure 3: Volatility series of three components with the most volatility clustering and three components with the least volatility clustering extracted using gSOBI. R> PVCwrd <- PVC(exrlogr, ordered = TRUE, acfk = 1:5, original = FALSE) R> round(PVCwrd$linP, 4) [1] 0.5172 0.1416 0.8147 0.0337 0.6906 0.0068 0.7410 0.2194 0.1110 [10] 0.4026 0.2933 0.2200 0.4044 0.1424 0.1574 0.0967 0.2094 0.0000 [19] 0.2863 0.5095 0.0227 0.1612 0.3487 R> PVCwrd$armaeff [1] FALSE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE FALSE FALSE [12] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE [23] FALSE R> round(PVCwrd$volP, 4) [1]00000000000000000000000 Four components seem to have linear autocorrelation and that is removed in order to estimate the volatility of the sources. Then we compute again the marginal volatilities based on the SV model as in the gSOBI case. The resulting volatility components using PVC are in Figure 4. R> ExpH_PVC <- apply(bss.components(PVCwrd)[, c(1:3, 21:23)], 2, svsample_exph) R> ExpH_PVC <- zoo(ExpH_PVC, order.by = as.Date(rownames(exrlogr))) R> plot(ExpH_PVC, ylim = c(0, 8), main = "Volatility series of components + with the most and the least volatility clustering")
Journal of Statistical Software 19 0 2 4 6 8 Series 1 0 2 4 6 8 Series 2 2000 2004 2008 2012 Index 02468 Series 3 0 2 4 6 8 Series 21 0 2 4 6 8 Series 22 2000 2004 2008 2012 Index 02468 Series 23 Volatility series of components with the most and the least volatility clustering Figure 4: Volatility series of components with the most volatility clustering and three components with the least volatility clustering extracted using PVC. Finally, we compare the gSOBI and the PVC results to corresponding principal components computed with standard principal component analysis (PCA) which ignores the time structure and is thus not targeting volatility clustering effects. As gSOBI and PVC standardize the components to have variance one, we do so here for the obtained PCs as well. R> PCA <- princomp(exrlogr) R> PCst <- scale(PCA$scores) After that we remove linear autocorrelations R> linear <- lbtest(PCst, 1:5, "linear") R> armaeff <- (linear$p_val < 0.05) R> p <- ncol(PCst) R> PCst2 <- PCst R> index <- (1:p)[armaeff] R> for (j in index) { + PCst2[, j] <- forecast::auto.arima(PCst[,j], stationary = TRUE, + seasonal = FALSE)$residuals + } R> PCst2 <- zoo(PCst2, order.by = as.Date(rownames(exrlogr))) The components are then ordered according to the volatility test statistic Q. The volatility series of components with the most and the least volatility clustering are plotted in Figure 5. R> vol <- lbtest(PCst2, 1:5, "squared") R> ordered <- order(vol$TS, decreasing = TRUE) R> PCst3 <- PCst2[, ordered]
20 Dimension Reduction for Time Series in a BSS Context 0 2 4 6 8 Comp.22 0 2 4 6 8 Comp.2 2000 2004 2008 2012 Index 02468 Comp.6 0 2 4 6 8 Comp.15 0 2 4 6 8 Comp.17 2000 2004 2008 2012 Index 02468 Comp.21 Volatility series of components with the most and the least volatility clustering Figure 5: Volatility series of components with the most volatility clustering and three components with the least volatility clustering extracted using PCA. R> ExpH_PCA <- apply(PCst3[, c(1:3, 21:23)], 2, svsample_exph) R> ExpH_PCA <- zoo(ExpH_PCA, order.by = as.Date(rownames(exrlogr))) R> plot(ExpH_PCA, ylim = c(0, 8), main = "Volatility series of components + with the most and the least volatility clustering") As before, all the components have volatility clustering, but it seems to be higher in the components with the least volatility clustering compared to the volatility series based on gSOBI or PVC. Note that the ordering of the volatility clustering is not related to the order of the PCs. Using for example only a few first PCs might have missed the components exhibiting a lot of volatility clustering. The most volatile component (Comp. 22) is the one with the second lowest variance. To further compare compare to gSOBI and PVC, note that for PCA the volatility clustering test statistic values are much less dispersed, i.e., even the ones with the lowest test statistic value tend to have more volatility clustering. This is a disadvantage when trying to uncover possible components without volatility clustering. R> round(gSOBIwrd$volTS) #gSOBI [1] 2733209 1131552 1056249 695381 166247 157372 156301 86093 [9] 52503 51997 36702 21050 10577 6927 6095 4237 [17] 2468 2128 1382 764 666 98 86 R> round(PVCwrd$volTS) #PVC [1] 2587720 177967 86407 79737 33781 29551 23391 10914 [9] 10848 8419 3667 2653 2349 2023 1140 1028 [17] 634 567 524 504 409 391 184
Journal of Statistical Software 21 R> round(vol$TS[ordered]) #PCA [1] 803437 234315 67806 45408 27815 23148 22255 21614 13381 [10] 13019 10258 5872 5505 4702 4354 3873 2187 1964 [19] 1702 1657 1416 998 595 6.3. Supervised dimension reduction for time series To conclude the illustration of the tsBSS package we demonstrate how to perform TSIR in a supervised dimension reduction context. For that purpose we use the PRSA data set (Liang et al. 2015) which is available from the UCI Machine Learning Repository (Dheeru and Karra Taniskidou 2017) and can be loaded into Ras R> PATH <- paste0("https://archive.ics.uci.edu/ml/machine-learning", + "-databases/00381/PRSA_data_2010.1.1-2014.12.31.csv") R> PRSA <- read.csv(PATH) The dataset includes hourly measurements of fine particulate matter, PM2.5 concentrations, taken at the US Embassy in Beijing, and some meteorological data from Beijing Capital International Airport. The whole dataset is from January 2010 to December 2014. The goal is here to predict the PM2.5 concentration using as predicting time series the hourly measurements of DEWP (dew point; ℃), TEMP (temperature; ℃), PRES (air pressure; hPa), Iws (cumulated wind speed; m/s), Is (cumulated hours of snow) and Ir (cumulated hours of rain). For a complete description of the data set, see Liang et al. (2015) and https: //archive.ics.uci.edu/ml/datasets/Beijing+PM2.5+Data. For simplicity we use the data from March 2013 to October 2014 and impute the few missing values using the package imputeTS (Moritz and Bartz-Beielstein 2017) with a simple moving average. R> library("imputeTS") R> response <- na_ma(PRSA[27721:42360, 6], k = 4, "simple") R> predictors <- PRSA[27721:42360, -c(1:6, 10)] The response time series in Figure 6can be plotted as R> plot(ts(response), ylab = "PM 2.5 concentration", xlab = "Time in hours") As a preparation step we make the predicting time series more stationary by taking the first order differences. For the variables Iws,Is and Ir this is done after taking logarithms where, if needed, one was added to make the counts all positive. Also all the time series are then centered and scaled. R> predictors$Iws <- log(predictors$Iws) R> predictors$Ir <- log(predictors$Ir + 1) R> predictors$Is <- log(predictors$Is + 1) R> X <- scale(diff(as.matrix(predictors))) R> y <- scale(response[-1])
22 Dimension Reduction for Time Series in a BSS Context Time in hours PM 2.5 concentration 0 5000 10000 15000 0 200 400 600 Figure 6: The hourly measured PM 2.5 concentration values. −15 −5 5 DEWP −5 0 5 TEMP −5 0 5 PRES −6 −2 2 Iws −60 −20 Is −15 −5 5 0 5000 10000 15000 Ir Time in hours Figure 7: The six times series which should be used to explain the PM 2.5 concentration values.
Journal of Statistical Software 23 The six explaining time series are then plotted in Figure 7with the command R> plot(ts(X), xlab = "Time in hours", main = "", nc = 1) To perform supervised dimension reduction we use the tssdr function, which has TSIR as its default. We choose to compute TSIR using the first 12 lags with 10 slices. R> library("tsBSS") R> TSIR <- tssdr(y, X, H = 10, algorithm = "TSIR", k = 1:12) We could check all the estimated sources using components(TSIR). However, the most convenient way to work with the TSIR object, which is of class ‘tssdr’, is to use the summary function, where one can specify the method and threshold to investigate which directions and lags might be relevant. Among the strategies for choosing the directions and the lags, we choose the biggest values method with a threshold of 0.8, R> TSIRbiggest <- summary(TSIR, thres = 0.8, type = "big") To see the most important results we can just use R> TSIRbiggest Summary of TSIR for response y and predictors X The signal separation matrix W is: [,1] [,2] [,3] [,4] [,5] [,6] [1,] -0.652 0.167 0.751 0.0401 -0.0439 -0.0229 The L matrix is: Dir.1 Dir.2 Dir.3 Dir.4 Dir.5 Dir.6 Lag 1 0.0251 0.00509 0.008412 0.000396 0.001478 0.000370 Lag 2 0.0412 0.00746 0.006506 0.000663 0.001076 0.000910 Lag 3 0.0578 0.00924 0.003978 0.001520 0.000610 0.000664 Lag 4 0.0725 0.00804 0.002212 0.002298 0.000368 0.000435 Lag 5 0.0881 0.00585 0.000769 0.001099 0.000546 0.001516 Lag 6 0.0949 0.00450 0.000642 0.001324 0.001223 0.000793 Lag 7 0.1021 0.00255 0.002390 0.001082 0.000578 0.000348 Lag 8 0.0990 0.00345 0.001567 0.000614 0.000873 0.000648 Lag 9 0.0844 0.00801 0.001232 0.000270 0.000949 0.000762 Lag 10 0.0678 0.01147 0.001111 0.000915 0.001054 0.000429 Lag 11 0.0558 0.01834 0.001199 0.000650 0.000540 0.000359 Lag 12 0.0453 0.02009 0.002296 0.000811 0.000617 0.000816 Using the biggest values in L to choose the directions and lags: The relevant combinations of lags and directions are
24 Dimension Reduction for Time Series in a BSS Context 0 4 y −5 5 0 5000 10000 15000 Series 1 Time The response and the chosen directions Figure 8: The hourly PM 2.5 concentration values time series together with the component considered relevant by TSIR. Lag Dir. [1,] 7 1 [2,] 8 1 [3,] 6 1 [4,] 5 1 [5,] 9 1 [6,] 4 1 [7,] 10 1 [8,] 3 1 [9,] 11 1 [10,] 12 1 [11,] 2 1 Following the biggest value strategy, one linear combination of predicting time series seems sufficient to model the response. The weights that the linear combination of interest gives to each variable can be seen from the matrix Wwhich can be extracted using coef(TSIRbiggest). The weights corresponding to the differentiated variables of Iws,Is and Ir are very small, whereas the differentiated variables of DEWP and PRES have the largest impact on the linear combination. From the last part of the summary output it seems also that the most relevant thing is what happened 6–8 hours before as these lags have the largest information content. If the air pressure has gone up and the dew point has gone down during the last 6-8 hours, which might be an indication of drier weather, which would have an effect on how long the pollution particles stay in the air. The first few values of the chosen source can be printed as R> head(components(TSIRbiggest))