I have data spanning over 17 years, and I would like to make a time series at the year level with ts()
. It works very fine for 1,3 and 6 month intervals, but when I try per year I get an error.
Here is my example:
date <- c("2000-01-01", "2001-01-01", "2002-01-01", "2003-01-01", "2004-01-01", "2005-01-01", "2006-01-01", "2007-01-01", "2008-01-01", "2009-01-01", "2010-01-01", "2011-01-01", "2012-01-01", "2013-01-01", "2014-01-01", "2015-01-01", "2016-01-01")
var <- c(1:17)
df <- data.frame(as.Date(date), var)
ts_df <- ts(df$var,start=c(2000,1),frequency=1)
stl_df <- stl(ts_df, s.window = "periodic")
Is there a way around this problem?
I've read that for months you need a minimum of 24 months to model it. Should I have the same minimum amount of values for years too? I'm open to using other tools too if they help solve this...
My goal ultimate goal is to use:
autoplot(cbind(Data=ts_df,Seasonal=seasonal(stl_df),
Trend=trendcycle(stl_df)),
facets=TRUE)
date <- c("2000-01-01", "2001-01-01", "2002-01-01", "2003-01-01", "2004-01-01", "2005-01-01", "2006-01-01", "2007-01-01", "2008-01-01", "2009-01-01", "2010-01-01", "2011-01-01", "2012-01-01", "2013-01-01", "2014-01-01", "2015-01-01", "2016-01-01")
var <- c(1:17)
df <- data.frame(as.Date(date), var)
ts_df <- ts(df$var,start=c(2000,1),frequency=1)
stl_df <- stl(ts_df, s.window = "periodic")