When trying to compose a function from smaller ones using Rob Hyndman's forecast library, like so:
> library('forecast')
> arf <- function(data, ...) forecast(ar(data, order.max=1, method="ols"), ...)
I get an error when trying to plug in some data:
> arf(ts(1:100, start=c(2000,1), frequency=4))
Error in ts(x, frequency = 1, start = 1) : object is not a matrix
However, using the body of arf directly works perfectly:
> forecast(ar(ts(1:100, start=c(2000,1), frequency=4), order.max=1,method="ols"))
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2025 Q1 101 101 101 101 101
2025 Q2 102 102 102 102 102
2025 Q3 103 103 103 103 103
2025 Q4 104 104 104 104 104
2026 Q1 105 105 105 105 105
2026 Q2 106 106 106 106 106
2026 Q3 107 107 107 107 107
2026 Q4 108 108 108 108 108
2027 Q1 109 109 109 109 109
2027 Q2 110 110 110 110 110
Why does arf not work as it should?
forecast.armethod as I was able to run this withforecast.Arimamethod while replacingarwithauto.arima. Let's wait for @RobHyndman - David Arenburg