0

我的新结果

我有每日销售数据,我在许多 Post 中使用 Rob Hyndman Sir 建议的 Tbat 函数。我的结果没有显示增长趋势

我正在使用以下代码

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)
4

1 回答 1

0

由于我不能使用您的数据,这里有一个示例,它使用您的方法来 a)模拟一些具有(某种)季节性的数据,以及 b)预测下一个时期。

A) 模拟数据

用三个分量模拟数据,一个正弦函数、一个余弦函数和一个随机分量。

# 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)

季节性系列

B) 预测系列

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)

预报

补充说明

如果这种方法对您不起作用,则意味着您的数据可能在某种程度上不适合预测...

要检查您的数据,您可以使用str(mydata)(在我的情况下str(df))、summary(mydata)和来检查类型head/tail(mydata)

最后一点,您dput显然有点太长了......要么 post dput(head(mydata, 100)),它提供前 100 个条目,要么将 csv 上传到主机并发布链接。

这是否为您指明了正确的方向?

于 2015-12-18T10:09:02.977 回答