I hope I understand you correctly, but here is a small edit to your function:
rolling.regression <- function(series) { mod <- dynlm(formula = y ~ L(y) + L(x), data = as.zoo(series))
To see how this works, do a little regression example:
x <- rnorm(1000); y <- 2*x + rnorm(1000) reg <- lm(y ~ x) summary(reg)$coef Estimate Std. Error t value Pr(>|t|) (Intercept) 0.02694322 0.03035502 0.8876033 0.374968 x 1.97572544 0.03177346 62.1816310 0.000000
As you can see, calling summary first and then getting its coefficients ( coef(summary(reg)) ) gives you a table with estimates, standard errors and t-values. Thus, the ratings are stored in column 1 of this table, the t-values ββin column 3. And that I get them in the updated rolling.regression function.
EDIT
I updated my solution; it now also contains adjusted R2. If you just want a normal R2, get rid of .adj .
EDIT 2
Quick and dirty hack, what to call columns:
rolling.regression <- function(series) { mod <- dynlm(formula = y ~ L(y) + L(x), data = as.zoo(series))
source share