Home > Mobile >  how to get residuals and perform the Durbin Watson test on Rolling Linear regression?
how to get residuals and perform the Durbin Watson test on Rolling Linear regression?

Time:03-06

i have run this below coded for which I got the result of coefficients and r2 values,

model <- roll_regres(y ~ x1   x2   x3   x4, Data, width = 15L, do_downdates = FALSE, do_compute = c("sigmas", "r.squareds"))

coef <- outneg$coefs

r2 <- outneg$r.squareds 

and what I need is to do the Durban-Watson test on residuals? the problem here is I am not able to extract the residuals from roll_regres. how do I get the residual values for rolling window regression?

CodePudding user response:

Do you mean the residuals of each of the expanding length window regression model? You can get them like this.

residuals = lapply(15:nrow(Data), function(x) {
  lm(y ~ x1   x2   x3   x4, data = Data[1:x,])$residuals
})
  •  Tags:  
  • r
  • Related