Type: | Package |
Title: | Frequency Domain Based Analysis: Dynamic PCA |
Version: | 2.0.5 |
Date: | 2024-04-03 |
Author: | Hormann S., Kidzinski L. |
Maintainer: | Kidzinski L. <lukasz.kidzinski@stanford.edu> |
Description: | Implementation of dynamic principal component analysis (DPCA), simulation of VAR and VMA processes and frequency domain tools. These frequency domain methods for dimensionality reduction of multivariate time series were introduced by David Brillinger in his book Time Series (1974). We follow implementation guidelines as described in Hormann, Kidzinski and Hallin (2016), Dynamic Functional Principal Component <doi:10.1111/rssb.12076>. |
License: | GPL-3 |
Depends: | R (≥ 2.15.0), mvtnorm, stats, graphics, base, matrixcalc, utils |
Suggests: | fda, MASS, MARSS, testthat (≥ 3.0.0) |
RoxygenNote: | 7.2.3 |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2024-04-06 21:40:37 UTC; kidzik |
Repository: | CRAN |
Date/Publication: | 2024-04-06 22:03:00 UTC |
Frequency domain basde analysis: dynamic PCA
Description
Implementation of dynamic principle component analysis (DPCA), simulation of VAR and VMA processes and frequency domain tools. The package also provides a toolset for developers simplifying construction of new frequency domain based methods for multivariate signals.
Details
freqdom package allows you to manipulate time series objects in both time and frequency domains. We implement dynamic principal component analysis methods, enabling spectral decomposition of a stationary vector time series into uncorrelated components.
Dynamic principal component analysis enables estimation of temporal filters which transform a vector time series into another vector time series with uncorrelated components, maximizing the long run variance explained. There are two key differnces between classical PCA and dynamic PCA:
Components returned by the dynamic procedure are uncorrelated in time, i.e. for any
i \neq j
andl \in Z
,Y_i(t)
andY_j(t_l)
are uncorrelated,The mapping maximizes the long run variance, which, in case of stationary vector time series, means that the process reconstructed from and
d > 0
first dynamic principal components better approximates your vector time series process than the firstd
classic principal components.
For details, please refer to literature below and to help pages of functions dpca
for estimating the components, dpca.scores
for estimating scores and
dpca.KLexpansion
for retrieving the signal from components.
Apart from frequency domain techniques for stationary vector time series,
freqdom provides a toolset of operators such as the vector Fourier Transform
(fourier.transform
) or a vector spectral density operator
(spectral.density
) as well as simulation of vector time series
models rar
, rma
generating vector
autoregressive and moving average respectively.
These functions enable developing new techniques based on the Frequency domain analysis.
References
Hormann Siegfried, Kidzinski Lukasz and Hallin Marc. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Hormann Siegfried, Kidzinski Lukasz and Kokoszka Piotr. Estimation in functional lagged regression. Journal of Time Series Analysis 36.4 (2015): 541-561.
Hormann Siegfried and Kidzinski Lukasz. A note on estimation in Hilbertian linear models. Scandinavian journal of statistics 42.1 (2015): 43-62.
Frequency-wise product of freqdom objects
Description
Frequency-wise product of freqdom objects
Usage
A %*% B
Frequency-wise sum of freqdom objects
Description
Frequency-wise sum of freqdom objects
Usage
## S3 method for class 'freqdom'
e1 + e2
Time-wise sum of freqdom objects
Description
Time-wise sum of freqdom objects
Usage
## S3 method for class 'timedom'
e1 + e2
Frequency-wise difference of freqdom objects
Description
Frequency-wise difference of freqdom objects
Usage
## S3 method for class 'freqdom'
e1 - e2
Time-wise difference of freqdom objects
Description
Time-wise sum of freqdom objects
Usage
## S3 method for class 'timedom'
e1 - e2
Estimate cross-covariances of two stationary multivariate time series
Description
This function computes the empirical cross-covariance of two stationary multivariate time series. If only one time series is provided it determines the empirical autocovariance function.
Usage
cov.structure(X, Y = X, lags = 0)
Arguments
X |
vector or matrix. If matrix, then each row corresponds to a timepoint of a vector time series. |
Y |
vector or matrix. If matrix, then each row corresponds to a timepoint of a vector time series. |
lags |
an integer-valued vector |
Details
Let [X_1,\ldots, X_T]^\prime
be a T\times d_1
matrix and
[Y_1,\ldots, Y_T]^\prime
be a T\times d_2
matrix. We stack the vectors and
assume that (X_t^\prime,Y_t^\prime)^\prime
is a stationary multivariate time series
of dimension d_1+d_2
. This function determines empirical lagged covariances between
the series (X_t)
and (Y_t)
. More precisely it determines
\widehat{C}^{XY}(h)
for h\in
lags,
where \widehat{C}^{XY}(h)
is the empirical version of \mathrm{Cov}(X_h,Y_0)
.
For a sample of size T
we set \hat\mu^X=\frac{1}{T}\sum_{t=1}^T X_t
and \hat\mu^Y=\frac{1}{T}\sum_{t=1}^T Y_t
and
\hat C^{XY}(h) = \frac{1}{T}\sum_{t=1}^{T-h} (X_{t+h} - \hat\mu^X)(Y_{t} - \hat\mu^Y)'
and for h < 0
\hat C^{XY}(h) = \frac{1}{T}\sum_{t=|h|+1}^{T} (X_{t+h} - \hat\mu^X)(Y_{t} - \hat\mu^Y)'.
Value
An object of class timedom
. The list contains
-
operators
\quad
an array. Element[,,k]
contains the covariance matrix related to lag\ell_k
. -
lags
\quad
returns the lags vector from the arguments.
Compute Dynamic Principal Components and dynamic Karhunen Loeve extepansion
Description
Dynamic principal component analysis (DPCA) decomposes multivariate time series into uncorrelated components. Compared to classical principal components, DPCA decomposition outputs components which are uncorrelated in time, allowing simpler modeling of the processes and maximizing long run variance of the projection.
Usage
dpca(X, q = 30, freq = (-1000:1000/1000) * pi, Ndpc = dim(X)[2])
Arguments
X |
a vector time series given as a |
q |
window size for the kernel estimator, i.e. a positive integer. |
freq |
a vector containing frequencies in |
Ndpc |
is the number of principal component filters to compute as in |
Details
This convenience function applies the DPCA methodology and returns filters (dpca.filters
), scores
(dpca.scores
), the spectral density (spectral.density
), variances (dpca.var
) and
Karhunen-Leove expansion (dpca.KLexpansion
).
See the example for understanding usage, and help pages for details on individual functions.
Value
A list containing
-
scores
\quad
DPCA scores (dpca.scores
) -
filters
\quad
DPCA filters (dpca.filters
) -
spec.density
\quad
spectral density ofX
(spectral.density
) -
var
\quad
amount of variance explained by dynamic principal components (dpca.var
) -
Xhat
\quad
Karhunen-Loeve expansion usingNdpc
dynamic principal components (dpca.KLexpansion
)
References
Hormann, S., Kidzinski, L., and Hallin, M. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Brillinger, D. Time Series (2001), SIAM, San Francisco.
Shumway, R., and Stoffer, D. Time series analysis and its applications: with R examples (2010), Springer Science & Business Media
Examples
X = rar(100,3)
# Compute DPCA with only one component
res.dpca = dpca(X, q = 5, Ndpc = 1)
# Compute PCA with only one component
res.pca = prcomp(X, center = TRUE)
res.pca$x[,-1] = 0
# Reconstruct the data
var.dpca = (1 - sum( (res.dpca$Xhat - X)**2 ) / sum(X**2))*100
var.pca = (1 - sum( (res.pca$x %*% t(res.pca$rotation) - X)**2 ) / sum(X**2))*100
cat("Variance explained by DPCA:\t",var.dpca,"%\n")
cat("Variance explained by PCA:\t",var.pca,"%\n")
Dynamic KL expansion
Description
Computes the dynamic Karhunen-Loeve expansion of a vector time series up to a given order.
Usage
dpca.KLexpansion(X, dpcs)
Arguments
X |
a vector time series given as a |
dpcs |
an object of class |
Details
We obtain the dynamic Karhnunen-Loeve expansion of order L
, 1\leq L\leq d
. It is defined as
\sum_{\ell=1}^L\sum_{k\in\mathbf{Z}} Y_{\ell, t+k} \phi_{\ell k},
where \phi_{\ell k}
are the dynamic PC filters as explained in dpca.filters
and Y_{\ell k}
are dynamic scores as explained in dpca.scores
. For the sample version the sum in k
extends over the range of lags for which the \phi_{\ell k}
are defined.
For more details we refer to Chapter 9 in Brillinger (2001), Chapter 7.8 in Shumway and Stoffer (2006) and to Hormann et al. (2015).
Value
A (T\times d)
-matix. The \ell
-th column contains the \ell
-th data point.
References
Hormann, S., Kidzinski, L., and Hallin, M. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Brillinger, D. Time Series (2001), SIAM, San Francisco.
Shumway, R.H., and Stoffer, D.S. Time Series Analysis and Its Applications (2006), Springer, New York.
See Also
dpca.filters
, filter.process
, dpca.scores
Compute DPCA filter coefficients
Description
For a given spectral density matrix dynamic principal component filter sequences are computed.
Usage
dpca.filters(F, Ndpc = dim(F$operators)[1], q = 30)
Arguments
F |
|
Ndpc |
an integer |
q |
a non-negative integer. DPCA filter coefficients at lags |
Details
Dynamic principal components are linear filters (\phi_{\ell k}\colon k\in \mathbf{Z})
,
1 \leq \ell \leq d
. They are defined as the Fourier coefficients of the dynamic eigenvector
\varphi_\ell(\omega)
of a spectral density matrix \mathcal{F}_\omega
:
\phi_{\ell k}:=\frac{1}{2\pi}\int_{-\pi}^\pi \varphi_\ell(\omega) \exp(-ik\omega) d\omega.
The index \ell
is referring to the \ell
-th #'largest dynamic eigenvalue. Since the \phi_{\ell k}
are
real, we have
\phi_{\ell k}^\prime=\phi_{\ell k}^*=\frac{1}{2\pi}\int_{-\pi}^\pi \varphi_\ell^* \exp(ik\omega)d\omega.
For a given
spectral density (provided as on object of class freqdom
) the function
dpca.filters()
computes (\phi_{\ell k})
for |k| \leq
q
and 1 \leq \ell \leq
Ndpc
.
For more details we refer to Chapter 9 in Brillinger (2001), Chapter 7.8 in Shumway and Stoffer (2006) and to Hormann et al. (2015).
Value
An object of class timedom
. The list has the following components:
-
operators
\quad
an array. Each matrix in this array has dimensionNdpc
\times d
and is assigned to a certain lag. For a given lagk
, the rows of the matrix correpsond to\phi_{\ell k}
. -
lags
\quad
a vector with the lags of the filter coefficients.
References
Hormann, S., Kidzinski, L., and Hallin, M. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Brillinger, D. Time Series (2001), SIAM, San Francisco.
Shumway, R.H., and Stoffer, D.S. Time Series Analysis and Its Applications (2006), Springer, New York.
See Also
dpca.var
, dpca.scores
, dpca.KLexpansion
Obtain dynamic principal components scores
Description
Computes dynamic principal component score vectors of a vector time series.
Usage
dpca.scores(X, dpcs = dpca.filters(spectral.density(X)))
Arguments
X |
a vector time series given as a |
dpcs |
an object of class |
Details
The \ell
-th dynamic principal components score sequence is defined by
Y_{\ell t}:=\sum_{k\in\mathbf{Z}} \phi_{\ell k}^\prime X_{t-k},\quad 1\leq \ell\leq d,
where \phi_{\ell k}
are the dynamic PC filters as explained in dpca.filters
. For the sample version the sum extends
over the range of lags for which the \phi_{\ell k}
are defined. The actual operation carried out is filter.process(X, A = dpcs)
.
We for more details we refer to Chapter 9 in Brillinger (2001), Chapter 7.8 in Shumway and Stoffer (2006) and to Hormann et al. (2015).
Value
A T\times
Ndpc
-matix with Ndpc = dim(dpcs$operators)[1]
. The \ell
-th column contains the
\ell
-th dynamic principal component score sequence.
References
Hormann, S., Kidzinski, L., and Hallin, M. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Brillinger, D. Time Series (2001), SIAM, San Francisco.
Shumway, R.H., and Stoffer, D.S. Time Series Analysis and Its Applications (2006), Springer, New York.
See Also
dpca.filters
, dpca.KLexpansion
, dpca.var
Proportion of variance explained
Description
Computes the proportion of variance explained by a given dynamic principal component.
Usage
dpca.var(F)
Arguments
F |
|
Details
Consider a spectral density matrix \mathcal{F}_\omega
and let \lambda_\ell(\omega)
by the
\ell
-th dynamic eigenvalue. The proportion of variance described by the \ell
-th dynamic
principal component is given as
v_\ell:=\int_{-\pi}^\pi \lambda_\ell(\omega)d\omega/\int_{-\pi}^\pi \mathrm{tr}(\mathcal{F}_\omega)d\omega.
This function numerically computes the vectors (v_\ell\colon 1\leq \ell\leq d)
.
For more details we refer to Chapter 9 in Brillinger (2001), Chapter 7.8 in Shumway and Stoffer (2006) and to Hormann et al. (2015).
Value
A d
-dimensional vector containing the v_\ell
.
References
Hormann, S., Kidzinski, L., and Hallin, M. Dynamic functional principal components. Journal of the Royal Statistical Society: Series B (Statistical Methodology) 77.2 (2015): 319-348.
Brillinger, D. Time Series (2001), SIAM, San Francisco.
Shumway, R.H., and Stoffer, D.S. Time Series Analysis and Its Applications (2006), Springer, New York.
See Also
dpca.filters
, dpca.KLexpansion
, dpca.scores
Convolute (filter) a multivariate time series using a time-domain filter
Description
This function applies a linear filter to some vector time series.
Usage
filter.process(X, A)
X %c% A
Arguments
X |
vector time series given in matrix form. Each row corresponds to a timepoint. |
A |
an object of class |
Details
Let [X_1,\ldots, X_T]^\prime
be a T\times d
matrix corresponding to a vector series X_1,\ldots,X_T
. This time series is transformed to the series Y_1,\ldots, Y_T
, where
Y_t=\sum_{k=-q}^p A_k X_{t-k},\quad t\in\{p+1,\ldots, T-q\}.
The index k
of A_k
is determined by the lags defined for the time domain object.
When index t-k
falls outside the domain \{1,\ldots, T\}
we set X_t=\frac{1}{T}\sum_{k=1}^T X_k
.
Value
A matrix. Row t
corresponds to Y_t
.
Functions
-
filter.process()
: Multivariate convolution (filter) in the time domain -
X %c% A
: Convenience operator forfilter.process
function
See Also
Coefficients of a discrete Fourier transform
Description
Computes Fourier coefficients of some functional represented by an object of class freqdom
.
Usage
fourier.inverse(F, lags = 0)
Arguments
F |
an object of class |
lags |
lags of the Fourier coefficients to be computed. |
Details
Consider a function F \colon [-\pi,\pi]\to\mathbf{C}^{d_1\times d_2}
. Its k
-th Fourier
coefficient is given as
\frac{1}{2\pi}\int_{-\pi}^\pi F(\omega) \exp(ik\omega)d\omega.
We represent the function F
by an object of class freqdom
and approximate the integral via
\frac{1}{|F\$freq|}\sum_{\omega\in {F\$freq}} F(\omega) \exp(i k\omega),
for k\in
lags.
Value
An object of class timedom
. The list has the following components:
-
operators
\quad
an array. Thek
-th matrix in this array corresponds to thek
-th Fourier coefficient. -
lags
\quad
the lags of the corresponding Fourier coefficients.
See Also
Examples
Y = rar(100)
grid = c(pi*(1:2000) / 1000 - pi) #a dense grid on -pi, pi
fourier.inverse(spectral.density(Y, q=2, freq=grid))
# compare this to
cov.structure(Y)
Computes the Fourier transformation of a filter given as timedom
object
Description
Computes the frequency response function of a linear filter and returns it as a freqdom
object.
Usage
fourier.transform(A, freq = pi * -100:100/100)
Arguments
A |
an object of class |
freq |
a vector of frequencies |
Details
Consider a filter (a sequence of vectors or matrices) (A_k)_{k\in A\$lags}
. Then this function computes
\sum_{k\in A\$lags} A_k e^{-ik\omega}
for all frequencies \omega
listed in the vector freq
.
Value
An object of class freqdom
.
See Also
Examples
# We compute the discrete Fourier transform (DFT) of a time series X_1,..., X_T.
X = rar(100)
T=dim(X)[1]
tdX = timedom(X/sqrt(T),lags=1:T)
DFT = fourier.transform(tdX, freq= pi*-1000:1000/1000)
Create an object corresponding to a frequency domain functional
Description
Creates an object of class freqdom
. This object corresponds to a functional with domain [-\pi,\pi]
and some complex vector space as codomain.
Usage
freqdom(F, freq)
Arguments
F |
a vector, a matrix or an array. For vectors |
freq |
a vector of dimension |
Details
This class is used to describe a frequency domain functional (like a spectral density matrix, a discrete Fourier transform, an impulse response function, etc.)
on selected frequencies. Formally we consider a collection [F_1,\ldots,F_K]
of complex-valued matrices F_k
, all of which have the same dimension
d_1\times d_2
. Moreover, we consider frequencies \{\omega_1,\ldots, \omega_K\}\subset[-\pi,\pi]
. The object this function creates corresponds
to the mapping f: \mathrm{freq}\to \mathbf{C}^{d_1\times d_2}
, where \omega_k\mapsto F_k
.
Consider, for example, the discrete Fourier transform of a vector time series X_1,\ldots, X_T
:. It is defined as
D_T(\omega)=\frac{1}{\sqrt{T}}\sum_{t=1}^T X_t e^{-it\omega},\quad \omega\in[-\pi,\pi].
We may choose \omega_k=2\pi k/K-\pi
and F_k=D_T(\omega_k)
. Then, the object freqdom
creates, is corresponding to the function which associates \omega_k
and D_T(\omega_k)
.
Value
Returns an object of class freqdom
. An object of class freqdom
is a list containing the following components:
-
operators
\quad
the arrayF
as given in the argument. -
freq
\quad
the vectorfreq
as given in the argument.
See Also
Examples
i = complex(imaginary=1)
OP = array(0, c(2, 2, 3))
OP[,,1] = diag(2) * exp(i)/2
OP[,,2] = diag(2)
OP[,,3] = diag(2) * exp(-i)/2
freq = c(-pi/3, 0, pi/3)
A = freqdom(OP, freq)
Eigendecompose a frequency domain operator at each frequency
Description
Gives the eigendecomposition of objects of class freqdom
.
Usage
freqdom.eigen(F)
Arguments
F |
an object of class freqdom. The matrices |
Details
This function makes an eigendecomposition for each of the matrices F\$operator[,,k]
.
Value
Returns a list. The list is containing the following components:
-
vectors
\quad
an array containingd
matrices. Thei
-th matrix contains in itsk
-th row the conjugate transpose eigenvector belonging to thek
-th largest eigenvalue ofF\$operator[,,i]
. -
values
\quad
matrix containing ink
-th column the eigenvalues ofF\$operator[,,k]
. -
freq
\quad
vector of frequencies defining the objectF
.
See Also
Compute a matrix product of two frequency-domain operators
Description
For given frequency-domain operators F
and G
(freqdom
) the function freqdom.kronecker
computes their matrix product frequency-wise.
Usage
freqdom.product(F, G)
Arguments
F |
frequency-domain filter of type |
G |
frequency-domain filter of type |
Details
Let F = \{ F_\theta : \theta \in S \}
, G = \{ G_\theta : \theta \in S \}
,
where S
is a finite grid of frequencies in [-\pi,\pi]
, F_\theta \in \mathbf{C}^{p \times q}
and G_\theta \in \mathbf{C}^{q \times r}
.
We define
H_\theta = F_\theta G_\theta
as a matrix product of F_\theta
and G_\theta
, i.e. H_\theta \in \mathbf{R}^{p\times r}
.
Function freqdom.product
returns H = \{ H_\theta : \theta \in S \}
.
Value
Function returns a frequency domain object (freqdom
) of dimensions L \times p \times r
, where L
is the
size of the evaluation grid. The elements correspond to F_\theta * G_\theta
defined above.
Functions
-
freqdom.product()
: Frequency-wise matrix product of two frequency-domain operators
Examples
n = 100
X = rar(n)
Y = rar(n)
SX = spectral.density(X)
SY = spectral.density(Y)
R = freqdom.product(SY,SX)
Compute a transpose of a given frequency-domain operator at each frequency
Description
For a given frequency-domain operator S
(freqdom
) the function freqdom.transpose
computes the transpose of S_\theta'
at
each frequency from the evaluation grid.
Usage
freqdom.transpose(x)
Arguments
x |
a frequency-domain filter of type |
Details
Let S = \{ S_\theta : \theta \in G \}
, where G
is some finite grid
of frequencies in [-\pi,\pi]
and S_\theta \in \mathbf{C}^{p \times p}
.
At each frequency \theta \in G
function freqdom.transpose
transposes
Resulting object is defined as
S' = \{ S_\theta': \theta \in G \}.
Value
Function returns a frequency domain object (freqdom
) of dimensions L \times p_2 \times p_1
, where L
is the size of the grid.
The elements of the object correspond to S_\theta'
as defined above.
Checks if an object belongs to the class freqdom
Description
Checks if an object belongs to the class freqdom
.
Usage
is.freqdom(X)
Arguments
X |
some object |
Value
TRUE
if X
is of type freqdom
, FALSE
otherwise
See Also
Checks if an object belongs to the class timedom
Description
Checks if an object belongs to the class timedom
.
Usage
is.timedom(X)
Arguments
X |
some object |
Value
TRUE
if X
is of type timedom
, FALSE
otherwise
See Also
Frequency-wise sum of freqdom objects
Description
Frequency-wise sum of freqdom objects
Usage
plus.freqdom(e1, e2)
Print freqdom object
Description
Print freqdom object
Usage
## S3 method for class 'freqdom'
print(x, ...)
Print timedom object
Description
Print timedom object
Usage
## S3 method for class 'timedom'
print(x, ...)
Simulate a multivariate autoregressive time series
Description
Generates a zero mean vector autoregressive process of a given order.
Usage
rar(
n,
d = 2,
Psi = NULL,
burnin = 10,
noise = c("mnormal", "mt"),
sigma = NULL,
df = 4
)
Arguments
n |
number of observations to generate. |
d |
dimension of the time series. |
Psi |
array of |
burnin |
an integer |
noise |
|
sigma |
covariance or scale matrix of the innovations. By default the identity matrix. |
df |
degrees of freedom if |
Details
We simulate a vector autoregressive process
X_t=\sum_{k=1}^p \Psi_k X_{t-k}+\varepsilon_t,\quad 1\leq t\leq n.
The innovation process \varepsilon_t
is either multivariate normal or multivariate
t
with a predefined covariance/scale matrix sigma and zero mean. The noise is generated
with the package mvtnorm
. For Gaussian noise we use rmvnorm
. For Student-t noise
we use rmvt
. The parameters sigma and df are imported as arguments, otherwise we use default
settings. To initialise the process we set
[X_{1-p},\ldots,X_{0}]=[\varepsilon_{1-p},\ldots,\varepsilon_{0}]
. When burnin
is set
equal to K
then, n+K
observations are generated and the first K
will be trashed.
Value
A matrix with d
columns and n
rows. Each row corresponds to one time point.
See Also
Invert order of lags or grid parameters of a timedom
or freqdom
object, respectively
Description
For a given
freqdom
objectx
, the functionrev
reverts the order of the evaluation grid.
Usage
## S3 method for class 'freqdom'
rev(x)
Arguments
x |
an object of class |
Value
Returns object of same class as x
.
rev Reverts order of lags in an object of class timedom
Description
For a given
timedom
objectx
, the functionrev
reverts the order of lags.
Usage
## S3 method for class 'timedom'
rev(x)
Moving average process
Description
Generates a zero mean vector moving average process.
Usage
rma(n, d = 2, Psi = NULL, noise = c("mnormal", "mt"), sigma = NULL, df = 4)
Arguments
n |
number of observations to generate. |
d |
dimension of the time series. |
Psi |
a |
noise |
|
sigma |
covariance or scale matrix of the innovations. If NULL then the identity matrix is used. |
df |
degrees of freedom if |
Details
This simulates a vector moving average process
X_t=\varepsilon_t+\sum_{k \in lags} \Psi_k \varepsilon_{t-k},\quad 1\leq t\leq n.
The innovation process \varepsilon_t
is either multivariate normal or multivarite t
with
a predefined covariance/scale matrix sigma and zero mean. The noise is generated with the
package mvtnorm
. For Gaussian noise we use rmvnorm
. For Student-t noise we use
rmvt
. The parameters sigma
and df
are imported as arguments, otherwise we use default settings.
Value
A matrix with d
columns and n
rows. Each row corresponds to one time point.
See Also
Compute empirical spectral density
Description
Estimates the spectral density and cross spectral density of vector time series.
Usage
spectral.density(
X,
Y = X,
freq = (-1000:1000/1000) * pi,
q = max(1, floor(dim(X)[1]^(1/3))),
weights = c("Bartlett", "trunc", "Tukey", "Parzen", "Bohman", "Daniell",
"ParzenCogburnDavis")
)
Arguments
X |
a vector or a vector time series given in matrix form. Each row corresponds to a timepoint. |
Y |
a vector or vector time series given in matrix form. Each row corresponds to a timepoint. |
freq |
a vector containing frequencies in |
q |
window size for the kernel estimator, i.e. a positive integer. |
weights |
kernel used in the spectral smoothing. By default the Bartlett kernel is chosen. |
Details
Let [X_1,\ldots, X_T]^\prime
be a T\times d_1
matrix and [Y_1,\ldots, Y_T]^\prime
be a T\times d_2
matrix. We stack the vectors and assume that (X_t^\prime,Y_t^\prime)^\prime
is a stationary multivariate time series of dimension d_1+d_2
. The cross-spectral density between the two time series (X_t)
and (Y_t)
is defined as
\sum_{h\in\mathbf{Z}} \mathrm{Cov}(X_h,Y_0) e^{-ih\omega}.
The function spectral.density
determines the empirical cross-spectral density between the two time series (X_t)
and (Y_t)
. The estimator is of form
\widehat{\mathcal{F}}^{XY}(\omega)=\sum_{|h|\leq q} w(|k|/q)\widehat{C}^{XY}(h)e^{-ih\omega},
with \widehat{C}^{XY}(h)
defined in cov.structure
Here w
is a kernel of the specified type and q
is the window size. By default the Bartlett kernel w(x)=1-|x|
is used.
See, e.g., Chapter 10 and 11 in Brockwell and Davis (1991) for details.
Value
Returns an object of class freqdom
. The list is containing the following components:
-
operators
\quad
an array. Thek
-th matrix in this array corresponds to the spectral density matrix evaluated at thek
-th frequency listed infreq
. -
freq
\quad
returns argument vectorfreq
.
References
Peter J. Brockwell and Richard A. Davis Time Series: Theory and Methods Springer Series in Statistics, 2009
Print object summary
Description
Print object summary
Usage
## S3 method for class 'freqdom'
summary(object, ...)
Print object summary
Description
Print object summary
Usage
## S3 method for class 'timedom'
summary(object, ...)
Defines a linear filter
Description
Creates an object of class timedom
. This object corresponds to a multivariate linear filter.
Usage
timedom(A, lags)
Arguments
A |
a vector, matrix or array. If array, the elements |
lags |
a vector of increasing integers. It corresponds to the time lags of the filter. |
Details
This class is used to describe a linear filter, i.e. a sequence of matrices, each of which correspond to a certain lag. Filters can, for example, be used to transform a sequence (X_t)
into a new sequence (Y_t)
by defining
Y_t=\sum_k A_kX_{t-k}.
See filter.process()
.
Formally we consider a collection [A_1,\ldots,A_K]
of complex-valued matrices A_k
, all of which have the same dimension d_1\times d_2
. Moreover, we consider lags \ell_1<\ell_2<\cdots<\ell_K
. The object this function creates corresponds to the mapping f: \mathrm{lags}\to \mathbf{R}^{d_1\times d_2}
, where \ell_k\mapsto A_k
.
Value
Returns an object of class timedom
. An object of class timedom
is a list containing the following components:
-
operators
\quad
returns the arrayA
as given in the argument. -
lags
\quad
returns the vectorlags
as given in the argument.
See Also
Examples
# In this example we apply the difference operator: Delta X_t= X_t-X_{t-1} to a time series
X = rar(20)
OP = array(0,c(2,2,2))
OP[,,1] = diag(2)
OP[,,2] = -diag(2)
A = timedom(OP, lags = c(0,1))
filter.process(X, A)
Compute operator norms of elements of a filter
Description
This function determines the norms of the matrices defining some linear filter.
Usage
timedom.norms(A, type = "2")
Arguments
A |
an object of class |
type |
matrix norm to be used as in |
Details
Computes \|A_h\|
for h
in the set of lags belonging to the object A. When type
is 2
then \|A\|
is the spectral radius of A
. When type is F
then \|A\|
is the Frobenius norm (or the Hilbert-Schmidt norm, or Schatten 2-norm) of
A
. Same options as for the function norm
as in base package.
Value
A list which contains the following components:
-
lags
\quad
a vector containing the lags ofA
. -
norms
\quad
a vector containing the norms of the matrices definingA
.
Examples
d = 2
A = array(0,c(d,d,2))
A[1,,] = 2 * diag(d:1)/d
A[2,,] = 1.5 * diag(d:1)/d
OP = timedom(A,c(-2,1))
timedom.norms(OP)
Choose lags of an object of class timedom
Description
This function removes lags from a linear filter.
Usage
timedom.trunc(A, lags)
Arguments
A |
an object of class |
lags |
a vector which contains a set of lags. These lags must be a subset of the lags defined for timedom object A. Only those lags will be kept, the other lags are removed. |
Value
An object of class timedom
.