the problem is the error in the S3 method for class ar . predict.ar try evaluating the newdata parameter with the ar object. Display first lines getS3method('predict','ar')
function (object, newdata, n.ahead = 1L, se.fit = TRUE, ...) { if (n.ahead < 1L) stop("'n.ahead' must be at least 1") if (missing(newdata)) { newdata <- eval.parent(parse(text = object$series)) if (!is.null(nas <- object$call$na.action)) newdata <- eval.parent(call(nas, newdata)) } ..... }
Relevant / Listened String:
newdata <- eval.parent(parse(text = object$series))
But the $ series object does not have the correct expression / character. since it is hidden by a new level of arf wrapper function. Here's a workaround is to set the correct expression for this term:
arf <- function(dat, ...) { object <- ar(dat, order.max=1, method="ols") object$series <- as.character(as.expression(as.list(match.call())$dat)) forecast(object,...) } arf( ts(1:100, start=c(2000,1), frequency=4)
Note that; this solution also works with:
aa <- ts(1:100, start=c(2000,1), frequency=4) arf(aa)
source share