0

My current code is this:

Model <- head(rollapplyr(z, width = 131, function(x)
  fitted(lm(y ~x1+ x2, data = as.data.frame(x))), by.column = FALSE)[,131],3429)

I would like to do this:

fit1 <- lm(y ~x1+ x2)
Model <- head(rollapplyr(z, width = 131, function(x) fitted(fit1),
  data = as.data.frame(x))), by.column = FALSE)[,131],3429)

Basically, I'm just trying to sub in fit1 for the regression equation, but I keep getting an error. Any help would be much appreciated.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • Hi there! Please make your post reproducible by having a look at [**How to make a great reproducible example**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for us to help you. Thank you. – Arun Mar 26 '13 at 00:06
  • Also, please edit with the error you get. – Arun Mar 26 '13 at 00:06

1 Answers1

3

It is not clear what do you want to do , but you can factor out the formula like this:

form <- y ~ x1 + x2
FUN <- function(x) fitted(lm(form, data = as.data.frame(x)))
rollapplyr(z, 131, FUN, by.column = FALSE)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
agstudy
  • 119,832
  • 17
  • 199
  • 261