[R] stats::decompose - Problem finding seasonal component without trend
Mike HC
michael at cassin.name
Wed Jul 8 13:31:04 CEST 2009
Hi R-help,
I'd like to extract the seasonal component of a short timeseries, and was
hoping to use stats::decompose. I don't want to decompose the 'trend'
component so I thought I should call decompose(x,filter=0). I think I've
either misunderstood the filter argument or come upon a bug/feature in
decompose.
# EXAMPLE
x<-ts(c(2:12,rep(1,12),1:12),start=c(2009,2),frequency=12);x # Starts in
Feb
# Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#2009 2 3 4 5 6 7 8 9 10 11 12
#2010 1 1 1 1 1 1 1 1 1 1 1 1
#2011 1 2 3 4 5 6 7 8 9 10 11 12
decompose(x) #ok, got some answer for seasonal component, but I don't want
to split the residual into trend and random.
decompose(x,filter=0) #this seems broken, ignoring some of the data in
seasonal calculation, and losing some points in the random component
# END EXAMPLE
I've debug-stepped through decompose and, as far as I can understand the
manipulation, it appears to ignore the first and last period. And only the
middle 12 points (all 1 in my example) are used in the calculation of the
seasonal averages. Unrelated, but it also seems to duplicate one value
during the calculation, and throw a warning due to a seemingly unnecessary
'end' argument to window.
I can probably get away with using some function like sweep or scale
instead, but please let me know if I'm just misusing decompose. If it's a
bug, I hope the above helps..
Regards,
Mike
P.S.
I see this comment in the R 2.8.0 release notes:
o HoltWinters() and decompose() use a (statistically) more
efficient computation for seasonal fits (they used to waste
one period).
I'm on R 2.80:
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 8.0
year 2008
month 10
day 20
svn rev 46754
language R
version.string R version 2.8.0 (2008-10-20)
--
View this message in context: http://www.nabble.com/stats%3A%3Adecompose----Problem-finding-seasonal-component-without-trend-tp24389771p24389771.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list