n_vars <- 10
n_obs <- 1000
x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars)
y <- matrix(rnorm(n_obs), nrow = n_obs, ncol = 1)
# 252-day rolling regression
result <- roll_lm(x, y, 252)
# Equivalent to 'na.rm = TRUE'
result <- roll_lm(x, y, 252, min_obs = 1)
# Expanding window
result <- roll_lm(x, y, n_obs, min_obs = 1)
# Exponential decay
weights <- 0.9 ^ (251:0)
result <- roll_lm(x, y, 252, weights, min_obs = 1)
Run the code above in your browser using DataLab