roll_regres.fit: Fitter Function for Rolling and Expanding Linear Models

View source: R/roll_regres.R

roll_regres.fitR Documentation

Fitter Function for Rolling and Expanding Linear Models

Description

Function with a few validations before calling C++ code.

Usage

roll_regres.fit(x, y, width, do_compute = character(), grp = NULL,
  do_downdates = TRUE, min_obs = NULL)

Arguments

x

design matrix of dimension n * p.

y

numeric vector of observations of length n.

width

integer with the width of the moving window. Only used if do_downdates == TRUE.

do_compute

character vector with elements "sigmas", "r.squareds", and/or "1_step_forecasts" for additional output to be computed. See "Details" in roll_regres.

grp

integer vector to be used if you e.g., want to run the regression over weekly blocks of data. See "Details" in roll_regres.

do_downdates

logical which is TRUE if you want a rolling window regressions. Otherwise, an expanding window is used.

min_obs

positive integer with minimum number of observation that are required in a window. Useful if there are gaps in grp or unequal number of observations for each grp.

Details

First, the dqrdc routine from LINPACK is used to form the QR decomposition for the first window of data using Householder transformations without pivoting. Then, the LINPACK dchud and dchdd routines are used to update and downdate the Cholesky decomposition (the R matrix in the QR decomposition).

Notice that unlike lm, there are no checks of the rank of the matrix.

Value

Same as roll_regres.

References

Golub, G. H., & Van Loan, C. F. (2013). Matrix computations (4rd ed.). JHU Press. See chapter 5 and section 6.5.

See Also

roll_regres for method similar to lm.

Examples

# simulate data
set.seed(9623556)
n <- 50
p <- 2
X <- cbind(1, matrix(rnorm(p * n), ncol = p))
y <- drop(X %*% c(1, -1, 1)) + rnorm(n)

# compute coefs
out <- roll_regres.fit(x = X, y = y, width = 45L)
tail(out$coefs)


rollRegres documentation built on May 5, 2022, 1:06 a.m.