Forecast Multiple seasonality Function Is not working

424 Views Asked by At

my new result

I have daily sales data i am using Tbat function suggested by Rob Hyndman Sir in many Post.my result is not showing growing trend

I am using the following code

mydata<-read.csv ("D:/data.csv",header=TRUE);
y <- msts(mydata$sales, seasonal.periods=c(7,365.25))
fit <- tbats(y)
fc <- forecast(fit)
plot(fc)
1

There are 1 best solutions below

9
On

As I cannot use your data, here is an example that uses your approach to a) simulate some data with (some kinds of) seasonality, and b) forecasts the next periods.

A) Simulate data

The data is simulated with three components, a sine-function, a cosine-function, and a random component.

# 1. simulate some data:
set.seed(123) # set seed for reproducability
n <- 1000

# simulate the random components
sin.comp <- sin((1:n)/10)*10
cos.comp <- cos((1:n)/5)*5
rand.comp <- rnorm(n)

df <- data.frame(time = seq(from = as.Date("2000-01-01"), by = "day", 
                            length.out = n),
                 value = sin.comp + cos.comp + rand.comp)

# plot the data
plot(x = df$time, y = df$value, main = "Seasonal Series", type = "l")
lines(x = df$time, y = sin.comp, col = "red")
lines(x = df$time, y = cos.comp, col = "blue")
lines(x = df$time, y = rand.comp, col = "green")
legend("bottomleft", 
       c("Series", "Sin", "Cos", "Rand"), 
       lty = c(1, 1), 
       col = c("black", "red", "blue", "green"), cex = 0.7)

Seasonal Series

B) Forecast the series

y <- msts(df$value, seasonal.periods = c(7, 36)) # cut down to 36
fit <- tbats(y) #takes some time to calculate..
fc <- forecast(fit)

plot(fc)

Forecast

Additional Notes

If this approach doesn't work for you that means that your is probably data in some way not right for the forecast...

To check your data, you can inspect the types with str(mydata) (in my case str(df)), summary(mydata), and head/tail(mydata).

As a last note, your dput is obviously a bit too long... Either post dput(head(mydata, 100)), which gives the first 100 entries, or upload the csv to a hoster and post the link.

Does that point you in the right direction?