R time series modeling on weekly data using ts() object R time series modeling on weekly data using ts() object r r

R time series modeling on weekly data using ts() object


Using non-integer frequencies works quite well and is compatible with most models (auto.arima, ets, ...). For the start date, I just use the convenience functions in lubridate. The importance here is to be consistent when working with multiple time series of potentially different start and end dates.

library(lubridate)ts(df$Amount,    freq=365.25/7,    start=decimal_date(ymd("2006-12-27")))


First make sure that your data has exactly 52 data per year. To do that, identify the years with 53 data and remove the one which is the less important for your seasonality pattern (for instance do not remove a week in December if you want to check the Christmas sales seasonality (!)

Xts is a good format as it is more flexible, however all the decomposition and forecasting tools usually work with ts as they require a fix number of data per cycle.

regarding your question on the non complete years. it should not be an issue. R doesn't know when is january or december, hence a year can start and end anytime.


Concerning your 4th question, I think the error is because you have just one period data (52 weeks), and you may need another 52 weeks data to complete 2 periods.