Why is ets telling me there is no seasonality to my data?
> hwin <- ets(train.ts, model = "MAA")
Error in ets(train.ts, model = "MAA") : Nonseasonal data
Is there not a clear, daily seasonality to this data? Please note that the image below is of my full dataset, where as the sample code below only contains a partial dataset.
I know there isn't much trend, but seasonality should be there, right?
This is my code:
d <- structure(list(Date = structure(c(17349, 17350, 17351, 17352,
17353, 17354, 17355, 17356, 17357, 17358, 17359, 17360, 17361,
17362, 17363, 17364, 17365, 17366, 17367, 17368, 17369, 17370,
17371, 17372, 17373, 17374, 17375, 17376, 17377, 17378, 17379,
17380, 17381, 17382, 17383), class = "Date"), Ratio = c(67, 50,
67, 50, 100, 50, 33, 67, 0, 0, 0, 0, 100, 75, 0, 0, 75, 100,
67, 33, 33, 33, 50, 50, 67, 100, 67, 50, 25, 25, 33, 33, 100,
33, 0)), .Names = c("Date", "Ratio"), row.names = 183:217, class = "data.frame")
library(xts)
dates = as.Date(d$Date,"%Y-%m-%d")
ratios.ts = xts(d$Ratio,dates)
library("forecast")
library("zoo")
plot(ratios.ts)
nValid <- 6
nTrain <- length(ratios.ts) - nValid
train.ts <- window(ratios.ts, start = as.Date("2017-07-02"), end = as.Date("2017-07-02") + nTrain)
valid.ts <- window(ratios.ts, start = as.Date("2017-07-02") + nTrain + 1, end = as.Date("2017-07-02") + nTrain + nValid)
hwin <- ets(train.ts, model = "MAA")
hwin.pred <- forecast(hwin, h = nValid, level = 0)
plot(hwin.pred, ylim = c(-20,120), ylab = "Ratio", xlab = "Date", bty = "l", xaxt = "n", main = "", flty = 2)
lines(hwin.pred$fitted, lwd = 2, col = "blue")
Thank you!


xts()that the data were periodic. Thefrequencyargument allows you to do this. You need to tell it how many observations correspond to the unit time interval. If you had monthly data this would be 1/12 say. Do read ?xts though for details of the specific requirements here; I may have the input incorrect for xts as I use these things too infrequently for it to stick and there are several of these time-series data objects that have similar but not unique interfaces and arguments. This is also off topic for [stats.se] as it is about a programming problem not a stats one. – Gavin Simpson Aug 31 '17 at 18:37ratios.ts = xts(d$Ratio,dates,frequency = 365.25)addressing the frequency, I still get the same error. Any ideas? – user1477388 Aug 31 '17 at 18:45ets(as.ts(train.ts), model = "MAA"), assumingtrain.tsis a zoo object by the time you come to model it.?etsindicates thatxis supposed to be a vector or'ts'classed object. It may beets()doesn't know how to handle what you are passing it. – Gavin Simpson Aug 31 '17 at 19:07xtsobject.ets(as.ts(train.ts), model = "MAA")seems to result in the same error but I think you are on the right track thinking that ets doesn't understand what I am passing it which is probably due to the fact that my data is daily, not weekly, monthly or yearly. – user1477388 Aug 31 '17 at 19:33windowmethod wouldn't have worked. I was unsure if the zoo method forwindowwould preserve the xts- and zoo-ness of the underlying series or just return a zoo object. I'm also not sure you can specify a decimal forfrequency, which may still be the cause of the problem... – Gavin Simpson Aug 31 '17 at 19:42zooin there from a previous attempt; it should be disregarded. Something interesting, though: It seems like xts understands that the data is daily. A quick call outputs that it determines the data to be daily. So, why isn't ets getting the memo?> periodicity(ratios.ts) Daily periodicity from 2017-01-01 to 2017-08-06– user1477388 Aug 31 '17 at 19:58