[R] stl outlier help request
rkevinburton at charter.net
rkevinburton at charter.net
Mon Oct 13 23:34:58 CEST 2008
Currently I find that if I call stl() repeatedly I can use the weights array that is part of the stil output to detect outliers. I also find that if I repeatedly call stl() (replacing the outliers after each call) that the "remainder" portion of the stil output gets reduced. I am calling it like:
for(.index in 1:4)
{
st <- stl(mt, s.window=frequency(mt), robust=TRUE)
outliers <- which(st $ weights < 1e-8)
if(length(outliers) > 0)
{
# Replace the outliers with the season + trend
mt[outliers] <- st$time.series[,"seasonal"][outliers] + st$time.series[,"trend"][outliers]
}
}
My question is, "is there a better way?". One improvement would be to use the square of the remainder as a stopping criteria rather than a hard-coded loop. Not being familiar with the arguments to stl (inner, outer, etc.) and their bearing on the wieghts I don't know if there is a better way by simply specifying these arguments. So far increasing these arguments above the default values does not seem to reduce the remainder or weights array. I realize that I could look at the source but before I do I would like to request some comments from those who have used this function probably more than I.
Thank you.
Kevin
More information about the R-help
mailing list