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 |
Fast and efficient computation of rolling and expanding eigenanalysis for time-series data.
rolleigen
is a package that provides fast and efficient computation of rolling and expanding eigenanalysis for time-series data.
Jason Foster
A function for computing the rolling and expanding eigenvalues and eigenvectors of time-series data.
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)
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)
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 |
scale |
logical. If |
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 |
complete_obs |
logical. If |
na_restore |
logical. Should missing values be restored? |
online |
logical. Process observations using an online algorithm. |
A list containing the following components:
values |
An object of the same class and dimension as |
vectors |
A cube with each slice the rolling and expanding eigenvectors. |
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)
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)
A function for computing the rolling and expanding principal component regressions of time-series data.
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)
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)
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 |
center |
logical. If |
scale |
logical. If |
min_obs |
integer. Minimum number of observations required to have a value within a window,
otherwise result is |
complete_obs |
logical. If |
na_restore |
logical. Should missing values be restored? |
online |
logical. Process observations using an online algorithm. |
A list containing the following components:
coefficients |
A list of objects with the rolling and expanding coefficients for each |
r.squared |
A list of objects with the rolling and expanding r-squareds for each |
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)
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)