On Tue, 25 Sep 2007, Martin Efferz wrote:
> Is there a function which does a rolling calcualtion with 2 input vectors.
> "rollapply" and "rollFun" seem to use only one input
vector.
In rollapply(), you need to set by.column=FALSE, e.g.
## generate random series of "true" and "predicted" values
set.seed(1071)
z <- zoo(cbind(true = rep(0, 100), pred = rnorm(100)))
## rolling evaluation of RMSE
rmse <- rollapply(z, 20, function(x) sqrt(mean((x[,1] - x[,2])^2)),
by.column = FALSE)
## visualization
plot(merge(z, rmse), screens = c(1, 1, 2), col = c(2, 1, 1),
main = "", ylab = c("true/pred", "rmse"))
See also the rolling regression example on the rollapply man page.
hth,
Z
>
>
> I want to calcualte some prediction evaluation measures like MSE and MAE
> with a rolling window. My functions look like
>
>
>
> prediction.mse(pred,true)
>
> prediction.mae(pred,true)
>
> ...
>
>
>
> pred and true are two vectors of equal size, the predictions and the
> realizations.
>
>
>
> Any ideas?
>
>
>
> Best,
>
> Martin
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>