Package 'rolleigen'

Title: Rolling Eigenanalysis
Description: Fast and efficient computation of rolling and expanding eigenanalysis for time-series data.
Authors: Jason Foster
Maintainer: Jason Foster <[email protected]>
License: GPL (>= 2)
Version: 1.0
Built: 2024-08-19 05:18:10 UTC
Source: https://github.com/jasonjfoster/rolleigen

Help Index


Rolling Eigenanalysis

Description

Fast and efficient computation of rolling and expanding eigenanalysis for time-series data.

Details

rolleigen is a package that provides fast and efficient computation of rolling and expanding eigenanalysis for time-series data.

Author(s)

Jason Foster


Rolling Eigenvalues and Eigenvectors

Description

A function for computing the rolling and expanding eigenvalues and eigenvectors of time-series data.

Usage

roll_eigen(x, width, weights = rep(1, width), center = TRUE,
  scale = FALSE, order = TRUE, min_obs = width, complete_obs = TRUE,
  na_restore = FALSE, online = TRUE)

Arguments

x

vector or matrix. Rows are observations and columns are variables.

width

integer. Window size.

weights

vector. Weights for each observation within a window.

center

logical. If TRUE then the weighted mean of each variable is used, if FALSE then zero is used.

scale

logical. If TRUE then the weighted standard deviation of each variable is used, if FALSE then no scaling is done.

order

logical. Change sign and order of the components.

min_obs

integer. Minimum number of observations required to have a value within a window, otherwise result is NA.

complete_obs

logical. If TRUE then rows containing any missing values are removed, if FALSE then pairwise is used.

na_restore

logical. Should missing values be restored?

online

logical. Process observations using an online algorithm.

Value

A list containing the following components:

values

An object of the same class and dimension as x with the rolling and expanding eigenvalues.

vectors

A cube with each slice the rolling and expanding eigenvectors.

Examples

n <- 15
m <- 3
x <- matrix(rnorm(n * m), nrow = n, ncol = m)
weights <- 0.9 ^ (n:1)

# rolling eigenvalues and eigenvectors with complete windows
roll_eigen(x, width = 5)

# rolling eigenvalues and eigenvectors with partial windows
roll_eigen(x, width = 5, min_obs = 1)

# expanding eigenvalues and eigenvectors with partial windows
roll_eigen(x, width = n, min_obs = 1)

# expanding eigenvalues and eigenvectors with partial windows and weights
roll_eigen(x, width = n, min_obs = 1, weights = weights)

Rolling Principal Component Regressions

Description

A function for computing the rolling and expanding principal component regressions of time-series data.

Usage

roll_pcr(x, y, width, n_comps = ncol(x), weights = rep(1, width),
  intercept = TRUE, center = TRUE, scale = FALSE, min_obs = width,
  complete_obs = TRUE, na_restore = FALSE, online = TRUE)

Arguments

x

vector or matrix Rows are observations and columns are the independent variables.

y

vector or matrix. Rows are observations and columns are the dependent variables.

width

integer. Window size.

n_comps

integer. Number of principal components.

weights

vector. Weights for each observation within a window.

intercept

logical. Either TRUE to include or FALSE to remove the intercept.

center

logical. If TRUE then the weighted mean of each variable is used, if FALSE then zero is used.

scale

logical. If TRUE then the weighted standard deviation of each variable is used, if FALSE then no scaling is done.

min_obs

integer. Minimum number of observations required to have a value within a window, otherwise result is NA.

complete_obs

logical. If TRUE then rows containing any missing values are removed, if FALSE then pairwise is used.

na_restore

logical. Should missing values be restored?

online

logical. Process observations using an online algorithm.

Value

A list containing the following components:

coefficients

A list of objects with the rolling and expanding coefficients for each y. An object is the same class and dimension (with an added column for the intercept) as x.

r.squared

A list of objects with the rolling and expanding r-squareds for each y. An object is the same class as x.

Examples

n <- 15
m <- 3
x <- matrix(rnorm(n * m), nrow = n, ncol = m)
y <- rnorm(n)
weights <- 0.9 ^ (n:1)

# rolling regressions with complete windows
roll_pcr(x, y, width = 5, n_comps = 1)

# rolling regressions with partial windows
roll_pcr(x, y, width = 5, n_comps = 1, min_obs = 1)

# expanding regressions with partial windows
roll_pcr(x, y, width = n, n_comps = 1, min_obs = 1)

# expanding regressions with partial windows and weights
roll_pcr(x, y, width = n, n_comps = 1, min_obs = 1, weights = weights)