stats package in R has stl(), but it requires a uniformly spaced time series created by ts(). It can't deal with zoo objects.
Strangely, it can't deal with missing values either, although STL method claims to be able to fill in missing value with LOESS. (see this question on CV.)
So for example, if you have business day data, you can't just make it calendar day by putting NA on weekends and call stl().
I also see the author of Python statsmodel trying to migrate stl() to work with Pandas TimeSeries, but it doesn't seem to be there yet.
Thanks
Edit: Just to add that I know I can just do a very simple model like fitting harmonics, but I want a well-established model to at least provide benchmark. I have sub monthly data, so X12 is not applicable.
According to @Julius in this post is it possible to use
stl
withna.approx
, fromzoo
package, usingstl(x, na.action = na.approx, ...)
. This does some sort of interpolation.Unfortunately
stl
prefers regular time series.So I take @Julius approach to test how well
loess
performs in fillingNAs
assuming a irregular time series. Apparently the error is very small.Lets simulate
The following function takes the data and simulate scenarios with
3^(0:p)
NAs withnaapprox=TRUE
for usingna.approx
andoptspan=TRUE
to optimize span parameter. The loss function is MAPE.Less MAPE when using
na.approx
from zoo package and recommendedspan= 0.75
. After filling the NAs other modelling alternatives may be considered.